From e4f82d84bee53d1d9d5038b11c783002793dbbc9 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 25 Oct 2022 09:49:25 -0500 Subject: [PATCH 1/3] allow selectors in noarch_platforms recipes --- conda_smithy/lint_recipe.py | 36 ++++++++-- news/noarch_platforms.rst | 23 ++++++ .../recipes/noarch_platforms/conda-forge.yml | 13 ++++ .../recipes/noarch_platforms/recipe/meta.yaml | 71 +++++++++++++++++++ tests/test_lint_recipe.py | 6 ++ 5 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 news/noarch_platforms.rst create mode 100644 tests/recipes/noarch_platforms/conda-forge.yml create mode 100644 tests/recipes/noarch_platforms/recipe/meta.yaml diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index f3dc5fa2c..2a268626a 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -384,8 +384,25 @@ def lintify(meta, recipe_dir=None, conda_forge=False): ) ) + if recipe_dir: + forge_yaml_filename = glob( + os.path.join(recipe_dir, "..", "conda-forge.yml") + ) or glob( + os.path.join(recipe_dir, "conda-forge.yml"), + ) or glob( + os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), + ) + if forge_yaml_filename: + with open(forge_yaml_filename[0], "r") as fh: + forge_yaml = get_yaml().load(fh) + else: + forge_yaml = {} + else: + forge_yaml = {} + # 18: noarch doesn't work with selectors for runtime dependencies if noarch_value is not None and os.path.exists(meta_fname): + noarch_platforms = len(forge_yaml.get("noarch_platforms", [])) > 1 with io.open(meta_fname, "rt") as fh: in_runreqs = False for line in fh: @@ -396,7 +413,7 @@ def lintify(meta, recipe_dir=None, conda_forge=False): continue if line_s.startswith("skip:") and is_selector_line(line): lints.append( - "`noarch` packages can't have selectors. If " + "`noarch` packages can't have skips with selectors. If " "the selectors are necessary, please remove " "`noarch: {}`.".format(noarch_value) ) @@ -405,7 +422,7 @@ def lintify(meta, recipe_dir=None, conda_forge=False): if runreqs_spacing == line[: -len(line.lstrip())]: in_runreqs = False continue - if is_selector_line(line): + if is_selector_line(line, allow_platforms=noarch_platforms): lints.append( "`noarch` packages can't have selectors. If " "the selectors are necessary, please remove " @@ -662,9 +679,14 @@ def check_pins_build_and_requirements(top_level): shell_scripts = [] if recipe_dir: shell_scripts = glob(os.path.join(recipe_dir, "*.sh")) - # support feedstocks and staged-recipes + # support + # 1. feedstocks + # 2. staged-recipes with custom conda-forge.yaml in recipe + # 3. staged-recipes forge_yaml = glob( os.path.join(recipe_dir, "..", "conda-forge.yml") + ) or glob( + os.path.join(recipe_dir, "conda-forge.yml"), ) or glob( os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), ) @@ -904,7 +926,7 @@ def run_conda_forge_specific(meta, recipe_dir, lints, hints): hints.append(msg) -def is_selector_line(line): +def is_selector_line(line, allow_platforms=False): # Using the same pattern defined in conda-build (metadata.py), # we identify selectors. line = line.rstrip() @@ -913,8 +935,10 @@ def is_selector_line(line): return False m = sel_pat.match(line) if m: - m.group(3) - return True + if allow_platforms and m.group(3) in ["win", "linux", "osx", "unix"]: + return False + else: + return True return False diff --git a/news/noarch_platforms.rst b/news/noarch_platforms.rst new file mode 100644 index 000000000..13f1abce3 --- /dev/null +++ b/news/noarch_platforms.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* recipes with ``noarch_platforms`` will no longer give a lint when selectors are used. + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/tests/recipes/noarch_platforms/conda-forge.yml b/tests/recipes/noarch_platforms/conda-forge.yml new file mode 100644 index 000000000..f39dd4e96 --- /dev/null +++ b/tests/recipes/noarch_platforms/conda-forge.yml @@ -0,0 +1,13 @@ +build_platform: + osx_arm64: osx_64 +conda_forge_output_validation: true +github: + branch_name: main + tooling_branch_name: main +provider: + linux_aarch64: default + linux_ppc64le: default +test_on_native_only: true +noarch_platforms: + - linux_64 + - win_64 diff --git a/tests/recipes/noarch_platforms/recipe/meta.yaml b/tests/recipes/noarch_platforms/recipe/meta.yaml new file mode 100644 index 000000000..b8b1a551d --- /dev/null +++ b/tests/recipes/noarch_platforms/recipe/meta.yaml @@ -0,0 +1,71 @@ +{% set version = "7.1.3" %} + +package: + name: pytest + version: {{ version }} + +source: + url: https://pypi.io/packages/source/p/pytest/pytest-{{ version }}.tar.gz + sha256: 4f365fec2dff9c1162f834d9f18af1ba13062db0c708bf7b946f8a5c76180c39 + +build: + number: 1 + script: {{ PYTHON }} setup.py install --single-version-externally-managed --record record.txt + entry_points: + - pytest = pytest:console_main + - py.test = pytest:console_main + noarch: python + string: "win_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}" # [win] + string: "unix_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}" # [unix] + + +requirements: + build: + - python # [build_platform != target_platform] + - cross-python_{{ target_platform }} # [build_platform != target_platform] + host: + - pip + - python >=3.8 + - setuptools >=42.0 + - setuptools_scm >=6.0 + run: + - python >=3.8 + - attrs >=19.2.0 + - iniconfig + - packaging + - pluggy >=0.12,<2.0 + - py >=1.8.2 + - tomli >=1.0.0 + - colorama # [win] + - __win # [win] + - __unix # [unix] + + run_constrained: + # pytest-faulthandler 2 is a dummy package. + # if an older version of fault-handler is installed, it will conflict with pytest >=5. + - pytest-faulthandler >=2 + +test: + commands: + - pytest -h + imports: + - pytest + +about: + home: https://docs.pytest.org/en/latest/ + license: MIT + license_file: LICENSE + summary: Simple and powerful testing with Python. + description: | + The pytest framework makes it easy to write small tests, yet scales to + support complex functional testing for applications and libraries. + doc_url: https://docs.pytest.org/en/latest/ + dev_url: https://github.com/pytest-dev/pytest/ + +extra: + recipe-maintainers: + - flub + - goanpeca + - nicoddemus + - ocefpaf + - mingwandroid diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 2e30bfc25..9c2c76298 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -1179,6 +1179,12 @@ def test_multiple_sources(self): ) assert not lints + def test_noarch_platforms(self): + lints = linter.main( + os.path.join(_thisdir, "recipes", "noarch_platforms", "recipe") + ) + assert not lints + def test_string_source(self): url = "http://mistake.com/v1.0.tar.gz" lints, hints = linter.lintify({"source": url}) From cc25aa9a04d3e604af08ec7a86f44c259ad01360 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 25 Oct 2022 10:02:39 -0500 Subject: [PATCH 2/3] pre-commit --- conda_smithy/lint_recipe.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index 2a268626a..bb217e01f 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -385,12 +385,14 @@ def lintify(meta, recipe_dir=None, conda_forge=False): ) if recipe_dir: - forge_yaml_filename = glob( - os.path.join(recipe_dir, "..", "conda-forge.yml") - ) or glob( - os.path.join(recipe_dir, "conda-forge.yml"), - ) or glob( - os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), + forge_yaml_filename = ( + glob(os.path.join(recipe_dir, "..", "conda-forge.yml")) + or glob( + os.path.join(recipe_dir, "conda-forge.yml"), + ) + or glob( + os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), + ) ) if forge_yaml_filename: with open(forge_yaml_filename[0], "r") as fh: @@ -422,7 +424,9 @@ def lintify(meta, recipe_dir=None, conda_forge=False): if runreqs_spacing == line[: -len(line.lstrip())]: in_runreqs = False continue - if is_selector_line(line, allow_platforms=noarch_platforms): + if is_selector_line( + line, allow_platforms=noarch_platforms + ): lints.append( "`noarch` packages can't have selectors. If " "the selectors are necessary, please remove " @@ -683,12 +687,14 @@ def check_pins_build_and_requirements(top_level): # 1. feedstocks # 2. staged-recipes with custom conda-forge.yaml in recipe # 3. staged-recipes - forge_yaml = glob( - os.path.join(recipe_dir, "..", "conda-forge.yml") - ) or glob( - os.path.join(recipe_dir, "conda-forge.yml"), - ) or glob( - os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), + forge_yaml = ( + glob(os.path.join(recipe_dir, "..", "conda-forge.yml")) + or glob( + os.path.join(recipe_dir, "conda-forge.yml"), + ) + or glob( + os.path.join(recipe_dir, "..", "..", "conda-forge.yml"), + ) ) if shell_scripts and forge_yaml: with open(forge_yaml[0], "r") as fh: From d349fa796e9df05b4d7d9230bb36cdc438af2a0f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 25 Oct 2022 10:11:28 -0500 Subject: [PATCH 3/3] fix tests --- tests/test_lint_recipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 9c2c76298..5055b1799 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -415,7 +415,7 @@ def assert_pyXY_selector(meta_string, is_good=False, kind="lint"): ) def test_noarch_selectors(self): - expected_start = "`noarch` packages can't have selectors." + expected_start = "`noarch` packages can't have" with tmp_directory() as recipe_dir: