Skip to content

Commit 938abfe

Browse files
mgornybeckermr
andauthored
Enable CondaForgeYAMLCleanup migrator for v1 recipes (#3765)
* Enable `CondaForgeYAMLCleanup` migrator for v1 recipes Enable `CondaForgeYAMLCleanup` migrator for v1 recipes. Since it works on `conda-forge.yml` only, it does not require any changes. So the most of the changes are related to extending the test. * Fix handling v1recipes with no `license_file` Fix an exception when the tested v1 recipe has no `license_file` key: E TypeError: 'NoneType' object is not subscriptable * Fix formatting * Add schema version check to `MiniMigrator.filter()` * Call superclass in `CondaForgeYAMLCleanup.filter()` * Actually enable schema version 1 in `CondaForgeYAMLCleanup` --------- Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
1 parent 8e82c6b commit 938abfe

File tree

7 files changed

+112
-9
lines changed

7 files changed

+112
-9
lines changed

conda_forge_tick/migrators/conda_forge_yaml_cleanup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class CondaForgeYAMLCleanup(MiniMigrator):
15+
allowed_schema_versions = {0, 1}
1516
keys_to_remove = [
1617
"min_r_ver",
1718
"max_r_ver",
@@ -26,6 +27,9 @@ class CondaForgeYAMLCleanup(MiniMigrator):
2627

2728
def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
2829
"""remove recipes without a conda-forge.yml file that has the keys to remove or change"""
30+
if super().filter(attrs):
31+
return True
32+
2933
cfy = attrs.get("conda-forge.yml", {})
3034
if any(key in cfy for key in (self.keys_to_remove + self.keys_to_change)):
3135
return False

conda_forge_tick/migrators/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
187187
bool :
188188
True if node is to be skipped
189189
"""
190-
return True
190+
return skip_migrator_due_to_schema(attrs, self.allowed_schema_versions)
191191

192192
def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> None:
193193
"""Perform the migration, updating the ``meta.yaml``

conda_forge_tick/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def _parse_recipes(
535535
"home": about.get("homepage"),
536536
"license": about.get("license"),
537537
"license_family": about.get("license"),
538-
"license_file": about.get("license_file")[0],
538+
"license_file": about.get("license_file", [None])[0],
539539
"summary": about.get("summary"),
540540
}
541541
)

tests/test_cfyaml_cleanup_migrator.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
piggy_back_migrations=[CondaForgeYAMLCleanup()],
1212
)
1313

14-
YAML_PATH = os.path.join(os.path.dirname(__file__), "test_yaml")
14+
YAML_PATHS = [
15+
os.path.join(os.path.dirname(__file__), "test_yaml"),
16+
os.path.join(os.path.dirname(__file__), "test_v1_yaml"),
17+
]
1518

1619

1720
@pytest.mark.parametrize(
@@ -27,14 +30,19 @@
2730
("compiler_stack"),
2831
],
2932
)
30-
def test_version_cfyaml_cleanup(cases, tmpdir):
33+
@pytest.mark.parametrize("recipe_version", [0, 1])
34+
def test_version_cfyaml_cleanup(cases, recipe_version, tmpdir):
3135
yaml = YAML()
3236

33-
with open(os.path.join(YAML_PATH, "version_cfyaml_cleanup_simple.yaml")) as fp:
37+
with open(
38+
os.path.join(YAML_PATHS[recipe_version], "version_cfyaml_cleanup_simple.yaml")
39+
) as fp:
3440
in_yaml = fp.read()
3541

3642
with open(
37-
os.path.join(YAML_PATH, "version_cfyaml_cleanup_simple_correct.yaml"),
43+
os.path.join(
44+
YAML_PATHS[recipe_version], "version_cfyaml_cleanup_simple_correct.yaml"
45+
),
3846
) as fp:
3947
out_yaml = fp.read()
4048

@@ -59,7 +67,8 @@ def test_version_cfyaml_cleanup(cases, tmpdir):
5967
"migrator_version": Version.migrator_version,
6068
"version": "0.9",
6169
},
62-
tmpdir=os.path.join(tmpdir, "recipe"),
70+
tmpdir=os.path.join(tmpdir, "recipe" if recipe_version == 0 else "."),
71+
recipe_version=recipe_version,
6372
)
6473

6574
with open(cf_yml_pth) as fp:

tests/test_migrators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def run_test_migration(
488488
recipe_dir_p = tmpdir_p
489489
elif recipe_version == 1:
490490
tmpdir_p.joinpath(".ci_support").mkdir()
491-
tmpdir_p.joinpath("recipe").mkdir()
491+
tmpdir_p.joinpath("recipe").mkdir(exist_ok=True)
492492
tmpdir_p.joinpath("recipe", "recipe.yaml").write_text(inp)
493493

494494
build_variants = (
@@ -527,7 +527,7 @@ def run_test_migration(
527527
recipe_dir = str(recipe_dir_p)
528528

529529
# read the conda-forge.yml
530-
cf_yml_path = Path(tmpdir).parent / "conda-forge.yml"
530+
cf_yml_path = recipe_dir_p.parent / "conda-forge.yml"
531531
cf_yml = cf_yml_path.read_text() if cf_yml_path.exists() else "{}"
532532

533533
# Load the meta.yaml (this is done in the graph)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
schema_version: 1
2+
3+
context:
4+
version: 0.8
5+
6+
package:
7+
name: viscm
8+
version: ${{ version }}
9+
10+
source:
11+
url: https://pypi.io/packages/source/v/viscm/viscm-v${{ version }}.zip
12+
sha256: 5a9677fa4751c6dd18a5a74e7ec06848e4973d0ac0af3e4d795753b15a30c759
13+
14+
build:
15+
number: 0
16+
skip: win
17+
noarch: python
18+
script: python -m pip install --no-deps --ignore-installed .
19+
20+
requirements:
21+
host:
22+
- python
23+
- pip
24+
- numpy
25+
run:
26+
- python
27+
- numpy
28+
- matplotlib
29+
- colorspacious
30+
31+
tests:
32+
- python:
33+
imports:
34+
- viscm
35+
pip_check: false
36+
37+
about:
38+
license: MIT
39+
# license_file: '' we need to an issue upstream to get a license in the source dist.
40+
summary: A colormap tool
41+
homepage: https://github.com/bids/viscm
42+
43+
extra:
44+
recipe-maintainers:
45+
- kthyng
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
schema_version: 1
2+
3+
context:
4+
version: "0.9"
5+
6+
package:
7+
name: viscm
8+
version: ${{ version }}
9+
10+
source:
11+
url: https://pypi.io/packages/source/v/viscm/viscm-${{ version }}.tar.gz
12+
sha256: c770e4b76f726e653d2b7c2c73f71941a88de6eb47ccf8fb8e984b55562d05a2
13+
14+
build:
15+
number: 0
16+
skip: win
17+
noarch: python
18+
script: python -m pip install --no-deps --ignore-installed .
19+
20+
requirements:
21+
host:
22+
- python
23+
- pip
24+
- numpy
25+
run:
26+
- python
27+
- numpy
28+
- matplotlib
29+
- colorspacious
30+
31+
tests:
32+
- python:
33+
imports:
34+
- viscm
35+
pip_check: false
36+
37+
about:
38+
license: MIT
39+
# license_file: '' we need to an issue upstream to get a license in the source dist.
40+
summary: A colormap tool
41+
homepage: https://github.com/bids/viscm
42+
43+
extra:
44+
recipe-maintainers:
45+
- kthyng

0 commit comments

Comments
 (0)