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

Adds a detection for index urls similar to how comments are captured. #825

Closed
wants to merge 1 commit into from
Closed

Conversation

renegaderyu
Copy link

This should avoid breaking ordering when --index-url (-i) and/or --extra-index-url are used.

Closes #612.

@renegaderyu
Copy link
Author

Here is a sample diff of a test I ran against a requirements file w/ comments and index urls

1,9d0
< # Bar
< --extra-index-url http://dist.repoze.org/zope2/2.10/simple
< zopelib2
< # Foo
< -i http://dist.repoze.org/zope2/2.10/simple
< zopelib1
< # Baz
< --index-url http://dist.repoze.org/zope2/2.10/simple
< zopelib3
332a324,332
> # Foo
> -i http://dist.repoze.org/zope2/2.10/simple
> zopelib1
> # Bar
> --extra-index-url http://dist.repoze.org/zope2/2.10/simple
> zopelib2
> # Baz
> --index-url http://dist.repoze.org/zope2/2.10/simple
> zopelib3

Comment on lines 113 to 121
b'# Foo\n'
b'-i http://dist.repoze.org/zope2/2.10/simple\n'
b'zopelib1\n'
b'# Bar\n'
b'--extra-index-url http://dist.repoze.org/zope2/2.10/simple\n'
b'zopelib2\n'
b'# Baz\n'
b'--index-url http://dist.repoze.org/zope2/2.10/simple\n'
b'zopelib3\n',
Copy link
Member

Choose a reason for hiding this comment

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

this isn't quite what I'd expect -- I think all options should stay at the top of the file

Copy link
Author

Choose a reason for hiding this comment

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

I've updated my changes to push index-url options to the top and preserve proper order (index-url before extra-index-url). If this is sufficient, great, please review/approve/merge assuming all test pass.

As a point of discussion, I'm wondering if there is a better solution here. It is my understanding that the index url and/or extra index url can be specified before any requirement to change the indices used for that particular package. If my understanding is correct, and the options are all put at the top I think there might be a few other unhandled edge cases. Since it seems that the consensus is similar to what you originally suggested "never use --extra-index-url" I'm wondering if it would be better to do one of the following:

  1. push index-url to top and additionally fail + print an error if extra-index-url is detected or multiple index-url's are detected
  2. push all index-url options to top and leave extra-index-url associated with the specific requirement it appears above
  3. something else

Copy link
Member

Choose a reason for hiding this comment

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

please review/approve/merge assuming all test pass.

yeah don't tell me what to do -- this is also just how things work so you don't need to say this

It is my understanding that the index url and/or extra index url can be specified before any requirement to change the indices used for that particular package

don't guess, figure out how it works -- that's a very important part of making this change especially if you're wrong

Copy link
Author

Choose a reason for hiding this comment

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

yeah don't tell me what to do -- this is also just how things work so you don't need to say this

I wasn't trying to hence the please. I'll also try to keep things brief.

don't guess, figure out how it works -- that's a very important part of making this change especially if you're wrong

I'd recommend leaving it as it stand now (pushing all options to top).

I wasn't guessing but the pip documentation for requirements files also doesn't seem to cover the minutia of index-url and extra-index-url options. I know that users can change index-url throughout the file but it doesn't appear to be recommended best practice and neither is using extra-index-url. I raised this as a discussion point because I thought, based on the comments made to the test case, that you might have further insights to help me understand better.

Copy link
Member

Choose a reason for hiding this comment

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

try it and figure out how it works and document it

…ed. This should avoid breaking ordering when --index-url (-i) and/or --extra-index-url are used. Also adds a relevant test to cover this case. Closes #612.
@renegaderyu renegaderyu closed this by deleting the head repository Feb 13, 2023
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