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.

In windows, requirements file parser collapses absolute reference to requirements file

See original GitHub issue

Description

In Windows, running pip install -r against the following requirements file containing an absolute reference to other requirements files fails.

# In power-shell
$ echo pandas > requirements.txt
$ echo "-r $(pwd)\requirements.txt" > other-requirements.txt
$ pip install -r "$(pwd)\other-requirements.txt"

Could not open requirements file: [Errno 2] No such file or directory: 'D:\\absolute\\path\\to\\absolutepathtorequirements.txt'

Expected behavior

pip install should succeed

pip version

21.1.3

Python version

3.7.9

OS

Windows

How to Reproduce

echo pandas > requirements.txt
echo "-r $(pwd)\requirements.txt" > other_requirements.txt
cat requirements.txt
cat other_requirements.txt
pip install -r "$(pwd)\other_equirements.txt"

See this github actions log: https://github.com/harupy/windows-playground/pull/1/checks?check_run_id=2979532159

Output

pandas
-r D:\a\windows-playground\windows-playground\requirements.txt
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'D:\\a\\windows-playground\\windows-playground\\awindows-playgroundwindows-playgroundrequirements.txt'

Code of Conduct

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
uranusjrcommented, Jul 3, 2021

I think it’s more because of we need quotes (to handle special names, spaces, etc.), and once quoting is a thing you need a way to escape quotes, and everything cascades from there. The root of the issue is requirements.txt handles options by writing them like command line options, and cross-shell command line parsing is literally impossible. So there is a design decision to make, either we restrict the allowed quoting/escaping syntax, restrict what characters can appear in a path, or do platform-dependant parsing. All of them have significant setbacks.

0reactions
pfmoorecommented, Jul 3, 2021

As I said, I don’t like this solution because it makes Windows paths second-class. Why do we even need backslash-escaping in a requirements file?

Declaring forward slashes as the only supported option is easy and convenient, and may well be sufficient in practice, but that doesn’t mean it’s correct…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to parse requirements file after pip upgrade to pip ...
First, I believe parsing requirements.txt from within setup.py is not a good idea. It should be the other way around, install_requires in ...
Read more >
madpah/requirements-parser: A Pip requirements file ... - GitHub
This is a small Python module for parsing Pip requirement files. The goal is to parse everything in the Pip requirement file format...
Read more >
Changelog - pip documentation v22.3.1
This fixes bugs where the file:// URL cannot be correctly used as requirement, constraint, or index URLs on Windows. (#10115).
Read more >
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Represent the path as a file URI. ValueError is raised if the path isn't absolute. >>> >>> ...
Read more >
UG162: Simplicity Commander Reference Guide - Silicon Labs
6.7.7 Creating a Signed GBL File Using a Hardware Security Module . ... To execute Simplicity Commander commands, start a Windows command ...
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