From 4bd96e73b575f4efc9be872c81464308fb6398ba Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 8 Jan 2025 10:39:21 +0100 Subject: [PATCH 1/4] render sha and md5 hashes --- src/rattler_build_conda_compat/recipe_sources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rattler_build_conda_compat/recipe_sources.py b/src/rattler_build_conda_compat/recipe_sources.py index 5c0d887..739c625 100644 --- a/src/rattler_build_conda_compat/recipe_sources.py +++ b/src/rattler_build_conda_compat/recipe_sources.py @@ -156,8 +156,8 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str as_url = Source( url=render(elem_dict["url"], context_variables), template=elem_dict["url"], - sha256=elem_dict.get("sha256"), - md5=elem_dict.get("md5"), + sha256=render(elem_dict.get("sha256"), context_variables), + md5=render(elem_dict.get("md5"), context_variables), context=context_variables, ) final_sources.add(as_url) From 7bc00702be82aa740ab389e9ed61825627cc520e Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 8 Jan 2025 10:51:36 +0100 Subject: [PATCH 2/4] fix --- src/rattler_build_conda_compat/recipe_sources.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rattler_build_conda_compat/recipe_sources.py b/src/rattler_build_conda_compat/recipe_sources.py index 739c625..dcdf3c4 100644 --- a/src/rattler_build_conda_compat/recipe_sources.py +++ b/src/rattler_build_conda_compat/recipe_sources.py @@ -110,7 +110,7 @@ def get_first_url(source: MutableMapping[str, Any]) -> str: return (get_first_url(source) for source in get_all_sources(recipe) if "url" in source) -def render_all_sources( +def render_all_sources( # noqa: C901 recipe: RecipeWithContext, variants: list[dict[str, list[str]]], override_version: str | None = None, @@ -152,12 +152,17 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str ): # we need to explicitly cast here elem_dict = typing.cast(dict[str, Any], elem) + sha256, md5 = None, None + if elem_dict.get("sha256") is not None: + sha256 = typing.cast(str, render(str(elem_dict["sha256"]), context_variables)) + if elem_dict.get("md5") is not None: + md5 = typing.cast(str, render(str(elem_dict["md5"]), context_variables)) if "url" in elem_dict: as_url = Source( url=render(elem_dict["url"], context_variables), template=elem_dict["url"], - sha256=render(elem_dict.get("sha256"), context_variables), - md5=render(elem_dict.get("md5"), context_variables), + sha256=sha256, + md5=md5, context=context_variables, ) final_sources.add(as_url) From ea9252744dcdfd877cda7b339769abb6d5094feb Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 8 Jan 2025 11:18:43 +0100 Subject: [PATCH 3/4] properly render hashes and update tests --- pixi.lock | 4 ++-- pyproject.toml | 2 +- tests/__snapshots__/test_jinja.ambr | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pixi.lock b/pixi.lock index fe22b85..1bdbd47 100644 --- a/pixi.lock +++ b/pixi.lock @@ -11120,8 +11120,8 @@ packages: timestamp: 1735902555109 - pypi: . name: rattler-build-conda-compat - version: 1.3.0 - sha256: 1b2fde96cb00c1514ac804b55e0ff018f3591437351550a2b69f252775c5f1ea + version: 1.3.1 + sha256: 07d45e11b8a66ae56b42e4923ec0fcc4734e5cdcbf8406d53e40af881c4f2844 requires_dist: - typing-extensions>=4.12,<5 - jinja2>=3.0.2,<4 diff --git a/pyproject.toml b/pyproject.toml index bab8e05..1d34f36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "rattler-build-conda-compat" description = "A package for exposing rattler-build API for conda-smithy" -version = "1.3.0" +version = "1.3.1" readme = "README.md" authors = [{ name = "Nichita Morcotilo", email = "nichita@prefix.dev" }] license = { file = "LICENSE.txt" } diff --git a/tests/__snapshots__/test_jinja.ambr b/tests/__snapshots__/test_jinja.ambr index d679846..0870b13 100644 --- a/tests/__snapshots__/test_jinja.ambr +++ b/tests/__snapshots__/test_jinja.ambr @@ -217,9 +217,9 @@ Source(url='https://osx.com/osx-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None), Source(url='https://osx.com/win-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None), Source(url='https://win.com', template='https://win.com', context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None), - Source(url=['https://foo.com/linux-64/zip.zip', 'https://mirror.com/linux-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='${{ "xxx" if win else "yyy" }}', md5=None), - Source(url=['https://foo.com/osx-64/zip.zip', 'https://mirror.com/osx-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='${{ "xxx" if win else "yyy" }}', md5=None), - Source(url=['https://foo.com/win-64/zip.zip', 'https://mirror.com/win-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='${{ "xxx" if win else "yyy" }}', md5=None), + Source(url=['https://foo.com/linux-64/zip.zip', 'https://mirror.com/linux-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None), + Source(url=['https://foo.com/osx-64/zip.zip', 'https://mirror.com/osx-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None), + Source(url=['https://foo.com/win-64/zip.zip', 'https://mirror.com/win-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None), }) # --- # name: test_render_recipe_with_context From ad48fe6a322b78d46bcf6a26af3a459536e4b1b0 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 8 Jan 2025 11:22:46 +0100 Subject: [PATCH 4/4] .. --- src/rattler_build_conda_compat/recipe_sources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rattler_build_conda_compat/recipe_sources.py b/src/rattler_build_conda_compat/recipe_sources.py index dcdf3c4..af7a66e 100644 --- a/src/rattler_build_conda_compat/recipe_sources.py +++ b/src/rattler_build_conda_compat/recipe_sources.py @@ -154,7 +154,9 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str elem_dict = typing.cast(dict[str, Any], elem) sha256, md5 = None, None if elem_dict.get("sha256") is not None: - sha256 = typing.cast(str, render(str(elem_dict["sha256"]), context_variables)) + sha256 = typing.cast( + str, render(str(elem_dict["sha256"]), context_variables) + ) if elem_dict.get("md5") is not None: md5 = typing.cast(str, render(str(elem_dict["md5"]), context_variables)) if "url" in elem_dict: