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/src/rattler_build_conda_compat/recipe_sources.py b/src/rattler_build_conda_compat/recipe_sources.py index 5c0d887..af7a66e 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,19 @@ 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=elem_dict.get("sha256"), - md5=elem_dict.get("md5"), + sha256=sha256, + md5=md5, context=context_variables, ) final_sources.add(as_url) 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