Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous PyPI to Conda dep name conversion for PyPI deps #701

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion conda_lock/src_parser/environment_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def _parse_environment_file_for_platform(
spec,
manager="pip",
category=category,
normalize_name=False,
mapping_url=mapping_url,
)
if evaluate_marker(dependency.markers, platform):
Expand Down
20 changes: 18 additions & 2 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ def parse_python_requirement(
mapping_url: str,
manager: Literal["conda", "pip"] = "conda",
category: str = "main",
normalize_name: bool = True,
) -> Dependency:
"""Parse a requirements.txt like requirement to a conda spec.

Expand All @@ -457,6 +456,23 @@ def parse_python_requirement(
VersionedDependency(name='my-package', manager='conda', category='main', extras=[],
markers=None, version='*', build=None, conda_channel=None, hash=None)

The PyPI name `build` will be translated to `python-build` for conda.
>>> parse_python_requirement(
... "build",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='python-build', manager='conda', category='main',
extras=[], markers=None, version='*', build=None, conda_channel=None, hash=None)

No translation is done for `manager="pip"`.
>>> parse_python_requirement(
... "build",
... manager="pip",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='build', manager='pip', category='main',
extras=[], markers=None, version='*', build=None, conda_channel=None, hash=None)

>>> parse_python_requirement(
... "My_Package[extra]==1.23",
... mapping_url=DEFAULT_MAPPING_URL,
Expand Down Expand Up @@ -500,7 +516,7 @@ def parse_python_requirement(
if conda_version:
conda_version = ",".join(sorted(conda_version.split(",")))

if normalize_name:
if manager == "conda":
conda_dep_name = pypi_name_to_conda_name(name, mapping_url=mapping_url)
else:
conda_dep_name = name
Expand Down
Loading