Skip to content

Commit

Permalink
fix: render sha and md5 hashes (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Jan 8, 2025
1 parent f7850a8 commit 4eb31fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
license = { file = "LICENSE.txt" }
Expand Down
13 changes: 10 additions & 3 deletions src/rattler_build_conda_compat/recipe_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/__snapshots__/test_jinja.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4eb31fe

Please sign in to comment.