Skip to content

fix(requirements-txt-fixer): keep --index-url before --extra-index-url#1241

Open
LouisLau-art wants to merge 2 commits intopre-commit:mainfrom
LouisLau-art:fix/requirements-txt-fixer-index-order
Open

fix(requirements-txt-fixer): keep --index-url before --extra-index-url#1241
LouisLau-art wants to merge 2 commits intopre-commit:mainfrom
LouisLau-art:fix/requirements-txt-fixer-index-order

Conversation

@LouisLau-art
Copy link

Fixes #612.

requirements-txt-fixer sorts entries by name, which causes --extra-index-url to be placed before --index-url. Pip processes these options in order, and this ordering can change behavior.

This adds a small sort special-case so --index-url is always ordered before --extra-index-url, and includes a regression test.

Test plan:

  • python -m pytest -q tests/requirements_txt_fixer_test.py

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't handle -i and -e or whatever the short option is

Comment on lines +16 to +19
_SPECIAL_ORDER = {
b'--index-url': 0,
b'--extra-index-url': 1,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's not really any reason to make this a constant -- just adds unnecessary indirection and makes the code harder to understand

@LouisLau-art
Copy link
Author

Good catch — updated to normalize and / so they get the same ordering, and added integration tests for both forms.

@LouisLau-art
Copy link
Author

Follow-up (previous comment lost formatting): normalized -i and --index-url=... / --extra-index-url=... forms, with integration tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants