pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.2k stars 694 forks source link

[Bug] requirements-txt-fixer: Index URLs Should not Sort #1054

Closed ax3l closed 3 months ago

ax3l commented 3 months ago

Hi,

I have a requirements.txt file of the form

-r ../requirements.txt

openPMD-validator

# https://pytorch.org/get-started/locally/
-i https://download.pytorch.org/whl/cpu
torch

which requirements-txt-fixer reformats (and breaks) to


# https://pytorch.org/get-started/locally/
-i https://download.pytorch.org/whl/cpu
-r ../requirements.txt

openPMD-validator
torch

In this case, I intentionally use -i for the index instead of --extra-index-url to avoid index confusion attacks. But if openPMD-validator gets sorted after the -i line, then it cannot be found (because it exists on the regular PyPI index).

As a minor observation, maybe the -r ../requirements.txt should also not be moved around?

asottile commented 3 months ago

sounds like a bit of a garbage in garbage out scenario. if you isolate your torch hack to it's own file it should work