Skip to content

Commit

Permalink
Merge pull request #2806 from isuruf/r-ucrt
Browse files Browse the repository at this point in the history
Add R UCRT cleanup mini migrator
  • Loading branch information
isuruf committed Jun 29, 2024
2 parents 6d2a642 + 86aa1ea commit 841ebd1
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
3 changes: 3 additions & 0 deletions conda_forge_tick/make_migrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
PipWheelMigrator,
QtQtMainMigrator,
Replacement,
RUCRTCleanup,
StdlibMigrator,
UpdateCMakeArgsMigrator,
UpdateConfigSubGuessMigrator,
Expand Down Expand Up @@ -294,6 +295,8 @@ def add_rebuild_migration_yaml(
piggy_back_migrations.append(LibboostMigrator())
if migration_name == "numpy2":
piggy_back_migrations.append(Numpy2Migrator())
if migration_name.startswith("r-base44"):
piggy_back_migrations.append(RUCRTCleanup())
# 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 @@ -29,6 +29,7 @@
from .pip_check import PipCheckMigrator
from .pip_wheel_dep import PipWheelMigrator
from .qt_to_qt_main import QtQtMainMigrator
from .r_ucrt import RUCRTCleanup
from .replacement import Replacement
from .use_pip import PipMigrator
from .version import Version
55 changes: 55 additions & 0 deletions conda_forge_tick/migrators/r_ucrt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import re
import typing
from typing import Any

from conda_forge_tick.migrators.core import MiniMigrator
from conda_forge_tick.os_utils import pushd

if typing.TYPE_CHECKING:
from ..migrators_types import AttrsTypedDict


def _cleanup_raw_yaml(raw_yaml):
lines = []
for line in raw_yaml.splitlines():
line = line.replace("{{ native }}", "")
line = line.replace("{{native}}", "")
if "merge_build_host: " in line:
continue
if "- gcc-libs" in line:
continue
if "- posix" in line:
continue
if "set native =" in line:
continue
if re.search(r"\s*skip: (T|t)rue\s+\# \[win\]", line):
nspaces = len(line) - len(line.lstrip())
spaces = " " * nspaces
comment = (
spaces
+ "# Checking windows to see if it passes. Uncomment the line if it fails."
)
lines.append(comment)
lines.append(spaces + "# " + line.lstrip())
continue
lines.append(line)

return "\n".join(lines) + "\n"


class RUCRTCleanup(MiniMigrator):
"""Cleanup the R recipes for ucrt"""

def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
return "native" not in attrs.get("raw_meta_yaml", "")

def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> None:
with pushd(recipe_dir):
with open("meta.yaml") as fp:
raw_yaml = fp.read()

raw_yaml = _cleanup_raw_yaml(raw_yaml)

# Rewrite the recipe file
with open("meta.yaml", "w") as fp:
fp.write(raw_yaml)
151 changes: 151 additions & 0 deletions tests/test_r_ucrt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
from flaky import flaky
from test_migrators import run_test_migration

from conda_forge_tick.migrators import RUCRTCleanup, Version

r_ucrt_migrator = RUCRTCleanup()
version_migrator_rbase = Version(
set(),
piggy_back_migrations=[r_ucrt_migrator],
)

rbase_recipe = """\
{% set version = "2.0.0" %}
{% set posix = 'm2-' if win else '' %}
{% set native = 'm2w64-' if win else '' %}
package:
name: r-magrittr
version: {{ version|replace("-", "_") }}
source:
url:
- {{ cran_mirror }}/src/contrib/magrittr_{{ version }}.tar.gz
- {{ cran_mirror }}/src/contrib/Archive/magrittr/magrittr_{{ version }}.tar.gz
sha256: 05c45943ada9443134caa0ab24db4a962b629f00b755ccf039a2a2a7b2c92ae8
build:
merge_build_host: true # [win]
skip: True # [win]
number: 1
rpaths:
- lib/R/lib/
- lib/
requirements:
build:
- {{ compiler('c') }} # [not win]
- {{ compiler('m2w64_c') }} # [win]
- {{ posix }}filesystem # [win]
- {{ posix }}make
- {{ posix }}sed # [win]
- {{ posix }}coreutils # [win]
- {{ posix }}zip # [win]
host:
- r-base
- r-rlang
- {{native}}gmp
- {{ native }}mpfr
run:
- r-base
- r-rlang
- {{ native }}gcc-libs # [win]
test:
commands:
- $R -e "library('magrittr')" # [not win]
- "\\"%R%\\" -e \\"library('magrittr')\\"" # [win]
about:
home: https://magrittr.tidyverse.org, https://github.com/tidyverse/magrittr
license: MIT
summary: Provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. There is flexible support for the type of right-hand side expressions. For more information, see package vignette. To quote
Rene Magritte, "Ceci n'est pas un pipe."
license_family: MIT
license_file:
- {{ environ["PREFIX"] }}/lib/R/share/licenses/MIT
- LICENSE
extra:
recipe-maintainers:
- conda-forge/r
- ocefpaf
""" # noqa

rbase_recipe_correct = """\
{% set version = "2.0.1" %}
{% set posix = 'm2-' if win else '' %}
package:
name: r-magrittr
version: {{ version|replace("-", "_") }}
source:
url:
- {{ cran_mirror }}/src/contrib/magrittr_{{ version }}.tar.gz
- {{ cran_mirror }}/src/contrib/Archive/magrittr/magrittr_{{ version }}.tar.gz
sha256: 75c265d51cc2b34beb27040edb09823c7b954d3990a7a931e40690b75d4aad5f
build:
# Checking windows to see if it passes. Uncomment the line if it fails.
# skip: True # [win]
number: 0
rpaths:
- lib/R/lib/
- lib/
requirements:
build:
- {{ compiler('c') }} # [not win]
- {{ compiler('m2w64_c') }} # [win]
- {{ posix }}filesystem # [win]
- {{ posix }}make
- {{ posix }}sed # [win]
- {{ posix }}coreutils # [win]
- {{ posix }}zip # [win]
host:
- r-base
- r-rlang
- gmp
- mpfr
run:
- r-base
- r-rlang
test:
commands:
- $R -e "library('magrittr')" # [not win]
- "\\"%R%\\" -e \\"library('magrittr')\\"" # [win]
about:
home: https://magrittr.tidyverse.org, https://github.com/tidyverse/magrittr
license: MIT
summary: Provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. There is flexible support for the type of right-hand side expressions. For more information, see package vignette. To quote
Rene Magritte, "Ceci n'est pas un pipe."
license_family: MIT
license_file:
- {{ environ["PREFIX"] }}/lib/R/share/licenses/MIT
- LICENSE
extra:
recipe-maintainers:
- conda-forge/r
- ocefpaf
""" # noqa


@flaky
def test_r_ucrt(tmpdir):
run_test_migration(
m=version_migrator_rbase,
inp=rbase_recipe,
output=rbase_recipe_correct,
prb="Dependencies have been updated if changed",
kwargs={"new_version": "2.0.1"},
mr_out={
"migrator_name": Version.name,
"migrator_version": Version.migrator_version,
"version": "2.0.1",
},
tmpdir=tmpdir,
)

0 comments on commit 841ebd1

Please sign in to comment.