-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allow the pip.conf to override the default index source. #5297
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those who didn't follow the discussion, I suggest we add a news snippet and explicit documentation.
NOTE: Original reply quoted below and removed. I've played around with it a bit. What do you think of this? # Load Pip configuration and get items
self.configuration = Configuration(isolated=False, load_only=None)
self.configuration.load()
configuration_items = self.configuration.items()
# Get unique set of index-url values from Pip configuration
index_urls = set(
value
for section_key, value in configuration_items
if "index-url" in section_key.split(".", 1)
)
if len(index_urls) == 1:
pip_configured_index = index_urls.pop()
else:
# NOTE: Either no index-url or ambiguous result
pip_configured_index = None
# Get unique set of trusted-host values from Pip configuration
trusted_hosts = set(
chain.from_iterable(
value.split(" ")
for section_key, value in configuration_items
if "trusted-host" in section_key.split(".", 1)
)
)
if pip_configured_index:
self.default_source = {
"url": pip_configured_index,
"verify_ssl": any(
trusted_host in pip_configured_index
for trusted_host in trusted_hosts
) or "http://" in pip_configured_index,
"name": "pip_conf_index",
}
elif self.s.PIPENV_TEST_INDEX:
self.default_source = {
"url": self.s.PIPENV_TEST_INDEX,
"verify_ssl": True,
"name": "custom",
}
else:
self.default_source = {
"url": "https://pypi.org/simple",
"verify_ssl": True,
"name": "pypi",
} It requires this additional import line:
|
@matteius Just checking in. Any updates? |
@kalebmckale I think your changes make sense; I spent some time trying to consider if we could handle the case where there is more than one index configured, and also if you want to be a committer you could branch off this and make a PR pointing at this one. I still have some documentation to do for it as well. We wanted this past release to be just bug fixes, the plan is to include this in the upcoming release that also includes pip 23.0. |
@kalebmckale I ended up refactoring your code and took a stab at supporting multiple sources defined, also I think there was a logical error in how |
Will do, @matteius! Thanks for making the changes. I have been trying to set up a test environment at home so I can confidently contribute. I will test this at work and let you know. |
It’s a Python thing. If the loop completes without hitting break, it runs the else statement.
UPDATE: Looks like I was commenting on the previous version and not talking about the same thing. You were talking about this: if pip_configured_index:
self.default_source = {
"url": pip_configured_index,
"verify_ssl": any(
trusted_host in pip_configured_index
for trusted_host in trusted_hosts
) or "http://" in pip_configured_index,
"name": "pip_conf_index",
} Specifically,
First, it probably would have been better for me to use urllib.parse.urlsplit(pip_configured_index).scheme == "http"` than just do the string comparison. Putting that aside, I did provide the negation of my intended logic. At home, I run the code in my head while typing on my iPad, so I tend to make mistakes, it seems. 😋 Thanks for catching that and applying DeMorgan’s Law! |
@kalebmckale Any other feedback on this -- I want to get the documentation fixed up and ideally a release this weekend ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey @matteius! Thanks for patience! Yes, the feature worked as expected with the The thing still pending, which is covered under another issue about the specifying |
No description provided.