Skip to content

Commit

Permalink
Remove Unnecessary aggregate_lock_spec in environment-yaml parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
srilman committed Mar 4, 2023
1 parent 1d4172f commit fd49270
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions conda_lock/src_parser/environment_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import yaml

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 All @@ -27,10 +26,10 @@ def parse_conda_requirement(req: str) -> Tuple[str, str]:


def _parse_environment_file_for_platform(
environment_file: pathlib.Path,
content: str,
category: str,
platform: str,
) -> LockSpecification:
) -> List[Dependency]:
"""
Parse dependencies from a conda environment specification for an
assumed target platform.
Expand All @@ -44,12 +43,7 @@ def _parse_environment_file_for_platform(
"""
filtered_content = "\n".join(filter_platform_selectors(content, platform=platform))
env_yaml_data = yaml.safe_load(filtered_content)

specs = env_yaml_data["dependencies"]
channels: List[str] = env_yaml_data.get("channels", [])

# These extension fields are nonstandard
category: str = env_yaml_data.get("category") or "main"

# Split out any sub spec sections from the dependencies mapping
mapping_specs = [x for x in specs if not isinstance(x, str)]
Expand Down Expand Up @@ -87,11 +81,7 @@ def _parse_environment_file_for_platform(
# ensure pip is in target env
dependencies.append(parse_python_requirement("pip", manager="conda"))

return LockSpecification(
dependencies={platform: dependencies},
channels=channels, # type: ignore
sources=[environment_file],
)
return dependencies


def parse_platforms_from_env_file(environment_file: pathlib.Path) -> List[str]:
Expand Down Expand Up @@ -125,22 +115,20 @@ def parse_environment_file(
with environment_file.open("r") as fo:
content = fo.read()

# Parse with selectors for each target platform
spec = aggregate_lock_specs(
[
_parse_environment_file_for_platform(
environment_file,
content,
platform,
)
for platform in platforms
]
)
env_yaml_data = yaml.safe_load(content)
channels: List[str] = env_yaml_data.get("channels", [])

# 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
# These extension fields are nonstandard
category: str = env_yaml_data.get("category") or "main"

return spec
# Parse with selectors for each target platform
dep_map = {
platform: _parse_environment_file_for_platform(content, category, platform)
for platform in platforms
}

return LockSpecification(
dependencies=dep_map,
channels=channels, # type: ignore
sources=[environment_file],
)

0 comments on commit fd49270

Please sign in to comment.