-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2806 from isuruf/r-ucrt
Add R UCRT cleanup mini migrator
- Loading branch information
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |