From 22059284316c90924e9ba853da3265fe3d12716b Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 7 Aug 2024 03:35:58 -0400 Subject: [PATCH] feat: start adding some more tests for version updates (#48) --- .../modify_recipe.py | 16 ++++--- tests/data/version/embree/expected.yaml | 47 +++++++++++++++++++ tests/data/version/embree/recipe.yaml | 47 +++++++++++++++++++ tests/data/version/jinja2sha/recipe.yaml | 31 ++++++++++++ tests/data/version/mpich/expected.yaml | 27 +++++++++++ tests/data/version/mpich/recipe.yaml | 27 +++++++++++ tests/data/version/polars_variant/recipe.yaml | 21 +++++++++ tests/test_recipe_modification.py | 17 +++++++ 8 files changed, 227 insertions(+), 6 deletions(-) create mode 100644 tests/data/version/embree/expected.yaml create mode 100644 tests/data/version/embree/recipe.yaml create mode 100644 tests/data/version/jinja2sha/recipe.yaml create mode 100644 tests/data/version/mpich/expected.yaml create mode 100644 tests/data/version/mpich/recipe.yaml create mode 100644 tests/data/version/polars_variant/recipe.yaml diff --git a/src/rattler_build_conda_compat/modify_recipe.py b/src/rattler_build_conda_compat/modify_recipe.py index ffbeecb..4067b0e 100644 --- a/src/rattler_build_conda_compat/modify_recipe.py +++ b/src/rattler_build_conda_compat/modify_recipe.py @@ -18,6 +18,8 @@ logger = logging.getLogger(__name__) +HashType = Literal["md5", "sha256"] + yaml = YAML() yaml.preserve_quotes = True yaml.width = 4096 @@ -81,7 +83,7 @@ def __init__(self, message: str = "Could not update version") -> None: class Hash: - def __init__(self, hash_type: Literal["md5", "sha256"], hash_value: str) -> None: + def __init__(self, hash_type: HashType, hash_value: str) -> None: self.hash_type = hash_type self.hash_value = hash_value @@ -105,17 +107,19 @@ def update_hash(source: Source, url: str, hash_: Hash | None) -> None: * `url` - The URL to download and hash (if no hash is provided). * `hash_` - The hash to use. If not provided, the file will be downloaded and `sha256` hashed. """ - if "md5" in source: - del source["md5"] - if "sha256" in source: - del source["sha256"] + hash_type: HashType = hash_.hash_type if hash_ is not None else "sha256" + # delete all old hashes that we are not updating + all_hash_types: set[HashType] = {"md5", "sha256"} + for key in all_hash_types - {hash_type}: + if key in source: + del source[key] if hash_ is not None: source[hash_.hash_type] = hash_.hash_value else: # download and hash the file hasher = hashlib.sha256() - logger.info("Retrieving and hashing %s", url) + print(f"Retrieving and hashing {url}") with requests.get(url, stream=True, timeout=100) as r: for chunk in r.iter_content(chunk_size=4096): hasher.update(chunk) diff --git a/tests/data/version/embree/expected.yaml b/tests/data/version/embree/expected.yaml new file mode 100644 index 0000000..4795ae2 --- /dev/null +++ b/tests/data/version/embree/expected.yaml @@ -0,0 +1,47 @@ +context: + name: embree + version: "3.7.0" + +package: + name: ${{ name }} + version: ${{ version }} + +source: + - if: osx + then: + file_name: ${{ name }}-${{ version }}.tar.gz + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x86_64.macosx.zip + sha256: 17c31f67efb9afc3ed658fcaa5886bc10c6f67f1e364d6494e494d189d8b8c70 + - if: linux + then: + file_name: ${{ name }}-${{ version }}.tar.gz + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x86_64.linux.tar.gz + sha256: 671a3aa7cc1c8501f1290dd051b42a337a692ea6552a07436779439d649e3e29 + - if: win + then: + file_name: ${{ name }}-${{ version }}.zip + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x64.vc14.windows.zip # [win] + sha256: 442c8933fa3a21d66c0459ded83e1a4c896b1a26c4e46ea62e65ffbfec273be2 + +build: + number: 100 + +requirements: + build: + - ${{ "python" if win }} + +tests: + - script: + - ${{ test -f "${PREFIX}/lib/libembree.so" if linux }} + - ${{ test -f "${PREFIX}/lib/libembree.dylib" if osx }} + +about: + homepage: https://embree.github.io/ + license: Apache 2.0 + license_file: doc/LICENSE.txt + summary: High Performance Ray Tracing Kernels + +extra: + recipe-maintainers: + - embree + - foo diff --git a/tests/data/version/embree/recipe.yaml b/tests/data/version/embree/recipe.yaml new file mode 100644 index 0000000..9c34b76 --- /dev/null +++ b/tests/data/version/embree/recipe.yaml @@ -0,0 +1,47 @@ +context: + name: embree + version: "2.14.0" + +package: + name: ${{ name }} + version: ${{ version }} + +source: + - if: osx + then: + file_name: ${{ name }}-${{ version }}.tar.gz + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x86_64.macosx.zip + sha256: f6113506bab9430f98773b0ab7776efe387f4d40c8785d8f8c427a91c36f4cfe + - if: linux + then: + file_name: ${{ name }}-${{ version }}.tar.gz + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x86_64.linux.tar.gz + sha256: 8cca2d7ef6e3f18668246c9eed609e03e720e4033d069164c991c5feb078443c + - if: win + then: + file_name: ${{ name }}-${{ version }}.zip + url: https://github.com/${{ name }}/${{ name }}/releases/download/v${{ version }}/${{ name }}-${{ version }}.x64.vc14.windows.zip # [win] + sha256: 6432449254f56b037f17d876403f919f6c136cc16ec91f7778001b10eea115ac + +build: + number: 100 + +requirements: + build: + - ${{ "python" if win }} + +tests: + - script: + - ${{ test -f "${PREFIX}/lib/libembree.so" if linux }} + - ${{ test -f "${PREFIX}/lib/libembree.dylib" if osx }} + +about: + homepage: https://embree.github.io/ + license: Apache 2.0 + license_file: doc/LICENSE.txt + summary: High Performance Ray Tracing Kernels + +extra: + recipe-maintainers: + - embree + - foo diff --git a/tests/data/version/jinja2sha/recipe.yaml b/tests/data/version/jinja2sha/recipe.yaml new file mode 100644 index 0000000..ba549a3 --- /dev/null +++ b/tests/data/version/jinja2sha/recipe.yaml @@ -0,0 +1,31 @@ +context: + version: 2.4.0 + download_url: https://github.com/git-lfs/git-lfs/releases/download + sha256: 56728ec9219c1a9339e1e6166f551459d74d300a29b51031851759cee4d7d710 + +package: + name: git-lfs + version: ${{ version }} + +source: + url: ${{ download_url }}/v${{ version }}/git-lfs-linux-amd64-${{ version }}.tar.gz + file_name: git-lfs-linux-amd64-${{ version }}.tar.gz + sha256: ${{ sha256 }} + +build: + number: 100 + +tests: + - script: + - git-lfs --help + +about: + homepage: https://git-lfs.github.com/ + license: MIT + license_file: '${{ env.get_default["RECIPE_DIR"] }}/LICENSE.md' + summary: An open source Git extension for versioning large files + +extra: + recipe-maintainers: + - baz + - foo diff --git a/tests/data/version/mpich/expected.yaml b/tests/data/version/mpich/expected.yaml new file mode 100644 index 0000000..e759e4c --- /dev/null +++ b/tests/data/version/mpich/expected.yaml @@ -0,0 +1,27 @@ +context: + version: 4.1.1 + build: 0 + version_url: ${{ version if version[-2:] != ".0" else version[:-2] }} + computed_build: ${{ build + 100 if mpi_type == 'conda' else build }} + +package: + # must not match any outputs for requirements to be handled correctly + name: mpich-mpi + version: ${{ version }} + +source: + file_name: mpich-${{ version }}.tar.gz + url: https://www.mpich.org/static/downloads/${{ version_url }}/mpich-${{ version_url }}.tar.gz + sha256: ee30471b35ef87f4c88f871a5e2ad3811cd9c4df32fd4f138443072ff4284ca2 + patches: + - libfrabric-osx-lock.patch + - libfrabric-osx-memsize.patch + +build: + number: ${{ build }} + skip: + - win + +extra: + recipe-maintainers: + - mpich diff --git a/tests/data/version/mpich/recipe.yaml b/tests/data/version/mpich/recipe.yaml new file mode 100644 index 0000000..d48f25f --- /dev/null +++ b/tests/data/version/mpich/recipe.yaml @@ -0,0 +1,27 @@ +context: + version: 4.1.0 + build: 0 + version_url: ${{ version if version[-2:] != ".0" else version[:-2] }} + computed_build: ${{ build + 100 if mpi_type == 'conda' else build }} + +package: + # must not match any outputs for requirements to be handled correctly + name: mpich-mpi + version: ${{ version }} + +source: + file_name: mpich-${{ version }}.tar.gz + url: https://www.mpich.org/static/downloads/${{ version_url }}/mpich-${{ version_url }}.tar.gz + sha256: 8b1ec63bc44c7caa2afbb457bc5b3cd4a70dbe46baba700123d67c48dc5ab6a0 + patches: + - libfrabric-osx-lock.patch + - libfrabric-osx-memsize.patch + +build: + number: ${{ build }} + skip: + - win + +extra: + recipe-maintainers: + - mpich diff --git a/tests/data/version/polars_variant/recipe.yaml b/tests/data/version/polars_variant/recipe.yaml new file mode 100644 index 0000000..945871b --- /dev/null +++ b/tests/data/version/polars_variant/recipe.yaml @@ -0,0 +1,21 @@ +context: + name: ${{ polars_variant }} + version: "1.0.0" + +package: + name: ${{ name }} + version: ${{ version }} + +source: + - if: name == "polars" + then: + url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name | replace("-", "_") }}-{{ version }}.tar.gz + sha256: 144a63d6d61dc5d675304673c4261ceccf4cfc75277431389d4afe9a5be0f70b + - if: name == "polars-lts-cpu" + then: + url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name | replace("-", "_") }}-{{ version }}.tar.gz + sha256: e4c3d203d398bd2914fe191544385950a0cd559051af6b2f6b431b837e357d8e + - if: name == "polars-u64-idx" + then: + url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name | replace("-", "_") }}-{{ version }}.tar.gz + sha256: e2fd9758a4381aef4f3bee0ba62b80c7125983445751579b0d95288e39c94d9f diff --git a/tests/test_recipe_modification.py b/tests/test_recipe_modification.py index c3550a7..51fc476 100644 --- a/tests/test_recipe_modification.py +++ b/tests/test_recipe_modification.py @@ -31,3 +31,20 @@ def test_version_mod(data_dir: Path) -> None: result = update_version(test_cran, "1.1-30", None) expected = test_cran.parent / "expected.yaml" assert result == expected.read_text() + + +def test_multi_source(data_dir: Path) -> None: + tests = data_dir / "version" + test_recipe = tests / "embree/recipe.yaml" + result = update_version(test_recipe, "3.7.0", None) + expected = test_recipe.parent / "expected.yaml" + assert result == expected.read_text() + + +def test_mpich(data_dir: Path) -> None: + tests = data_dir / "version" + test_recipe = tests / "mpich/recipe.yaml" + result = update_version(test_recipe, "4.1.1", None) + print(result) + expected = test_recipe.parent / "expected.yaml" + assert result == expected.read_text()