Skip to content

Commit

Permalink
Extract package name from included and required packages (#283)
Browse files Browse the repository at this point in the history
* Extract package name from matchspec for conda packages

* Black formatting
  • Loading branch information
costrouc authored Apr 13, 2022
1 parent 21d28c5 commit a98b394
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
def conda_store_validate_specification(
conda_store: "CondaStore", namespace: str, specification: schema.CondaSpecification
) -> schema.CondaSpecification:
def _package_names(dependencies):
return {MatchSpec(_).name: _ for _ in dependencies if isinstance(_, str)}

# ============== MODIFICATION =================
# CondaStore.conda_default_channels
Expand All @@ -24,11 +26,11 @@ def conda_store_validate_specification(
specification.dependencies = conda_store.conda_default_packages.copy()

# CondaStore.conda_included_packages
dependency_names = set(
MatchSpec(_).name for _ in specification.dependencies if isinstance(_, str)
)
for package in set(conda_store.conda_included_packages) - dependency_names:
specification.dependencies.append(package)
included_packages = _package_names(conda_store.conda_included_packages)
for package in (
included_packages.keys() - _package_names(specification.dependencies).keys()
):
specification.dependencies.append(included_packages[package])

# ================ VALIDATION ===============
normalized_conda_channels = set(
Expand All @@ -47,12 +49,13 @@ def conda_store_validate_specification(
)

# validate that required conda package are in specification
dependency_names = set(
MatchSpec(_).name for _ in specification.dependencies if isinstance(_, str)
missing_packages = (
_package_names(conda_store.conda_required_packages).keys()
<= _package_names(specification.dependencies).keys()
)
if not (set(conda_store.conda_required_packages) <= dependency_names):
if not missing_packages:
raise ValueError(
f"Conda packages {conda_store.conda_required_packages - dependency_names} required and missing from specification"
f"Conda packages {missing_packages} required and missing from specification"
)

return specification
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
pythonPackages.filelock

pythonPackages.pytest
pythonPackages.black
pythonPackages.flake8
];
};
};
Expand Down

0 comments on commit a98b394

Please sign in to comment.