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.

Ambiguity in relative file urls

See original GitHub issue

I would like to point out that the requirements file format specification mentions the ability to set relative path names such as file:../../lib/project#egg=MyProject in the file. Although those who try to use this syntax probably were disappointed, because in fact this variant does not work.

While trying to cope with the problem I discovered that relative urls are not supported “officially” at all, nor in RFC (wikipedia could be the starting point), nor in web browsers which can be considered as “reference implementation”.

In light of that, it would be acceptable to fix the documentation and to forbid explicitly using relative names in packages. On the other hand, it would be useful to accept such format. Personally, I discovered the issue when I tried to create the package and the sample subpackage in its subdirectory. The sample has a bunch of dependencies including “parent package” which I tried to point as file:…/ . I believe this approach does make sense.

I suggest considering my patch 54f5adeae4f9640c6b8d which fixes url_to_path function behavior such that urls starting with file:/ are considered as absolute, whereas urls which don’t have any slash after “file:” are relative ones.

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:26 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
michaeljonescommented, Jan 9, 2016

Ok, this can be resolved by using file:// instead of just file: which might be more appropriate anyway:

>>> scheme, netloc, path, query, fragment = urlparse.urlsplit('file://somewhere')
>>> urlparse.urlunsplit((scheme, netloc, path, query, None))                                                                                              
'file://somewhere'
>>> scheme, netloc, path, query, fragment = urlparse.urlsplit('file://./somewhere')
>>> urlparse.urlunsplit((scheme, netloc, path, query, None))                                                                                              
'file://./somewhere'

But then we fall afoul of the UNC check here: https://github.com/pypa/pip/blob/develop/pip/download.py#L447

>>> from pip.download import url_to_path
>>> url_to_path('file://somewhere')
'\\\\somewhere'
>>> url_to_path('file://./somewhere')
'\\\\./somewhere'

Could it be worth improving that check? Can we check for the current operating system or any other kind of condition before making that assumption? I’d love some input here as I’m out of my depth. From the little I’ve seen, UNC is a Windows thing and I’m on Linux.

Edit: As a final data point, if I delete that UNC check then it works fine for me with file://somewhere style paths.

1reaction
rachcommented, Jun 18, 2013

Hi,

I met the same issue today.

It’s a bit annoying that the behavior are not coherent :

-r …/prod-requirement.txt # is relative to the file …/my-app # is relative to where I launched the command

Is there any workaround at this stage to make work relative path ?

Thanks you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative Path Confusion - ScanRepeat
Relative Path Confusion means that your web server is configured to serve responses to ambiguous URLs. This configuration can possibly cause confusion about ......
Read more >
HATEOAS: absolute or relative URLs? - Stack Overflow
There is a subtle conceptual ambiguity when people say "relative URI". By RFC3986's definition, a generic URI contains: URI = scheme ":" hier-part...
Read more >
[Absolute or Relative path] `Default location for new notes ...
Currently, create new notes from relative path is very problematic as noted in a related feature request Obsidian has trouble creating new notes...
Read more >
Problems with using relative path names [#13148] | Drupal.org
If Drupal causes all the site's urls to be absolute, then none of this would be ... called Blinkx/DFS-Fetch keeps adding the .css...
Read more >
RFC 1808 - Relative Uniform Resource Locators
Relative URL Syntax The syntax for relative URLs is a shortened form of that ... the base document. file Host-specific Files ftp File...
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