Skip to content

Commit

Permalink
Remove Unnecessary aggregate_lock_spec in meta-yaml parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
srilman committed Mar 4, 2023
1 parent fd49270 commit 236651c
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions conda_lock/src_parser/meta_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from conda_lock.common import get_in
from conda_lock.models.lock_spec import Dependency, LockSpecification
from conda_lock.src_parser.aggregation import aggregate_lock_specs
from conda_lock.src_parser.conda_common import conda_spec_to_versioned_dep
from conda_lock.src_parser.selectors import filter_platform_selectors


Expand Down Expand Up @@ -94,32 +94,37 @@ def parse_meta_yaml_file(
selectors other than platform.
"""

if not meta_yaml_file.exists():
raise FileNotFoundError(f"{meta_yaml_file} not found")

with meta_yaml_file.open("r") as fo:
t = jinja2.Template(fo.read(), undefined=UndefinedNeverFail)
rendered = t.render()
meta_yaml_data = yaml.safe_load(rendered)

channels = get_in(["extra", "channels"], meta_yaml_data, [])

# parse with selectors for each target platform
spec = aggregate_lock_specs(
[
_parse_meta_yaml_file_for_platform(meta_yaml_file, platform)
for platform in platforms
]
)
# remove platform selectors if they apply to all targets
for platform in spec.platforms:
for dep in spec.dependencies[platform]:
if dep.selectors.platform == platforms:
dep.selectors.platform = None
dep_map = {
platform: _parse_meta_yaml_file_for_platform(meta_yaml_file, platform)
for platform in platforms
}

return spec
return LockSpecification(
dependencies=dep_map,
channels=channels,
sources=[meta_yaml_file],
)


def _parse_meta_yaml_file_for_platform(
meta_yaml_file: pathlib.Path,
platform: str,
) -> LockSpecification:
) -> List[Dependency]:
"""Parse a simple meta-yaml file for dependencies, assuming the target platform.
* This does not support multi-output files and will ignore all lines with selectors other than platform
"""
if not meta_yaml_file.exists():
raise FileNotFoundError(f"{meta_yaml_file} not found")

with meta_yaml_file.open("r") as fo:
filtered_recipe = "\n".join(
Expand All @@ -130,15 +135,12 @@ def _parse_meta_yaml_file_for_platform(

meta_yaml_data = yaml.safe_load(rendered)

channels = get_in(["extra", "channels"], meta_yaml_data, [])
dependencies: List[Dependency] = []

def add_spec(spec: str, category: str) -> None:
if spec is None:
return

from .conda_common import conda_spec_to_versioned_dep

dep = conda_spec_to_versioned_dep(spec, category)
dep.selectors.platform = [platform]
dependencies.append(dep)
Expand All @@ -155,8 +157,4 @@ def add_requirements_from_recipe_or_output(yaml_data: Dict[str, Any]) -> None:
for output in get_in(["outputs"], meta_yaml_data, []):
add_requirements_from_recipe_or_output(output)

return LockSpecification(
dependencies={platform: dependencies},
channels=channels,
sources=[meta_yaml_file],
)
return dependencies

0 comments on commit 236651c

Please sign in to comment.