Skip to content

Commit

Permalink
move to shared channel concept for conda & pip
Browse files Browse the repository at this point in the history
  • Loading branch information
croth1-liveeo committed Feb 18, 2023
1 parent 1235c16 commit f09744d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def _solve_for_arch(
conda_locked={dep.name: dep for dep in conda_deps.values()},
python_version=conda_deps["python"].version,
platform=platform,
poetry_repositories=spec.poetry_repositories,
pypi_channels=spec.pypi_channels,
allow_pypi_requests=spec.allow_pypi_requests,
)
else:
Expand Down
2 changes: 1 addition & 1 deletion conda_lock/conda_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def solve_conda(
"""

conda_specs = [
_to_match_spec(dep.name, dep.version, dep.build, dep.conda_channel)
_to_match_spec(dep.name, dep.version, dep.build, dep.channel)
for dep in specs.values()
if isinstance(dep, VersionedDependency) and dep.manager == "conda"
]
Expand Down
10 changes: 6 additions & 4 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ def get_dependency(dep: src_parser.Dependency) -> PoetryDependency:
# FIXME: how do deal with extras?
extras: List[str] = []
if isinstance(dep, src_parser.VersionedDependency):
return PoetryDependency(
dependency = PoetryDependency(
name=dep.name, constraint=dep.version or "*", extras=dep.extras
)
dependency.source_name = dep.channel # type: ignore
return dependency
elif isinstance(dep, src_parser.URLDependency):
return PoetryURLDependency(
name=dep.name,
Expand Down Expand Up @@ -180,7 +182,7 @@ def solve_pypi(
conda_locked: Dict[str, lockfile.LockedDependency],
python_version: str,
platform: str,
poetry_repositories: Optional[List[src_parser.PoetrySource]] = None,
pypi_channels: Optional[List[src_parser.PyPIChannel]] = None,
allow_pypi_requests: bool = True,
verbose: bool = False,
) -> Dict[str, lockfile.LockedDependency]:
Expand Down Expand Up @@ -216,7 +218,7 @@ def solve_pypi(
for dep in dependencies:
dummy_package.add_dependency(dep)

pool = _prepare_repositories_pool(allow_pypi_requests, poetry_repositories)
pool = _prepare_repositories_pool(allow_pypi_requests, pypi_channels)

installed = Repository()
locked = Repository()
Expand Down Expand Up @@ -327,7 +329,7 @@ def solve_pypi(

def _prepare_repositories_pool(
allow_pypi_requests: bool,
repositories: Optional[List[src_parser.PoetrySource]] = None,
repositories: Optional[List[src_parser.PyPIChannel]] = None,
) -> Pool:
"""
Prepare the pool of repositories to solve pip dependencies
Expand Down
11 changes: 5 additions & 6 deletions conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _BaseDependency(StrictModel):
selectors: Selectors = Selectors()


class PoetrySource(StrictModel):
class PyPIChannel(StrictModel):
class Config:
frozen = True

Expand All @@ -58,8 +58,7 @@ class Config:
class VersionedDependency(_BaseDependency):
version: str
build: Optional[str] = None
conda_channel: Optional[str] = None
poetry_source: Optional[str] = None
channel: Optional[str] = None


class URLDependency(_BaseDependency):
Expand All @@ -83,7 +82,7 @@ class LockSpecification(BaseModel):
sources: List[pathlib.Path]
virtual_package_repo: Optional[FakeRepoData] = None
allow_pypi_requests: bool = True
poetry_repositories: Optional[List[PoetrySource]] = None
pypi_channels: Optional[List[PyPIChannel]] = None

def content_hash(self) -> Dict[str, str]:
return {
Expand Down Expand Up @@ -147,8 +146,8 @@ def aggregate_lock_specs(
# uniquify metadata, preserving order
platforms=ordered_union(lock_spec.platforms or [] for lock_spec in lock_specs),
sources=ordered_union(lock_spec.sources or [] for lock_spec in lock_specs),
poetry_repositories=ordered_union(
lock_spec.poetry_repositories or [] for lock_spec in lock_specs
pypi_channels=ordered_union(
lock_spec.pypi_channels or [] for lock_spec in lock_specs
)
or None,
)
2 changes: 1 addition & 1 deletion conda_lock/src_parser/conda_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def conda_spec_to_versioned_dep(spec: str, category: str) -> VersionedDependency
category=category,
extras=[],
build=ms.get("build"),
conda_channel=channel_str,
channel=channel_str,
)
10 changes: 5 additions & 5 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from conda_lock.src_parser import (
Dependency,
LockSpecification,
PoetrySource,
PyPIChannel,
URLDependency,
VersionedDependency,
)
Expand Down Expand Up @@ -123,7 +123,7 @@ def parse_poetry_pyproject_toml(

poetry_repositories = []
for repository in get_in(["tool", "poetry", "source"], contents, {}):
source = PoetrySource(**repository)
source = PyPIChannel(**repository)
poetry_repositories.append(source)

for section, default_category in categories.items():
Expand Down Expand Up @@ -187,7 +187,7 @@ def parse_poetry_pyproject_toml(
optional=optional,
category=category,
extras=extras,
poetry_source=poetry_source,
channel=poetry_source,
)
)

Expand All @@ -200,7 +200,7 @@ def specification_with_dependencies(
path: pathlib.Path,
toml_contents: Mapping[str, Any],
dependencies: List[Dependency],
poetry_repositories: Optional[List[PoetrySource]] = None,
pypi_channels: Optional[List[PyPIChannel]] = None,
) -> LockSpecification:
force_pypi = set()
for depname, depattrs in get_in(
Expand Down Expand Up @@ -234,7 +234,7 @@ def specification_with_dependencies(
channels=get_in(["tool", "conda-lock", "channels"], toml_contents, []),
platforms=get_in(["tool", "conda-lock", "platforms"], toml_contents, []),
sources=[path],
poetry_repositories=poetry_repositories,
pypi_channels=pypi_channels,
allow_pypi_requests=get_in(
["tool", "conda-lock", "allow-pypi-requests"], toml_contents, True
),
Expand Down

0 comments on commit f09744d

Please sign in to comment.