forked from conda/conda-lock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request conda#529 from jacksmith15/feat/460/configure-pypi…
…-repo-in-environment-file Configure private pip repositories in the environment file
- Loading branch information
Showing
18 changed files
with
394 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from hashlib import sha256 | ||
from urllib.parse import urlparse, urlunparse | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
|
||
|
||
class PipRepository(BaseModel): | ||
model_config = ConfigDict(frozen=True) | ||
|
||
url: str | ||
|
||
@classmethod | ||
def from_string(cls, url: str) -> "PipRepository": | ||
return PipRepository(url=url) | ||
|
||
@property | ||
def base_url(self) -> str: | ||
"""The base URL of the pip repository, without a URL path.""" | ||
full_url = urlparse(self.url) | ||
return full_url.scheme + "://" + full_url.netloc | ||
|
||
@property | ||
def stripped_base_url(self) -> str: | ||
"""The base URL of the pip repository, without any basic auth.""" | ||
base_url = urlparse(self.base_url) | ||
return urlunparse(base_url._replace(netloc=base_url.netloc.split("@", 1)[-1])) | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Poetry solver requires a name for each repository. | ||
We use this to match solver results back to their relevant | ||
repository. | ||
""" | ||
sha = sha256() | ||
sha.update(self.url.encode("utf-8")) | ||
return sha.hexdigest() | ||
|
||
def normalize_solver_url(self, solver_url: str) -> str: | ||
"""Normalize the URL returned by Poetry's solver. | ||
Poetry doesn't return URLs with URL-based basic Auth, because it gets converted to | ||
header-based Basic Auth. Because of this, we have to add the auth back in here. | ||
""" | ||
if not solver_url.startswith(self.stripped_base_url): | ||
# The resolved package URL is at a different host to the repository | ||
return solver_url | ||
return solver_url.replace(self.stripped_base_url, self.base_url, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.