Skip to content
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

feat: add support for git to lockfile #394

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion conda_lock/models/lock_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Dependency,
LockSpecification,
URLDependency,
VCSDependency,
VersionedDependency,
)

Expand Down Expand Up @@ -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(
Expand Down