Skip to content

Commit

Permalink
add mini-piggyback migrator for removing pin_compatible("numpy"...)
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Apr 20, 2024
1 parent 383a15a commit e0adab6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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())

Check warning on line 684 in conda_forge_tick/auto_tick.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/auto_tick.py#L683-L684

Added lines #L683 - L684 were not covered by tests
# 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
47 changes: 47 additions & 0 deletions conda_forge_tick/migrators/numpy2.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 24 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L23-L24

Added lines #L23 - L24 were not covered by tests


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)

Check warning on line 30 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L29-L30

Added lines #L29 - L30 were not covered by tests
# filter() returns True if we _don't_ want to migrate
return not (has_pcn)

Check warning on line 32 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L32

Added line #L32 was not covered by tests

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

Check warning on line 38 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L35-L38

Added lines #L35 - L38 were not covered by tests

new_lines = []
sections = _slice_into_output_sections(lines, attrs)
for name, section in sections.items():

Check warning on line 42 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L40-L42

Added lines #L40 - L42 were not covered by tests
# _process_section returns list of lines already
new_lines += _process_section(name, attrs, section)

Check warning on line 44 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L44

Added line #L44 was not covered by tests

with open(fname, "w") as fp:
fp.write("".join(new_lines))

Check warning on line 47 in conda_forge_tick/migrators/numpy2.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/migrators/numpy2.py#L46-L47

Added lines #L46 - L47 were not covered by tests

0 comments on commit e0adab6

Please sign in to comment.