Skip to content

Commit

Permalink
Fix case when using multiple platforms but pip contains a single plat…
Browse files Browse the repository at this point in the history
…form

Prevents
```
  File "/Users/bas.nijholt/micromamba/lib/python3.11/site-packages/conda_lock/src_parser/environment_yaml.py", line 58, in _parse_environment_file_for_platform
    for spec in mapping_spec["pip"]:
TypeError: 'NoneType' object is not iterable
```
Which occurs when locking:
```
name: example
channels:
  - conda-forge
dependencies:
  - tomli
  - pip:
    - psutil  # [linux64]
platforms:
  - linux-64
  - osx-arm64
```
Which becomes:
```
env_yaml_data = {'name': 'test-pip-with-platform-selector', 'channels': ['conda-forge'], 'dependencies': ['tomli', {'pip': None}], 'platforms': ['linux-64', 'osx-arm64']}
```
For `osx-arm64`.

This fix skips `{"pip": None}`.
  • Loading branch information
basnijholt committed Nov 30, 2023
1 parent f912d92 commit 857c430
Show file tree
Hide file tree
Showing 2 changed files with 34 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

0 comments on commit 857c430

Please sign in to comment.