Skip to content

Commit

Permalink
Take a lockfile path from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
jvansanten committed Nov 24, 2021
1 parent 545cfdd commit 1f5f224
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import pathlib
import re
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -209,6 +210,7 @@ def make_lock_files(
conda: PathLike,
src_files: List[pathlib.Path],
kinds: List[str],
lockfile_path: pathlib.Path = pathlib.Path(DEFAULT_LOCKFILE_NAME),
platform_overrides: Optional[Sequence[str]] = None,
channel_overrides: Optional[Sequence[str]] = None,
virtual_package_spec: Optional[pathlib.Path] = None,
Expand All @@ -229,6 +231,8 @@ def make_lock_files(
Files to parse requirements from
kinds :
Lockfile formats to output
lockfile_path :
Path to a conda-lock.yml to create or update
platform_overrides :
Platforms to solve for. Takes precedence over platforms found in src_files.
channels_overrides :
Expand Down Expand Up @@ -264,16 +268,12 @@ def make_lock_files(
virtual_package_repo=virtual_package_repo,
)

kind = "lock"
filename = DEFAULT_LOCKFILE_NAME

lockfile = pathlib.Path(filename)

lock_content: Optional[Lockfile] = None

platforms_to_lock: List[str] = []
platforms_already_locked: List[str] = []
if lockfile.exists():
lock_content = parse_conda_lock_file(lockfile)
if lockfile_path.exists():
lock_content = parse_conda_lock_file(lockfile_path)
platforms_already_locked = list(lock_content.metadata.platforms)
update_spec = UpdateSpecification(
locked=lock_content.package, update=update
Expand Down Expand Up @@ -306,15 +306,15 @@ def make_lock_files(
conda=conda,
spec=lock_spec,
platforms=platforms_to_lock,
lockfile_path=lockfile,
lockfile_path=lockfile_path,
update_spec=update_spec,
)

if "lock" in kinds:
write_conda_lock_file(lock_content, lockfile)
write_conda_lock_file(lock_content, lockfile_path)
print(
f" - Install lock using {'(see warning below)' if kind == 'env' else ''}:",
KIND_USE_TEXT[kind].format(lockfile=filename),
" - Install lock using:",
KIND_USE_TEXT["lock"].format(lockfile=str(lockfile_path)),
file=sys.stderr,
)

Expand Down Expand Up @@ -782,15 +782,15 @@ def _render_lockfile_for_install(
Parameters
----------
filename :
Path to conda-lock.toml
Path to conda-lock.yml
include_dev_dependencies :
Include development dependencies in output
extras :
Optional dependency groups to include in output
"""

if not filename.endswith(".toml"):
if not filename.endswith(DEFAULT_LOCKFILE_NAME):
yield filename
return

Expand Down Expand Up @@ -827,6 +827,7 @@ def run_lock(
channel_overrides: Optional[Sequence[str]] = None,
filename_template: Optional[str] = None,
kinds: Optional[List[str]] = None,
lockfile_path: pathlib.Path = pathlib.Path(DEFAULT_LOCKFILE_NAME),
check_input_hash: bool = False,
extras: Optional[AbstractSet[str]] = None,
virtual_package_spec: Optional[pathlib.Path] = None,
Expand All @@ -848,6 +849,7 @@ def run_lock(
virtual_package_spec=virtual_package_spec,
update=update,
kinds=kinds or DEFAULT_KINDS,
lockfile_path=lockfile_path,
filename_template=filename_template,
include_dev_dependencies=include_dev_dependencies,
extras=extras,
Expand Down Expand Up @@ -912,7 +914,12 @@ def main():
@click.option(
"--filename-template",
default="conda-{platform}.lock",
help="Template for the lock file names. Filename must include {platform} token, and must not end in '.yml'. For a full list and description of available tokens, see the command help text.",
help="Template for single-platform (explicit, env) lock file names. Filename must include {platform} token, and must not end in '.yml'. For a full list and description of available tokens, see the command help text.",
)
@click.option(
"--lockfile",
default=DEFAULT_LOCKFILE_NAME,
help="Path to a conda-lock.yml to create or update",
)
@click.option(
"--strip-auth",
Expand Down Expand Up @@ -963,6 +970,7 @@ def lock(
files,
kind,
filename_template,
lockfile,
strip_auth,
extras,
check_input_hash: bool,
Expand Down Expand Up @@ -1019,6 +1027,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
include_dev_dependencies=dev_dependencies,
channel_overrides=channel_overrides,
kinds=kind,
lockfile_path=pathlib.Path(lockfile),
extras=extras,
virtual_package_spec=virtual_package_spec,
update=update,
Expand Down Expand Up @@ -1073,14 +1082,14 @@ def handle_exception(exc_type, exc_value, exc_traceback):
"--dev/--no-dev",
is_flag=True,
default=True,
help="include dev dependencies in the lockfile (where applicable)",
help="install dev dependencies from the lockfile (where applicable)",
)
@click.option(
"-E",
"--extras",
multiple=True,
default=[],
help="include dev dependencies in the lockfile (where applicable)",
help="include extra dependencies from the lockfile (where applicable)",
)
@click.argument("lock-file", default=DEFAULT_LOCKFILE_NAME)
def install(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def test_poetry_version_parsing_constraints(package, version, url_pattern, capsy
lockfile_contents = create_lockfile_from_spec(
conda=_conda_exe,
spec=spec,
lockfile_path=pathlib.Path("conda-lock.toml"),
lockfile_path=pathlib.Path(DEFAULT_LOCKFILE_NAME),
)

python = next(p for p in lockfile_contents.package if p.name == "python")
Expand Down

0 comments on commit 1f5f224

Please sign in to comment.