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

add mini-piggyback migrator for removing pin_compatible("numpy"...) #2470

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions conda_forge_tick/auto_tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
Migrator,
MPIPinRunAsBuildCleanup,
NoCondaInspectMigrator,
Numpy2Migrator,
PipMigrator,
PipWheelMigrator,
QtQtMainMigrator,
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions conda_forge_tick/migrators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions conda_forge_tick/migrators/numpy2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import re

from conda_forge_tick.migrators.core import MiniMigrator
from conda_forge_tick.migrators.libboost import _replacer

# pin_compatible("numpy"...)
# ^ ^ ^
# p c n
raw_pat_pcn = r".*\{\{\s*pin_compatible\([\"\']numpy[\"\'].*"
pat_pcn = re.compile(raw_pat_pcn)


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()

# _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))