From aa6f374147e58e7f3ed28bf7288f5f5a9d05eba0 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Sat, 25 Mar 2023 02:07:26 -0700 Subject: [PATCH] feat: add support for git to lockfile --- conda_lock/models/lock_spec.py | 5 ++++- conda_lock/pypi_solver.py | 13 +++++++++++++ conda_lock/src_parser/pyproject_toml.py | 10 +++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/conda_lock/models/lock_spec.py b/conda_lock/models/lock_spec.py index a6ce7b88..582a6ffc 100644 --- a/conda_lock/models/lock_spec.py +++ b/conda_lock/models/lock_spec.py @@ -31,8 +31,11 @@ class URLDependency(_BaseDependency): url: str hashes: List[str] +class VCSDependency(_BaseDependency): + source: str + vcs: str -Dependency = Union[VersionedDependency, URLDependency] +Dependency = Union[VersionedDependency, URLDependency, VCSDependency] class Package(StrictModel): diff --git a/conda_lock/pypi_solver.py b/conda_lock/pypi_solver.py index bd2b973e..df3cb346 100644 --- a/conda_lock/pypi_solver.py +++ b/conda_lock/pypi_solver.py @@ -16,6 +16,7 @@ ProjectPackage as PoetryProjectPackage, ) from conda_lock._vendor.poetry.core.packages import URLDependency as PoetryURLDependency +from conda_lock._vendor.poetry.core.packages import VCSDependency as PoetryVCSDependency from conda_lock._vendor.poetry.factory import Factory from conda_lock._vendor.poetry.installation.chooser import Chooser from conda_lock._vendor.poetry.installation.operations.uninstall import Uninstall @@ -160,6 +161,12 @@ def get_dependency(dep: lock_spec.Dependency) -> PoetryDependency: url=f"{dep.url}#{dep.hashes[0].replace(':','=')}", extras=extras, ) + elif isinstance(dep, lock_spec.VCSDependency): + return PoetryVCSDependency( + name=dep.name, + vcs=dep.vcs, + source=dep.source, + ) else: raise ValueError(f"Unknown requirement {dep}") @@ -283,7 +290,13 @@ def solve_pypi( source = lockfile.DependencySource( type="url", url=op.package.source_url ) + elif op.package.source_type == "git": + url = f"{op.package.source_type}+{op.package.source_url}@{op.package.source_resolved_reference}" + # TODO: FIXME git ls-remoet + hash = lockfile.HashModel(**{"sha256": op.package.source_resolved_reference }) # Choose the most specific distribution for the target + # TODO: need to handle git here + # https://github.com/conda/conda-lock/blob/ac31f5ddf2951ed4819295238ccf062fb2beb33c/conda_lock/_vendor/poetry/installation/executor.py#L557 else: link = chooser.choose_for(op.package) url = link.url_without_fragment diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 745ca569..12439295 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -33,6 +33,7 @@ Dependency, LockSpecification, URLDependency, + VCSDependency, VersionedDependency, ) @@ -339,7 +340,14 @@ def parse_python_requirement( conda_dep_name = name extras = list(parsed_req.extras) - if parsed_req.url: # type: ignore[attr-defined] + if parsed_req.url and parsed_req.url.startswith('git+'): + return VCSDependency( + name=conda_dep_name, + source=parsed_req.url[4:], + manager=manager, + vcs='git', + ) + elif parsed_req.url: # type: ignore[attr-defined] assert conda_version in {"", "*", None} url, frag = urldefrag(parsed_req.url) # type: ignore[attr-defined] return URLDependency(