question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve relative links in long_description

See original GitHub issue

What’s the problem this feature will solve?

Broken relative links in many pypi hosted project descriptions.

Describe the solution you’d like

Add a project maintainer option that sets what relative links should be resolved to.

A similar feature is available in html itself: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

Even better would be if we can use some properties of the package such as version to describe the path to resolve relative links with.

E.g. github.com/example/foobar/tree/v$VERSION configured as base path.

Additional context

A common use-case is to take your project readme, and load it into the package long-description. Often this is done with:

with open("README.md", "rt", encoding="utf8") as f:
    readme = f.read()
...
    long_description=readme,
    long_description_content_type="text/markdown",

This works, but relative links break. And hardcoding is a poor practice too, as e.g. GitHub-hosted Readme links become stuck to a certain version, instead of referencing the resource on the same version the viewer is on. Also, sometimes a resource moves, and to keep older documentation working some ability to point to a different absolute path would be great.

PyPi as a viewer of the description can resolve these relative links. And maybe even default to the home page (which lots of projects set to their github project link), to un-break thousands of broken relative description links currently in PyPi.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jamaddencommented, Apr 7, 2020

We’d want to be able to support the same functionality for rST-formatted descriptions as well though, and I’m not familiar enough with rST to say how to do that.

The Nikola static blog engine supports extensive metadata in both markdown and reST. While it can just use specially formatted comments, it can also use the reST standard “docinfo” nodes, which is what I personally use:

How to make money
=================

:slug: how-to-make-money
:date: 2012-09-15 19:52:05 UTC

These have the advantage of being parsed by docutils itself; there are a set of standard tags, and arbitrary custom tags can be used as well. Getting the data is easy:

        meta = {}
        if 'title' in document:
            meta['title'] = document['title']
        for docinfo in document.traverse(docutils.nodes.docinfo):
            for element in docinfo.children:
                if element.tagname == 'field':  # custom fields (e.g. summary)
                    name_elem, body_elem = element.children
                    name = name_elem.astext()
                    value = body_elem.astext()
                elif element.tagname == 'authors':  # author list
                    name = element.tagname
                    value = [element.astext() for element in element.children]
                else:  # standard fields (e.g. address)
                    name = element.tagname
                    value = element.astext()
                name = name.lower()

                meta[name] = value

If tools are unaware of custom tags, they format in HTML as a field list (basically a table). (This is opposed to a custom directive, which can do anything from produce an error in the rendered document to nothing at all, depending on settings.) Nikola strips the docinfo nodes so they don’t show up in rendering, which is pretty easy:

        for node in self.document.traverse(docutils.nodes.docinfo):
            node.parent.remove(node)
1reaction
Mattwmaster58commented, Apr 7, 2020

Here’s an example of a project with this issue: https://pypi.org/project/black/

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set current url so relative links resolve correctly when ...
I can think of two options: Create a function to turn a relative path into a file:// URL. Run a simple server. I...
Read more >
SEO Toolkit giving false broken link warnings - MSDN - Microsoft
The toolkit reports a broken link on the website's home page. ... This is causing the SEO Toolkit to resolve the longdesc attribute...
Read more >
OData TC meeting #159 Thursday Jan 26, 2017 - OASIS Open
Mike: I move we resolve ODATA-1027 as proposed. Ramesh seconds. Ralf: ODATA-1027 is RESOLVED as proposed. 6.1.5 ODATA-1028 - 4.3.4: clarify relative URLs...
Read more >
HTML and URLs
Relative URLs may contain relative path components (".." means one level up in the hierarchy defined by the path), and may contain fragment...
Read more >
Division of Student Affairs Advanced Web Editor Training
presets by lower percentages and resolution at 72px to crop. ... When linking, under “link info” type the relative link in the url...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found