pre-commit-hooks icon indicating copy to clipboard operation
pre-commit-hooks copied to clipboard

`requirements-txt-fixer` ordering breaks using --index-url and --extra-index-url together in requirements.txt

Open redfungus opened this issue 4 years ago • 8 comments

If you use both the --index-url and --extra-index-url flags together in a requirements.txt file the hook will put --extra-index-url above the --index-url which causes the url set to index-url be skipped. I suppose this is because the flags are also sorted alphabetically.

redfungus avatar Jun 14 '21 12:06 redfungus

note that --extra-index-url is unsafe and should generally never be used

a special case could be added, though my thought is that supporting something that shouldn't be used seems like unnecessary work

asottile avatar Jun 14 '21 14:06 asottile

@asottile I did not know about the security problems! Thank you for the link!

redfungus avatar Jun 14 '21 14:06 redfungus

Is there a pre-commit hook for detecting if the developer has incorrectly configured pip to run with --extra-index-url instead of --index-url?

I mean in addition to simply reading the requirements files, so it would also detect if the global pip config has been incorrectly configured?

robin-snt avatar Jun 21 '22 11:06 robin-snt

something like that doesn't really make sense as a hook -- looking at global settings doesn't make sense for something that's supposed to check source code

plus you'd have to know to configure such a thing and at that point you might as well just turn off the bad setting -- it's not something you're going to "accidentally" commit one day

asottile avatar Jun 21 '22 12:06 asottile

@asottile Your insight is highly appreciated!

robin-snt avatar Jun 21 '22 13:06 robin-snt

@asottile please review if you have time. I'm hoping this PR is simple enough and goes with the spirit of the special case you mentioned. Also, I'd appreciate if you could label w/ hacktoberfest-accepted so I can get a tree planted, thanks.

renegaderyu avatar Oct 19 '22 16:10 renegaderyu

I'm not going to review something which doesn't pass tests

asottile avatar Oct 19 '22 16:10 asottile

@asottile Apologies for not seeing the failing tests before asking. I think its ready now.

renegaderyu avatar Oct 20 '22 15:10 renegaderyu