Skip to content

Commit

Permalink
Merge branch 'main' into remove-pip-dev-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Oct 11, 2023
2 parents 5391eee + 425b384 commit a879f12
Show file tree
Hide file tree
Showing 17 changed files with 2,316 additions and 2,129 deletions.
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/update-lockfile.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Run conda-lock to update dependencies

on:
push:
branches:
- main
workflow_dispatch:
schedule:
# At 5:28am UTC Monday and Thursday
Expand Down
16 changes: 2 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,17 @@ repos:
- id: check-ast

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
language_version: python3

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
rev: v0.0.291
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

# Ruff should catch (and mostly fix) everything that flake8 and isort do; if
# either of these checks fails, can Ruff's config be updated to catch the same?
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
Expand Down
56 changes: 38 additions & 18 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def fn_to_dist_name(fn: str) -> str:
return fn


def make_lock_files(
def make_lock_files( # noqa: C901
*,
conda: PathLike,
src_files: List[pathlib.Path],
Expand Down Expand Up @@ -341,35 +341,35 @@ def make_lock_files(
virtual_package_repo=virtual_package_repo,
required_categories=required_categories if filter_categories else None,
)
lock_content: Optional[Lockfile] = None
original_lock_content: Optional[Lockfile] = None

platforms_to_lock: List[str] = []
platforms_already_locked: List[str] = []
if lockfile_path.exists():
import yaml

try:
lock_content = parse_conda_lock_file(lockfile_path)
original_lock_content = parse_conda_lock_file(lockfile_path)
except (yaml.error.YAMLError, FileNotFoundError):
logger.warning(
"Failed to parse existing lock. Regenerating from scratch"
)
lock_content = None
original_lock_content = None
else:
lock_content = None
original_lock_content = None

if lock_content is not None:
platforms_already_locked = list(lock_content.metadata.platforms)
platforms_to_lock: List[str] = []
platforms_already_locked: List[str] = []
if original_lock_content is not None:
platforms_already_locked = list(original_lock_content.metadata.platforms)
update_spec = UpdateSpecification(
locked=lock_content.package, update=update
locked=original_lock_content.package, update=update
)
for platform in lock_spec.platforms:
if (
update
or platform not in lock_content.metadata.platforms
or platform not in platforms_already_locked
or not check_input_hash
or lock_spec.content_hash_for_platform(platform)
!= lock_content.metadata.content_hash[platform]
!= original_lock_content.metadata.content_hash[platform]
):
platforms_to_lock.append(platform)
if platform in platforms_already_locked:
Expand All @@ -385,9 +385,12 @@ def make_lock_files(
)
platforms_to_lock = sorted(set(platforms_to_lock))

if platforms_to_lock:
if not platforms_to_lock:
new_lock_content = original_lock_content
else:
print(f"Locking dependencies for {platforms_to_lock}...", file=sys.stderr)
lock_content = lock_content | create_lockfile_from_spec(

fresh_lock_content = create_lockfile_from_spec(
conda=conda,
spec=lock_spec,
platforms=platforms_to_lock,
Expand All @@ -398,9 +401,24 @@ def make_lock_files(
strip_auth=strip_auth,
)

if not original_lock_content:
new_lock_content = fresh_lock_content
else:
# Persist packages from original lockfile for platforms not requested for lock
packages_not_to_lock = [
dep
for dep in original_lock_content.package
if dep.platform not in platforms_to_lock
]
lock_content_to_persist = original_lock_content.copy(
deep=True,
update={"package": packages_not_to_lock},
)
new_lock_content = lock_content_to_persist | fresh_lock_content

if "lock" in kinds:
write_conda_lock_file(
lock_content,
new_lock_content,
lockfile_path,
metadata_choices=metadata_choices,
)
Expand All @@ -410,7 +428,9 @@ def make_lock_files(
file=sys.stderr,
)

assert lock_content is not None
# After this point, we're working with `new_lock_content`, never
# `original_lock_content` or `fresh_lock_content`.
assert new_lock_content is not None

# check for implicit inclusion of cudatoolkit
# warn if it was pulled in, but not requested explicitly
Expand All @@ -422,13 +442,13 @@ def make_lock_files(
for pkg in itertools.chain(*lock_spec.dependencies.values())
)
if not cudatoolkit_requested:
for package in lock_content.package:
for package in new_lock_content.package:
if package.name == "cudatoolkit":
logger.warning(_implicit_cuda_message)
break

do_render(
lock_content,
new_lock_content,
kinds=[k for k in kinds if k != "lock"],
include_dev_dependencies=include_dev_dependencies,
filename_template=filename_template,
Expand Down
7 changes: 3 additions & 4 deletions conda_lock/lockfile/v2prelim/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# isort: skip_file
# TODO: Remove the isort skip comment above if/when isort is no longer used. This skip
# exists because isort and ruff disagree about how to sort the imports in this file.
from collections import defaultdict
from typing import ClassVar, Dict, List, Optional

Expand All @@ -10,10 +7,12 @@
GitMeta,
HashModel,
InputMeta,
LockMeta,
MetadataOption,
TimeMeta,
)
from conda_lock.lockfile.v1.models import LockedDependency as LockedDependencyV1
from conda_lock.lockfile.v1.models import Lockfile as LockfileV1
from conda_lock.lockfile.v1.models import LockMeta, MetadataOption, TimeMeta
from conda_lock.models import StrictModel


Expand Down
15 changes: 15 additions & 0 deletions environments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# How to install dev environment

* First install dev dependencies:

```
mamba env create -f environments/dev-environment.yaml
mamba activate conda-lock-dev
```

* Then, install `conda-lock` in editable mode. This will also install its runtime
dependencies as defined in `pyproject.toml`.

```
pip install --editable .
```
Loading

0 comments on commit a879f12

Please sign in to comment.