Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 25 additions & 3 deletions conda_forge_tick/update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,22 @@ def is_expression_requirement(dep: str) -> bool:
return dep.startswith(r"${{")


def _dep_package_name(dep: str) -> str:
"""Return the package-token part of a conda dependency string."""
return dep.split()[0]


def _find_dep_index(deps: list[str], dep: str) -> int | None:
"""Find a dependency by exact text first, then by package token."""
if dep in deps:
return deps.index(dep)
package = _dep_package_name(dep)
for i, existing_dep in enumerate(deps):
if _dep_package_name(existing_dep) == package:
return i
return None


def _apply_env_dep_comparison(
deps: list[str], env_dep_comparison: EnvDepComparison
) -> list[str]:
Expand All @@ -779,12 +795,18 @@ def _apply_env_dep_comparison(
# Add new package.
if patch.before is None:
new_deps.append(patch.after) # type: ignore[arg-type]
continue

dep_index = _find_dep_index(new_deps, patch.before)
if dep_index is None:
continue

# Remove old package.
elif patch.after is None:
new_deps.remove(patch.before)
if patch.after is None:
new_deps.pop(dep_index)
Comment thread
beckermr marked this conversation as resolved.
# Update existing package.
else:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else:

new_deps[new_deps.index(patch.before)] = patch.after
new_deps[dep_index] = patch.after
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_deps[dep_index] = patch.after
new_deps[dep_index] = patch.after

return new_deps


Expand Down
25 changes: 25 additions & 0 deletions tests/test_update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from conda_forge_tick.recipe_parser import CondaMetaYAML
from conda_forge_tick.update_deps import (
DepComparison,
_apply_env_dep_comparison,
_merge_dep_comparisons_sec,
_modify_package_name_from_github,
_update_sec_deps,
Expand Down Expand Up @@ -180,6 +181,30 @@ def test_get_depfinder_comparison():
assert "host" not in d


def test_apply_env_dep_comparison_matches_dependency_by_package_name():
deps = [
"cuda-version >=12,<13",
"cuda-nvcc-impl >=12.0",
"python >=3.11",
]
env_dep_comparison = {
"cf_minus_df": {"cuda-version", "cuda-nvcc-impl"},
"df_minus_cf": set(),
}

assert _apply_env_dep_comparison(deps, env_dep_comparison) == ["python >=3.11"]


def test_apply_env_dep_comparison_ignores_missing_dependency_text():
deps = ["cuda-version >=12,<13", "python >=3.11"]
env_dep_comparison = {
"cf_minus_df": {"cuda-cudart-dev"},
"df_minus_cf": set(),
}

assert _apply_env_dep_comparison(deps, env_dep_comparison) == deps


praw_recipe = """\
{% set name = "praw" %}
{% set import = "praw" %}
Expand Down
Loading