Skip to content

Commit

Permalink
Merge pull request #564 from basnijholt/fix-only-pip
Browse files Browse the repository at this point in the history
Fix case when using multiple platforms but pip contains a single platform
  • Loading branch information
maresb authored Dec 1, 2023
2 parents f912d92 + 6ee68f1 commit 0481cc6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
45 changes: 24 additions & 21 deletions conda_lock/src_parser/environment_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,32 @@ def _parse_environment_file_for_platform(
dependencies.append(conda_spec_to_versioned_dep(spec, category))

for mapping_spec in mapping_specs:
if "pip" in mapping_spec:
for spec in mapping_spec["pip"]:
if re.match(r"^-e .*$", spec):
print(
(
f"Warning: editable pip dep '{spec}' will not be included in the lock file. "
"You will need to install it separately."
),
file=sys.stderr,
)
continue

dependencies.append(
parse_python_requirement(
spec,
manager="pip",
category=category,
normalize_name=False,
)
pip = mapping_spec.get("pip")
if pip is None:
# might not be present OR might be None due to platform selector
continue
for spec in pip:
if re.match(r"^-e .*$", spec):
print(
(
f"Warning: editable pip dep '{spec}' will not be included in the lock file. "
"You will need to install it separately."
),
file=sys.stderr,
)
continue

dependencies.append(
parse_python_requirement(
spec,
manager="pip",
category=category,
normalize_name=False,
)
)

# ensure pip is in target env
dependencies.append(parse_python_requirement("pip", manager="conda"))
# ensure pip is in target env
dependencies.append(parse_python_requirement("pip", manager="conda"))

return dependencies

Expand Down
10 changes: 10 additions & 0 deletions tests/test-pip-with-platform-selector/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: test-pip-with-platform-selector
channels:
- conda-forge
dependencies:
- tomli
- pip:
- psutil # [linux64]
platforms:
- linux-64
- osx-arm64
15 changes: 15 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,3 +2445,18 @@ def test_pip_finds_recent_manylinux_wheels(
# Make sure the manylinux wheel was built with glibc > 2.17 as a
# non-regression test for #517
assert manylinux_version > [2, 17]


def test_parse_environment_file_with_pip_and_platform_selector():
"""See https://github.com/conda/conda-lock/pull/564 for the context."""
env_file = TEST_DIR / "test-pip-with-platform-selector" / "environment.yml"
spec = parse_environment_file(env_file, platforms=["linux-64", "osx-arm64"])
assert spec.platforms == ["linux-64", "osx-arm64"]
assert spec.dependencies["osx-arm64"] == [
VersionedDependency(name="tomli", manager="conda", version="")
]
assert spec.dependencies["linux-64"] == [
VersionedDependency(name="tomli", manager="conda", version=""),
VersionedDependency(name="psutil", manager="pip", version="*"),
VersionedDependency(name="pip", manager="conda", version="*"),
]

0 comments on commit 0481cc6

Please sign in to comment.