Skip to content

Commit

Permalink
Support skipping pip_no_build_backend hints
Browse files Browse the repository at this point in the history
Support skipping the hints about missing build backend dependency,
e.g. when the package itself is providing the build backend
(e.g. in poetry-core-feedstock).

Also requested in issue conda-forge#2170.
  • Loading branch information
mgorny committed Jan 6, 2025
1 parent 0f642d0 commit 8cd888d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions conda_smithy/data/conda-forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@
"Lints": {
"enum": [
"lint_noarch_selectors",
"hint_pip_no_build_backend",
"hint_python_min"
],
"title": "Lints",
Expand Down
39 changes: 20 additions & 19 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,26 +593,27 @@ def run_conda_forge_specific(
)

# 8: Ensure the recipe specifies a Python build backend if needed
host_or_build_reqs = (requirements_section.get("host") or []) or (
requirements_section.get("build") or []
)
hint_pip_no_build_backend(host_or_build_reqs, recipe_name, hints)
for out in outputs_section:
if recipe_version == 1:
output_requirements = rattler_loader.load_all_requirements(out)
build_reqs = output_requirements.get("build") or []
host_reqs = output_requirements.get("host") or []
else:
_req = out.get("requirements") or {}
if isinstance(_req, Mapping):
build_reqs = _req.get("build") or []
host_reqs = _req.get("host") or []
if "hint_pip_no_build_backend" not in lints_to_skip:
host_or_build_reqs = (requirements_section.get("host") or []) or (
requirements_section.get("build") or []
)
hint_pip_no_build_backend(host_or_build_reqs, recipe_name, hints)
for out in outputs_section:
if recipe_version == 1:
output_requirements = rattler_loader.load_all_requirements(out)
build_reqs = output_requirements.get("build") or []
host_reqs = output_requirements.get("host") or []
else:
build_reqs = []
host_reqs = []

name = out.get("name", "").strip()
hint_pip_no_build_backend(host_reqs or build_reqs, name, hints)
_req = out.get("requirements") or {}
if isinstance(_req, Mapping):
build_reqs = _req.get("build") or []
host_reqs = _req.get("host") or []
else:
build_reqs = []
host_reqs = []

name = out.get("name", "").strip()
hint_pip_no_build_backend(host_reqs or build_reqs, name, hints)

# 9: No duplicates in conda-forge.yml
if (
Expand Down
1 change: 1 addition & 0 deletions conda_smithy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class BotConfigVersionUpdatesSourcesChoice(StrEnum):

class Lints(StrEnum):
LINT_NOARCH_SELECTORS = "lint_noarch_selectors"
HINT_PIP_NO_BUILD_BACKEND = "hint_pip_no_build_backend"
HINT_PYTHON_MIN = "hint_python_min"


Expand Down
24 changes: 22 additions & 2 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3055,14 +3055,31 @@ def test_v1_package_name_version():
),
],
)
@pytest.mark.parametrize("skip", [False, True])
def test_hint_pip_no_build_backend(
meta_str,
expected_hints,
backend,
outputs_to_add,
outputs_expected_hints,
remove_top_level,
skip,
tmp_path,
):
if skip:
if (
not expected_hints or remove_top_level
) and not outputs_expected_hints:
pytest.skip("No hints expected")
with open(tmp_path / "conda-forge.yml", "w") as fh:
fh.write(
"""
linter:
skip:
- hint_pip_no_build_backend
"""
)

meta = get_yaml().load(meta_str.replace("@@backend@@", backend))
if remove_top_level:
meta.pop("requirements", None)
Expand All @@ -3076,13 +3093,16 @@ def test_hint_pip_no_build_backend(
outputs_to_add.replace("@@backend@@", backend)
)

total_expected_hints = _expected_hints + outputs_expected_hints
if skip:
total_expected_hints = []
else:
total_expected_hints = _expected_hints + outputs_expected_hints

lints = []
hints = []
linter.run_conda_forge_specific(
meta,
None,
str(tmp_path),
lints,
hints,
recipe_version=0,
Expand Down

0 comments on commit 8cd888d

Please sign in to comment.