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

Support skipping python_min and pip_no_build_backend hints #2206

Merged
merged 7 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion conda_smithy/data/conda-forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,9 @@
},
"Lints": {
"enum": [
"lint_noarch_selectors"
"lint_noarch_selectors",
"hint_pip_no_build_backend",
"hint_python_min"
],
"title": "Lints",
"type": "string"
Expand Down
66 changes: 36 additions & 30 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def lintify_meta_yaml(
lints = []
hints = []
major_sections = list(meta.keys())
lints_to_skip = (
_get_forge_yaml(recipe_dir).get("linter", {}).get("skip", [])
)
lints_to_skip = (_get_forge_yaml(recipe_dir).get("linter") or {}).get(
"skip"
) or []

# If the recipe_dir exists (no guarantee within this function) , we can
# find the meta.yaml within it.
Expand Down Expand Up @@ -487,6 +487,10 @@ def run_conda_forge_specific(
hints,
recipe_version: int = 0,
):
lints_to_skip = (_get_forge_yaml(recipe_dir).get("linter") or {}).get(
"skip"
) or []

# Retrieve sections from meta
package_section = get_section(
meta, "package", lints, recipe_version=recipe_version
Expand Down Expand Up @@ -589,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 = []
_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)
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 All @@ -627,15 +632,16 @@ def run_conda_forge_specific(
)

# 10: check for proper noarch python syntax
hint_noarch_python_use_python_min(
requirements_section.get("host") or [],
requirements_section.get("run") or [],
test_reqs,
outputs_section,
noarch_value,
recipe_version,
hints,
)
if "hint_python_min" not in lints_to_skip:
hint_noarch_python_use_python_min(
requirements_section.get("host") or [],
requirements_section.get("run") or [],
test_reqs,
outputs_section,
noarch_value,
recipe_version,
hints,
)

# 11: ensure we can parse the recipe
if recipe_version == 1:
Expand Down
2 changes: 2 additions & 0 deletions conda_smithy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ 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
23 changes: 23 additions & 0 deletions news/skip-python-hints.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Add ``hint_python_min`` and ``hint_pip_no_build_backend`` values to ``linter.skip`` key, allowing to skip respective checks. (#2206)

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fix a ``TypeError`` when either the ``linter`` key or the ``skip`` subkey is empty. (#2206)

**Security:**

* <news item>
43 changes: 39 additions & 4 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 Expand Up @@ -3313,23 +3333,38 @@ def test_hint_pip_no_build_backend(
),
],
)
@pytest.mark.parametrize("skip", [False, True])
def test_hint_noarch_python_use_python_min(
meta_str,
expected_hints,
skip,
tmp_path,
):
if skip:
if not expected_hints:
pytest.skip("No hints expected")
Copy link
Member

Choose a reason for hiding this comment

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

Why should we need to skip this test if there are no expected hints? We could reformulate the test below to expect empty hints, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It always expected empty hints. I've skipped it because it's redundant, i.e. doesn't test anything.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I agree. It's still testing that the config in conda-forge.yml doesn't break the case of "no hints expected".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I'll update it. In the end, the skips don't save that much time, and could be confusing.

with open(tmp_path / "conda-forge.yml", "w") as fh:
fh.write(
"""
linter:
skip:
- hint_python_min
"""
)

meta = get_yaml().load(render_meta_yaml(meta_str))
lints = []
hints = []
linter.run_conda_forge_specific(
meta,
None,
str(tmp_path),
lints,
hints,
recipe_version=0,
)

# make sure we have the expected hints
if expected_hints:
if expected_hints and not skip:
for expected_hint in expected_hints:
assert any(expected_hint in hint for hint in hints), hints
else:
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading