Skip to content

Commit

Permalink
Change category → categories in LockedDependencyV2
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Jan 24, 2024
1 parent 1715f5a commit 20049ff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def render_lockfile_for_platform( # noqa: C901
lockfile.filter_virtual_packages_inplace()

for p in lockfile.package:
if p.platform == platform and len({p.category} & categories_to_install) > 0:
if p.platform == platform and len(p.categories & categories_to_install) > 0:
if p.manager == "pip":
pip_deps.append(p)
elif p.manager == "conda":
Expand Down
4 changes: 2 additions & 2 deletions conda_lock/lockfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def dep_name(manager: str, dep: str) -> str:
if not isinstance(targets, list):
targets = [targets]
for target in targets:
target.category = source.category
target.categories = {source.category}


def parse_conda_lock_file(path: pathlib.Path) -> Lockfile:
Expand Down Expand Up @@ -163,7 +163,7 @@ def write_conda_lock_file(
content.filter_virtual_packages_inplace()
with path.open("w") as f:
if include_help_text:
categories: Set[str] = set().union(*({p.category} for p in content.package))
categories: Set[str] = set().union(*(p.categories for p in content.package))

def write_section(text: str) -> None:
lines = dedent(text).split("\n")
Expand Down
9 changes: 3 additions & 6 deletions conda_lock/lockfile/v2prelim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class LockedDependency(BaseLockedDependency):
category: str = "main"
categories: Set[str] = {"main"}

def to_v1(self) -> List[LockedDependencyV1]:
"""Convert a v2 dependency into a list of v1 dependencies.
Expand All @@ -41,7 +41,7 @@ def to_v1(self) -> List[LockedDependencyV1]:
build=self.build,
optional=category != "main",
)
for category in sorted({self.category})
for category in sorted(self.categories)
]
return package_entries_per_category

Expand Down Expand Up @@ -167,9 +167,6 @@ def _locked_dependency_v1_to_v2(
# Each entry should correspond to a distinct category
assert len(categories) == len(package_entries_per_category)

# Until we allow multiple categories in v2 we need this workaround
single_category = package_entries_per_category[0].category

return LockedDependency(
name=package_entries_per_category[0].name,
version=package_entries_per_category[0].version,
Expand All @@ -178,7 +175,7 @@ def _locked_dependency_v1_to_v2(
dependencies=package_entries_per_category[0].dependencies,
url=package_entries_per_category[0].url,
hash=package_entries_per_category[0].hash,
category=single_category,
categories=categories,
source=package_entries_per_category[0].source,
build=package_entries_per_category[0].build,
)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import tempfile
import typing
import uuid
import warnings

from glob import glob
from pathlib import Path
Expand Down Expand Up @@ -385,10 +384,10 @@ def test_lock_poetry_ibis(
)
lockfile = parse_conda_lock_file(pyproject.parent / DEFAULT_LOCKFILE_NAME)

all_categories = set()
all_categories: Set[str] = set()

for pkg in lockfile.package:
all_categories.add(pkg.category)
all_categories.update(pkg.categories)

for desired_category in extra_categories:
assert (
Expand Down

0 comments on commit 20049ff

Please sign in to comment.