Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a drive letter in a URI breaks (Windows) #10115

Closed
1 task done
henryiii opened this issue Jun 30, 2021 · 1 comment · Fixed by #10116
Closed
1 task done

Using a drive letter in a URI breaks (Windows) #10115

henryiii opened this issue Jun 30, 2021 · 1 comment · Fixed by #10116
Labels
type: bug A confirmed bug or unintended behavior

Comments

@henryiii
Copy link
Contributor

Description

If you use a URI on Windows for PIP_CONSTRAINTS, then pip breaks down with an error like this:

ERROR: Could not open requirements file: [Errno 22] Invalid argument: '/C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-1/test_dependency_constraints_fi1/constraints file.txt'

This was supposed to be a workaround for #10114. Seen in pypa/cibuildwheel#738 (comment)

Expected behavior

URIs from path lib should work on Windows.

pip version

21.1.3

Python version

All

OS

Windows and macOS, at least, probably all.

How to Reproduce

  1. Get a URI, say from pathlib's Path.as_uri().
  2. Set PIP_CONSTRAINTS with it and install something
  3. An error occurs.

Output

ERROR: Could not open requirements file: [Errno 22] Invalid argument: '/C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-1/test_dependency_constraints_fi1/constraints file.txt'

Code of Conduct

@henryiii henryiii added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jun 30, 2021
@uranusjr
Copy link
Member

uranusjr commented Jun 30, 2021

Turns out this is a limitation to urllib.parse.urlsplit() (which pip uses to parse file:// URLs).

>>> from pathlib import Path
>>> from urllib.parse import urlsplit
>>> scheme, netloc, path, *_ = urlsplit(Path("C:/Users/VssAdministrator").as_posix())
# scheme == "file"
# netloc == ""
# path == "/C:/Users/VssAdministrator"

This leading slash unfortunately causes issues in functions like open(). Windows can take a UNC path, /Users/VssAdministrator (without the drive name, as long as you are on the same drive), or C:/Users/VssAdministrator (the one we all know), but not /C:/Users/VssAdministrator.

I’ll submit a hack to work around this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2021
@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants