Skip to content

Commit

Permalink
support also "file://" urls for private pip repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixSchwarz committed Oct 24, 2023
1 parent 5636e7c commit 4f3c1ca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
2 changes: 2 additions & 0 deletions conda_lock/_vendor/requests_file.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions conda_lock/interfaces/vendored_poetry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from conda_lock._vendor.poetry.config.config import Config
from conda_lock._vendor.poetry.core.packages import Dependency as PoetryDependency
from conda_lock._vendor.poetry.core.packages import Package as PoetryPackage
from conda_lock._vendor.poetry.core.packages import (
Expand All @@ -9,16 +10,22 @@
from conda_lock._vendor.poetry.installation.chooser import Chooser
from conda_lock._vendor.poetry.installation.operations.uninstall import Uninstall
from conda_lock._vendor.poetry.puzzle import Solver as PoetrySolver
from conda_lock._vendor.poetry.repositories.legacy_repository import LegacyRepository
from conda_lock._vendor.poetry.repositories.pool import Pool
from conda_lock._vendor.poetry.repositories.pypi_repository import PyPiRepository
from conda_lock._vendor.poetry.repositories.repository import Repository
from conda_lock._vendor.poetry.utils.env import Env
from conda_lock._vendor.poetry.utils.helpers import get_cert, get_client_cert


__all__ = [
"get_cert",
"get_client_cert",
"Chooser",
"Config",
"Env",
"Factory",
"LegacyRepository",
"PoetryDependency",
"PoetryPackage",
"PoetryProjectPackage",
Expand Down
6 changes: 6 additions & 0 deletions conda_lock/interfaces/vendored_requests_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from conda_lock._vendor.requests_file import FileAdapter


__all__ = [
"FileAdapter",
]
45 changes: 37 additions & 8 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
from pathlib import Path
from posixpath import expandvars
from typing import TYPE_CHECKING, Dict, List, Optional
from urllib.parse import urldefrag, urlparse, urlsplit, urlunsplit
from urllib.parse import urldefrag, urlsplit, urlunsplit

import requests

from clikit.api.io.flags import VERY_VERBOSE
from clikit.io import ConsoleIO, NullIO
from packaging.tags import compatible_tags, cpython_tags, mac_platforms

from conda_lock.interfaces.vendored_poetry import (
Chooser,
Config,
Env,
Factory,
LegacyRepository,
PoetryDependency,
PoetryPackage,
PoetryProjectPackage,
Expand All @@ -24,7 +28,10 @@
PyPiRepository,
Repository,
Uninstall,
get_cert,
get_client_cert,
)
from conda_lock.interfaces.vendored_requests_file import FileAdapter
from conda_lock.lockfile import apply_categories
from conda_lock.lockfile.v2prelim.models import (
DependencySource,
Expand Down Expand Up @@ -384,6 +391,28 @@ def solve_pypi(
return {dep.name: dep for dep in requirements}


class CondaLockLegacyRepository(LegacyRepository):
@property
def session(self) -> requests.Session:
_session = super().session
_session.mount("file://", FileAdapter())
return _session


def create_legacy_repository(
source: Dict[str, str], auth_config: Config
) -> LegacyRepository:
name = source["name"]
url = source["url"]
return CondaLockLegacyRepository(
name,
url,
config=auth_config,
cert=get_cert(auth_config, name),
client_cert=get_client_cert(auth_config, name),
)


def _prepare_repositories_pool(
allow_pypi_requests: bool, pip_repositories: Optional[List[PipRepository]] = None
) -> Pool:
Expand All @@ -397,13 +426,13 @@ def _prepare_repositories_pool(
"""
factory = Factory()
config = factory.create_config()
repos = [
factory.create_legacy_repository(
{"name": pip_repository.name, "url": expandvars(pip_repository.url)},
config,
)
for pip_repository in pip_repositories or []
] + [

legacy_repos = []
for pip_repository in pip_repositories or []:
repo_cfg = {"name": pip_repository.name, "url": expandvars(pip_repository.url)}
legacy_repo = create_legacy_repository(repo_cfg, config)
legacy_repos.append(legacy_repo)
repos = legacy_repos + [
factory.create_legacy_repository(
{"name": source[0], "url": source[1]["url"]}, config
)
Expand Down

0 comments on commit 4f3c1ca

Please sign in to comment.