From e0adab6f0e65bda3e5f63ac088817bd34232943d Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 20 Apr 2024 21:14:54 +1100 Subject: [PATCH 1/2] add mini-piggyback migrator for removing `pin_compatible("numpy"...)` --- conda_forge_tick/auto_tick.py | 3 ++ conda_forge_tick/migrators/__init__.py | 1 + conda_forge_tick/migrators/numpy2.py | 47 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 conda_forge_tick/migrators/numpy2.py diff --git a/conda_forge_tick/auto_tick.py b/conda_forge_tick/auto_tick.py index eb3a024d3..4d6dda54c 100644 --- a/conda_forge_tick/auto_tick.py +++ b/conda_forge_tick/auto_tick.py @@ -85,6 +85,7 @@ Migrator, MPIPinRunAsBuildCleanup, NoCondaInspectMigrator, + Numpy2Migrator, PipMigrator, PipWheelMigrator, QtQtMainMigrator, @@ -679,6 +680,8 @@ def add_rebuild_migration_yaml( piggy_back_migrations.append(JpegTurboMigrator()) if migration_name == "boost_cpp_to_libboost": piggy_back_migrations.append(LibboostMigrator()) + if migration_name == "numpy2": + piggy_back_migrations.append(Numpy2Migrator()) # stdlib migrator runs on top of ALL migrations, see # https://github.com/conda-forge/conda-forge.github.io/issues/2102 piggy_back_migrations.append(StdlibMigrator()) diff --git a/conda_forge_tick/migrators/__init__.py b/conda_forge_tick/migrators/__init__.py index 81963dc72..c5c314b49 100644 --- a/conda_forge_tick/migrators/__init__.py +++ b/conda_forge_tick/migrators/__init__.py @@ -25,6 +25,7 @@ from .matplotlib_base import MatplotlibBase from .migration_yaml import MigrationYaml, MigrationYamlCreator, merge_migrator_cbc from .mpi_pin_run_as_build import MPIPinRunAsBuildCleanup +from .numpy2 import Numpy2Migrator from .pip_check import PipCheckMigrator from .pip_wheel_dep import PipWheelMigrator from .qt_to_qt_main import QtQtMainMigrator diff --git a/conda_forge_tick/migrators/numpy2.py b/conda_forge_tick/migrators/numpy2.py new file mode 100644 index 000000000..8020a7b9e --- /dev/null +++ b/conda_forge_tick/migrators/numpy2.py @@ -0,0 +1,47 @@ +import os +import re + +from conda_forge_tick.migrators.core import MiniMigrator +from conda_forge_tick.migrators.libboost import _replacer, _slice_into_output_sections + +# pin_compatible("numpy"...) +# ^ ^ ^ +# p c n +raw_pat_pcn = r".*\{\{\s*pin_compatible\([\"\']numpy[\"\'].*" +pat_pcn = re.compile(raw_pat_pcn) + + +def _process_section(name, attrs, lines): + """ + Migrate requirements per section. + + We want to migrate as follows: + - remove all occurrences of `{{ pin_compatible("numpy",...) }}`; + these will be taken care of henceforth by numpy's run-export + """ + # _replacer take the raw pattern, not the compiled one + lines = _replacer(lines, raw_pat_pcn, "") + return lines + + +class Numpy2Migrator(MiniMigrator): + def filter(self, attrs, not_bad_str_start=""): + lines = attrs["raw_meta_yaml"].splitlines() + has_pcn = any(pat_pcn.search(line) for line in lines) + # filter() returns True if we _don't_ want to migrate + return not (has_pcn) + + def migrate(self, recipe_dir, attrs, **kwargs): + fname = os.path.join(recipe_dir, "meta.yaml") + if os.path.exists(fname): + with open(fname) as fp: + lines = fp.readlines() + + new_lines = [] + sections = _slice_into_output_sections(lines, attrs) + for name, section in sections.items(): + # _process_section returns list of lines already + new_lines += _process_section(name, attrs, section) + + with open(fname, "w") as fp: + fp.write("".join(new_lines)) From ebcdb4f5872c29808fa03b7784eafeb424f73e37 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 20 Apr 2024 22:08:09 +1100 Subject: [PATCH 2/2] numpy2: don't bother with treating sections separately --- conda_forge_tick/migrators/numpy2.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/conda_forge_tick/migrators/numpy2.py b/conda_forge_tick/migrators/numpy2.py index 8020a7b9e..418c1c8bd 100644 --- a/conda_forge_tick/migrators/numpy2.py +++ b/conda_forge_tick/migrators/numpy2.py @@ -2,7 +2,7 @@ import re from conda_forge_tick.migrators.core import MiniMigrator -from conda_forge_tick.migrators.libboost import _replacer, _slice_into_output_sections +from conda_forge_tick.migrators.libboost import _replacer # pin_compatible("numpy"...) # ^ ^ ^ @@ -11,19 +11,6 @@ pat_pcn = re.compile(raw_pat_pcn) -def _process_section(name, attrs, lines): - """ - Migrate requirements per section. - - We want to migrate as follows: - - remove all occurrences of `{{ pin_compatible("numpy",...) }}`; - these will be taken care of henceforth by numpy's run-export - """ - # _replacer take the raw pattern, not the compiled one - lines = _replacer(lines, raw_pat_pcn, "") - return lines - - class Numpy2Migrator(MiniMigrator): def filter(self, attrs, not_bad_str_start=""): lines = attrs["raw_meta_yaml"].splitlines() @@ -37,11 +24,8 @@ def migrate(self, recipe_dir, attrs, **kwargs): with open(fname) as fp: lines = fp.readlines() - new_lines = [] - sections = _slice_into_output_sections(lines, attrs) - for name, section in sections.items(): - # _process_section returns list of lines already - new_lines += _process_section(name, attrs, section) + # _replacer take the raw pattern, not the compiled one + new_lines = _replacer(lines, raw_pat_pcn, "") with open(fname, "w") as fp: fp.write("".join(new_lines))