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

_dependency_source, _cli, test: Do not override pip.conf unless explicitly specified via flags #565

Merged
merged 7 commits into from
Mar 24, 2023

Conversation

philblckwd
Copy link
Contributor

@philblckwd philblckwd commented Mar 22, 2023

Refactor index-url and extra-index-url options to not override config defined in 'pip.conf' unless explicitly specified via flags.

Closes #563

@@ -286,7 +285,6 @@ def _parser() -> argparse.ArgumentParser: # pragma: no cover
type=str,
help="base URL of the Python Package Index; this should point to a repository compliant "
"with PEP 503 (the simple repository API)",
default=PYPI_URL,
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to keep this default in the CLI -- behaviorally it should remain the default, and having it appear as such in the --help render makes for a nicer UX 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So leaving this as the default means that it will always be explicitly passed to the pip install CLI, which results in the index-url specified in the pip.conf being ignored. I understand that it makes for a more friendly UX to specify as such, but would it be reasonable to convey that the url will be resolved by pip if not passed by the user explicitly?

If this is a deal breaker though, then I'll have to dig deeper into pip to determine how it is performing the index-url resolution.

Copy link
Contributor

Choose a reason for hiding this comment

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

So leaving this as the default means that it will always be explicitly passed to the pip install CLI, which results in the index-url specified in the pip.conf being ignored. I understand that it makes for a more friendly UX to specify as such, but would it be reasonable to convey that the url will be resolved by pip if not passed by the user explicitly?

That sounds reasonable to me!

self, filename: Path, index_urls: list[str] = [PYPI_URL], state: AuditState = AuditState()
self,
filename: Path,
index_url: str = "",
Copy link
Member

Choose a reason for hiding this comment

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

Similar typestate nit here: maybe drop the default "" here (or make it PYPI_URL), since we always expect a valid URL?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this was a misunderstanding on my part! I think we want this to be:

Suggested change
index_url: str = "",
index_url: str | None = None,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I'd prefer this too.

@@ -47,7 +46,8 @@ def __init__(
require_hashes: bool = False,
no_deps: bool = False,
skip_editable: bool = False,
index_urls: list[str] = [PYPI_URL],
index_url: str = "",
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
index_url: str = "",
index_url: str | None = None,

@@ -44,7 +43,8 @@ class VirtualEnv(venv.EnvBuilder):
def __init__(
self,
install_args: list[str],
index_urls: list[str] = [PYPI_URL],
index_url: str = "",
Copy link
Member

Choose a reason for hiding this comment

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

Oh, this explains it! Rather than using an empty string as falsey, let's make this an optional type:

Suggested change
index_url: str = "",
index_url: str | None = None,

...since that'll better convey the valid states here.

@woodruffw
Copy link
Member

Thanks a ton for opening this, @philblckwd!

This looks great to me structurally; just a few small nitpicks 🙂

@woodruffw woodruffw added enhancement New feature or request component:dep-sources Dependency sources labels Mar 22, 2023
@woodruffw
Copy link
Member

woodruffw commented Mar 22, 2023

(This also needs a CHANGELOG.md entry. Feel free to do it yourself if you feel like it, otherwise I'll do it as a fixup after merge!)

@tetsuo-cpp
Copy link
Contributor

I'm also happy with where this is at. Once the help text is amended and those type state related comments are addressed, this should be good to go.

Thanks again for your work. We really appreciate it.

@tetsuo-cpp
Copy link
Contributor

@philblckwd One more thing. We have a check in CI to ensure that the help text that we display in the README is up to date. So once you've amended the help text for --index-url, you'll need to update the README.

@philblckwd
Copy link
Contributor Author

Per feedback:

  • I updated arguments to use optional types
  • I updated the help text, as well as the readme, to state the index-url will be resolved by pip if not specified
  • I added an entry to the changelog
  • I noticed unrelated lint and check-readme errors, so resolved those too

@tetsuo-cpp tetsuo-cpp changed the title feature/index-url-usage _dependency_source, _cli, test: Do not override pip.conf unless explicitly specified via flags Mar 24, 2023
Copy link
Contributor

@tetsuo-cpp tetsuo-cpp left a comment

Choose a reason for hiding this comment

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

LGTM!

@tetsuo-cpp
Copy link
Contributor

I'll merge this shortly after I've done a bit of testing locally.

@tetsuo-cpp tetsuo-cpp merged commit 36973e9 into pypa:main Mar 24, 2023
@tetsuo-cpp
Copy link
Contributor

Thanks @philblckwd!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 30, 2023
## [2.5.4]

### Changed

* Refactored `index-url` option to not override user pip config by default,
  unless specified ([#565](pypa/pip-audit#565))

### Fixed

* Fixed bug with the `--fix` flag where new requirements were sometimes being
  appended to requirement files instead of patching the existing requirement
  ([#577](pypa/pip-audit#577))

* Fixed a crash caused by auditing requirements files that refer to other
  requirements files ([#568](pypa/pip-audit#568))

## [2.5.3]

### Changed

* Further simplified `pip-audit`'s dependency resolution to remove inconsistent
  behaviour when using hashed requirements or the `--no-deps` flag
  ([#540](pypa/pip-audit#540))

### Fixed

* Fixed a crash caused by invalid UTF-8 sequences in subprocess outputs
  ([#572](pypa/pip-audit#572))

## [2.5.2]

### Fixed

* Fixed a loose dependency constraint for CycloneDX SBOM generation
  ([#558](pypa/pip-audit#558))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:dep-sources Dependency sources enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Private repo dependencies no longer being skipped
3 participants