diff --git a/src/rattler_build_conda_compat/modify_recipe.py b/src/rattler_build_conda_compat/modify_recipe.py index 45c24fb..2c73f0b 100644 --- a/src/rattler_build_conda_compat/modify_recipe.py +++ b/src/rattler_build_conda_compat/modify_recipe.py @@ -1,21 +1,27 @@ from __future__ import annotations +import copy import hashlib import io import re +import logging from typing import TYPE_CHECKING, Any, Literal import requests from ruamel.yaml import YAML from rattler_build_conda_compat.jinja.jinja import jinja_env, load_recipe_context -from rattler_build_conda_compat.recipe_sources import get_all_sources, Source +from rattler_build_conda_compat.recipe_sources import Source, get_all_sources if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + yaml = YAML() yaml.preserve_quotes = True +yaml.width = 4096 +yaml.indent(mapping=2, sequence=2, offset=0) def _update_build_number_in_context(recipe: dict[str, Any], new_build_number: int) -> bool: @@ -109,6 +115,7 @@ def update_hash(source: Source, url: str, hash_: Hash | None) -> None: else: # download and hash the file hasher = hashlib.sha256() + logger.info("Retrieving and hashing %s", url) with requests.get(url, stream=True, timeout=100) as r: for chunk in r.iter_content(chunk_size=4096): hasher.update(chunk) @@ -142,8 +149,10 @@ def update_version(file: Path, new_version: str, hash_: Hash | None) -> str: # set up the jinja context env = jinja_env() - context = data.get("context", {}) + context = copy.deepcopy(data.get("context", {})) context_variables = load_recipe_context(context, env) + # for r-recipes we add the default `cran_mirror` variable + context_variables["cran_mirror"] = "https://cran.r-project.org" for source in get_all_sources(data): # render the whole URL and find the hash diff --git a/tests/data/version/future_tests/r1.yaml b/tests/data/version/test_3/expected.yaml similarity index 100% rename from tests/data/version/future_tests/r1.yaml rename to tests/data/version/test_3/expected.yaml diff --git a/tests/data/version/test_3/recipe.yaml b/tests/data/version/test_3/recipe.yaml new file mode 100644 index 0000000..cad30b7 --- /dev/null +++ b/tests/data/version/test_3/recipe.yaml @@ -0,0 +1,11 @@ +context: + name: pytest-aio + version: 1.8.1 + +package: + name: ${{ name|lower }} + version: ${{ version }} + +source: + url: https://pypi.io/packages/source/${{ name[0] }}/${{ name }}/${{ name.replace('-', '_') }}-${{ version }}.tar.gz + sha256: 97dcbc1c5ac991705f32bb2cf72f9ba94a8889fd0295d29ed4d7252b3e158684 diff --git a/tests/data/version/future_tests/r2.yaml b/tests/data/version/test_4/expected.yaml similarity index 63% rename from tests/data/version/future_tests/r2.yaml rename to tests/data/version/test_4/expected.yaml index ce7d684..a4c18d8 100644 --- a/tests/data/version/future_tests/r2.yaml +++ b/tests/data/version/test_4/expected.yaml @@ -9,6 +9,6 @@ package: source: url: - - ${{ cran_mirror }}/src/contrib/systemfit_{{ version }}.tar.gz - - ${{ cran_mirror }}/src/contrib/Archive/systemfit/systemfit_{{ version }}.tar.gz + - ${{ cran_mirror }}/src/contrib/systemfit_${{ version }}.tar.gz + - ${{ cran_mirror }}/src/contrib/Archive/systemfit/systemfit_${{ version }}.tar.gz sha256: 5994fbb81f1678325862414f58328cdc2c46d47efa1f23218e9416a4da431ce2 diff --git a/tests/data/version/test_4/recipe.yaml b/tests/data/version/test_4/recipe.yaml new file mode 100644 index 0000000..fb35a82 --- /dev/null +++ b/tests/data/version/test_4/recipe.yaml @@ -0,0 +1,14 @@ +context: + version: "1.1-26" + posix: ${{ 'm2' if win else '' }} + native: ${{ 'm2w64' if win else '' }} + +package: + name: r-systemfit + version: ${{ version|replace("-", "_") }} + +source: + url: + - ${{ cran_mirror }}/src/contrib/systemfit_${{ version }}.tar.gz + - ${{ cran_mirror }}/src/contrib/Archive/systemfit/systemfit_${{ version }}.tar.gz + sha256: a99a59787dc5556afe9a1a153f2a3a8047aa7d357aab450101e20ab1f329f758 diff --git a/tests/test_recipe_modification.py b/tests/test_recipe_modification.py index 4e5824a..c3550a7 100644 --- a/tests/test_recipe_modification.py +++ b/tests/test_recipe_modification.py @@ -16,8 +16,18 @@ def test_build_number_mod(data_dir: Path) -> None: def test_version_mod(data_dir: Path) -> None: tests = data_dir / "version" - test_recipes = tests.glob("**/recipe.yaml") + test_recipes = [tests / "test_1/recipe.yaml", tests / "test_2/recipe.yaml"] for recipe in test_recipes: result = update_version(recipe, "0.25.0", None) expected = recipe.parent / "expected.yaml" assert result == expected.read_text() + + test_python = tests / "test_3/recipe.yaml" + result = update_version(test_python, "1.9.0", None) + expected = test_python.parent / "expected.yaml" + assert result == expected.read_text() + + test_cran = tests / "test_4/recipe.yaml" + result = update_version(test_cran, "1.1-30", None) + expected = test_cran.parent / "expected.yaml" + assert result == expected.read_text()