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

v2 lint: add end to end tests #2029

Merged
merged 18 commits into from
Aug 10, 2024
14 changes: 9 additions & 5 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from inspect import cleandoc
from pathlib import Path
from textwrap import indent
from typing import List, Tuple
from typing import Any, List, Optional, Tuple

import github
import jsonschema
Expand Down Expand Up @@ -76,7 +76,7 @@
NEEDED_FAMILIES = ["gpl", "bsd", "mit", "apache", "psf"]


def lintify_forge_yaml(recipe_dir=None) -> (list, list):
def lintify_forge_yaml(recipe_dir: Optional[str] = None) -> (list, list):
if recipe_dir:
forge_yaml_filename = (
glob(os.path.join(recipe_dir, "..", "conda-forge.yml"))
Expand All @@ -100,9 +100,9 @@ def lintify_forge_yaml(recipe_dir=None) -> (list, list):


def lintify_meta_yaml(
meta,
recipe_dir=None,
conda_forge=False,
meta: Any,
recipe_dir: Optional[str] = None,
conda_forge: bool = False,
recipe_version: int = 0,
) -> Tuple[List[str], List[str]]:
lints = []
Expand Down Expand Up @@ -632,6 +632,9 @@ def main(
forge_config = _read_forge_config(feedstock_dir)
if forge_config.get("conda_build_tool", "") == RATTLER_BUILD_TOOL:
build_tool = RATTLER_BUILD_TOOL
else:
if os.path.exists(os.path.join(recipe_dir, "recipe.yaml")):
build_tool = RATTLER_BUILD_TOOL

if build_tool == RATTLER_BUILD_TOOL:
recipe_file = os.path.join(recipe_dir, "recipe.yaml")
Expand All @@ -651,6 +654,7 @@ def main(
meta = get_yaml().load(Path(recipe_file))

recipe_version = 1 if build_tool == RATTLER_BUILD_TOOL else 0

results, hints = lintify_meta_yaml(
meta,
recipe_dir,
Expand Down
20 changes: 5 additions & 15 deletions conda_smithy/linter/conda_recipe_v1_linter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
from typing import Any, Dict, List, Optional

Expand All @@ -9,7 +8,6 @@

from conda_smithy.linter.errors import HINT_NO_ARCH
from conda_smithy.linter.utils import (
TEST_FILES,
_lint_package_version,
_lint_recipe_name,
)
Expand All @@ -36,7 +34,6 @@
"about",
"extra",
]
TEST_KEYS = {"script", "python"}
JINJA_VAR_PAT = re.compile(r"\${{(.*?)}}")


Expand All @@ -50,27 +47,20 @@ def lint_recipe_tests(
tests_lints = []
tests_hints = []

if not any(key in TEST_KEYS for key in test_section):
a_test_file_exists = recipe_dir is not None and any(
os.path.exists(os.path.join(recipe_dir, test_file))
for test_file in TEST_FILES
)
if a_test_file_exists:
return

if not test_section:
if not outputs_section:
lints.append("The recipe must have some tests.")
else:
has_outputs_test = False
no_test_hints = []
for section in outputs_section:
test_section = section.get("tests", {})
if any(key in TEST_KEYS for key in test_section):
for output in outputs_section:
o_test_section = output.get("tests", [])
if o_test_section:
has_outputs_test = True
else:
no_test_hints.append(
"It looks like the '{}' output doesn't "
"have any tests.".format(section.get("name", "???"))
"have any tests.".format(output.get("name", "???"))
)
if has_outputs_test:
hints.extend(no_test_hints)
Expand Down
14 changes: 8 additions & 6 deletions conda_smithy/linter/lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def lint_recipe_maintainers(extra_section, lints):


def lint_recipe_have_tests(
recipe_dir,
test_section,
outputs_section,
lints,
hints,
recipe_dir: str,
test_section: List[Dict[str, Any]],
outputs_section: List[Dict[str, Any]],
lints: List[str],
hints: List[str],
recipe_version: int = 0,
):
if recipe_version == 1:
Expand Down Expand Up @@ -197,7 +197,9 @@ def lint_build_section_should_be_before_run(requirements_section, lints):
)


def lint_sources_should_have_hash(sources_section, lints):
def lint_sources_should_have_hash(
sources_section: List[Dict[str, Any]], lints: List[str]
):
for source_section in sources_section:
if "url" in source_section and not (
{"sha1", "sha256", "md5"} & set(source_section.keys())
Expand Down
4 changes: 2 additions & 2 deletions conda_smithy/linter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
FIELDS as _CONDA_BUILD_FIELDS,
)
from rattler_build_conda_compat import loader as rattler_loader
from rattler_build_conda_compat.recipe_sources import get_all_url_sources
from rattler_build_conda_compat.recipe_sources import get_all_sources

FIELDS = copy.deepcopy(_CONDA_BUILD_FIELDS)

Expand Down Expand Up @@ -78,7 +78,7 @@ def get_recipe_v1_section(meta, name) -> Union[Dict, List[Dict]]:
elif name == "tests":
return rattler_loader.load_all_tests(meta)
elif name == "source":
sources = get_all_url_sources(meta)
sources = get_all_sources(meta)
return list(sources)

return meta.get(name, {})
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ dependencies:
- jsonschema
- backports.strenum
- exceptiongroup
- rattler-build-conda-compat >=1.1.1,<2.0.0a0
- rattler-build-conda-compat >=1.2.0,<2.0.0a0
35 changes: 0 additions & 35 deletions tests/recipes/rattler_recipes/boltons_arch/recipe.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions tests/recipes/rattler_recipes/boltons_arch/variants.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 28 additions & 0 deletions tests/recipes/v1_recipes/recipe-lint-name-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
context:
version: "$!@#"

package:
name: foo@bar
version: ${{ version }}

source:
url: https://example.com/foo.tar.gz
sha256: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

build:
number: 0

tests:
- script:
- echo "Hello, world!"

about:
license: BSD-3-Clause
license_file: LICENSE.txt
homepage: https://example.com/foo
summary: A package that does foo.

extra:
recipe-maintainers:
- alice
- bob
25 changes: 25 additions & 0 deletions tests/recipes/v1_recipes/recipe-no-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package:
name: foo
version: 1.2.3

source:
url: https://example.com/foo.tar.gz
sha256: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

build:
number: 0

tests:
- script:
- echo "Hello, world!"

about:
license: BSD-3-Clause
license_file: LICENSE.txt
homepage: https://example.com/foo
summary: A package that does foo.

extra:
recipe-maintainers:
- Alice
- Bob
21 changes: 21 additions & 0 deletions tests/recipes/v1_recipes/recipe-no-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package:
name: foo
version: 1.2.3

source:
url: https://example.com/foo.tar.gz
sha256: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

build:
number: 0

about:
license: BSD-3-Clause
license_file: LICENSE.txt
homepage: https://example.com/foo
summary: A package that does foo.

extra:
recipe-maintainers:
- Alice
- Bob
Loading
Loading