Skip to content

Commit

Permalink
feat: start adding some more tests for version updates (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Aug 7, 2024
1 parent 4d920bd commit 2205928
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/rattler_build_conda_compat/modify_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

logger = logging.getLogger(__name__)

HashType = Literal["md5", "sha256"]

yaml = YAML()
yaml.preserve_quotes = True
yaml.width = 4096
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions tests/data/version/embree/expected.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions tests/data/version/embree/recipe.yaml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions tests/data/version/jinja2sha/recipe.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/data/version/mpich/expected.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/data/version/mpich/recipe.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions tests/data/version/polars_variant/recipe.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/test_recipe_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2205928

Please sign in to comment.