Skip to content

Commit

Permalink
add tests for sources that depend on conda build config variants (rec…
Browse files Browse the repository at this point in the history
…ipe v0 & v1) (#3605)

* add tests for recipe v0 polars update
directly selecting source based on conda build config variant

* add tests for recipe v0 polars update
successfully reproduce polars issue

* fix URL reference error

* fix polars recipes

---------

Co-authored-by: Matthew R. Becker <[email protected]>
  • Loading branch information
ytausch and beckermr authored Jan 26, 2025
1 parent c4ef633 commit 733272b
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 12 deletions.
1 change: 1 addition & 0 deletions conda_forge_tick/update_recipe/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def _get_new_url_tmpl_and_hash(
logger.info("initial rendered URL: %s", url)
except jinja2.UndefinedError:
logger.info("initial URL template does not render")
url = None
pass

if url != url_tmpl:
Expand Down
66 changes: 54 additions & 12 deletions tests/test_migrators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import itertools
import json
import os
import re
import subprocess
from pathlib import Path

import pytest
import yaml

from conda_forge_tick.contexts import ClonedFeedstockContext
from conda_forge_tick.feedstock_parser import populate_feedstock_attributes
Expand Down Expand Up @@ -471,35 +473,69 @@ def run_test_migration(
should_filter: bool = False,
make_body: bool = False,
recipe_version: int = 0,
conda_build_config: str | None = None,
):
tmpdir_p = Path(tmpdir)
if mr_out:
mr_out.update(bot_rerun=False)

if recipe_version == 0:
if conda_build_config:
raise ValueError(
"conda_build_config is only supported for recipe version 1 in this test function"
)
tmpdir_p.joinpath("meta.yaml").write_text(inp)
recipe_dir = str(tmpdir_p)
recipe_dir_p = tmpdir_p
elif recipe_version == 1:
tmpdir_p.joinpath(".ci_support").mkdir()
tmpdir_p.joinpath("recipe").mkdir()
tmpdir_p.joinpath("recipe", "recipe.yaml").write_text(inp)
for target_platform in ("linux-64", "osx-arm64", "win-64"):
(
tmpdir_p / ".ci_support" / f"{target_platform.replace('-', '_')}_.yaml"
).write_text("target_platform:\n" f"- {target_platform}\n")

recipe_dir = str(tmpdir_p / "recipe")
build_variants = (
yaml.safe_load(conda_build_config) if conda_build_config else {}
)

if "target_platform" not in build_variants:
build_variants["target_platform"] = ["linux-64", "osx-arm64", "win-64"]

# move target_platform to the beginning of the keys
build_variants = {
"target_platform": build_variants.pop("target_platform"),
**build_variants,
}

for assignment in itertools.product(*build_variants.values()):
assignment_map = dict(zip(build_variants.keys(), assignment))
variant_name = "_".join(
str(value).replace("-", "_").replace("/", "")
for value in assignment_map.values()
)
(tmpdir_p / ".ci_support" / f"{variant_name}_.yaml").write_text(
yaml.dump({k: [v] for k, v in assignment_map.items()})
)

recipe_dir_p = tmpdir_p / "recipe"
else:
raise ValueError(f"Unsupported recipe version: {recipe_version}")

if conda_build_config:
conda_build_config_file = recipe_dir_p / "conda_build_config.yaml"
conda_build_config_file.write_text(conda_build_config)
else:
conda_build_config_file = None

recipe_dir = str(recipe_dir_p)

# read the conda-forge.yml
cf_yml_path = Path(tmpdir).parent / "conda-forge.yml"
cf_yml = cf_yml_path.read_text() if cf_yml_path.exists() else "{}"

# Load the meta.yaml (this is done in the graph)
if recipe_version == 0:
try:
name = parse_meta_yaml(inp)["package"]["name"]
name = parse_meta_yaml(inp, cbc_path=conda_build_config_file)["package"][
"name"
]
except Exception:
name = "blah"

Expand All @@ -518,7 +554,9 @@ def run_test_migration(
pmy.update(kwargs)
else:
try:
name = parse_recipe_yaml(inp)["package"]["name"]
name = parse_recipe_yaml(inp, cbc_path=conda_build_config_file)["package"][
"name"
]
except Exception:
name = "blah"

Expand Down Expand Up @@ -720,7 +758,8 @@ def test_all_noarch(meta, is_all_noarch):
"meta,is_all_noarch",
[
(
json.loads("""\
json.loads(
"""\
{
"about": {
"description": "NetworkX is a Python language software package for the creation,\\nmanipulation, and study of the structure, dynamics, and functions of complex\\nnetworks.",
Expand Down Expand Up @@ -784,11 +823,13 @@ def test_all_noarch(meta, is_all_noarch):
"sha256": "307c3669428c5362aab27c8a1260aa8f47c4e91d3891f48be0141738d8d053e1",
"url": "https://pypi.org/packages/source/n/networkx/networkx-3.4.2.tar.gz"
}
}"""),
}"""
),
True,
),
(
json.loads("""\
json.loads(
"""\
{
"about": {
"description": "This is a python extension ",
Expand Down Expand Up @@ -857,7 +898,8 @@ def test_all_noarch(meta, is_all_noarch):
"pytest"
]
}
}"""),
}"""
),
False,
),
],
Expand Down
105 changes: 105 additions & 0 deletions tests/test_v1_yaml/version_polars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
context:
version: "1.17.1"

# Note: This recipe is specifically designed to work well with the autotick bot.
# Also refer to https://github.com/conda-forge/rust-feedstock/blob/main/recipe/meta.yaml.
package:
name: ${{ polars_variant }}
version: ${{ version }}

source:
- if: polars_variant == 'polars'
then:
url: https://pypi.org/packages/source/p/polars/polars-${{ version }}.tar.gz
sha256: 5a3dac3cb7cbe174d1fa898cba9afbede0c08e8728feeeab515554d762127019
- if: polars_variant == 'polars-lts-cpu'
then:
url: https://pypi.org/packages/source/p/polars-lts-cpu/polars_lts_cpu-${{ version }}.tar.gz
sha256: d2717d17cd764223ea01e35ada2e3235327bc08040ecd41c71c803c7aad874fb
- if: polars_variant == 'polars-u64-idx'
then:
url: https://pypi.org/packages/source/p/polars-u64-idx/polars_u64_idx-${{ version }}.tar.gz
sha256: 5b47e993d3a73e40f674bc856dbac0e93eaf26c10bc7b1d6768f71faa6e023fe

build:
number: 0

requirements:
build:
- if: build_platform != target_platform
then:
- python
# there is no cross-python for linux-64 -> win-64
- if: target_platform != 'win-64'
then: cross-python_${{ target_platform }}
- crossenv
- maturin >=1.3.2,<2
- ${{ compiler('c') }}
- ${{ compiler('cxx') }}
# clang_win-64 already adds all required run_exports for the windows build
- if: not (build_platform != target_platform and target_platform == "win-64")
then:
- ${{ stdlib('c') }}
else:
- cargo-feature
- if: build_platform == 'win-64'
then:
- posix
- ${{ compiler('rust') }}
- cmake
- if: unix
then:
- make
- cargo-bundle-licenses
host:
- python
- pip
- maturin >=1.3.2,<2
- if: build_platform != target_platform and target_platform == "win-64"
then:
- mingw-w64-ucrt-x86_64-headers-git
run:
- python
- numpy >=1.16.0
- if: python<3.11
then:
- typing_extensions >=4.0.0
- if: python >=3.10
then:
- packaging

tests:
- python:
pip_check: true
imports:
- polars
- script:
- python -c "from polars import DataFrame"
- package_contents:
site_packages:
- polars/polars.abi3.so
- polars/dataframe/__init__.py
- ${{ polars_variant | replace('-', '_') }}-${{ version }}.dist-info/METADATA

about:
homepage: https://github.com/pola-rs/polars
license: MIT
license_file:
- LICENSE
- THIRDPARTY.yml
summary: Dataframes powered by a multithreaded, vectorized query engine, written in Rust
description: Polars is a DataFrame interface on top of an OLAP Query Engine implemented in Rust using Apache Arrow Columnar Format as the memory model.
documentation: https://docs.pola.rs
repository: https://github.com/pola-rs/polars

extra:
recipe-maintainers:
- borchero
- Maxyme
- timkpaine
- ritchie46
- sugatoray
- xhochy
- dhirschfeld
- pavelzw
- '0xbe7a'
105 changes: 105 additions & 0 deletions tests/test_v1_yaml/version_polars_correct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
context:
version: "1.20.0"

# Note: This recipe is specifically designed to work well with the autotick bot.
# Also refer to https://github.com/conda-forge/rust-feedstock/blob/main/recipe/meta.yaml.
package:
name: ${{ polars_variant }}
version: ${{ version }}

source:
- if: polars_variant == 'polars'
then:
url: https://pypi.org/packages/source/p/polars/polars-${{ version }}.tar.gz
sha256: e8e9e3156fae02b58e276e5f2c16a5907a79b38617a9e2d731b533d87798f451
- if: polars_variant == 'polars-lts-cpu'
then:
url: https://pypi.org/packages/source/p/polars-lts-cpu/polars_lts_cpu-${{ version }}.tar.gz
sha256: f8770fe1a752f60828ec73e6215c7dadcb2badd1f34dcb1def7a0f4ca0ac36f8
- if: polars_variant == 'polars-u64-idx'
then:
url: https://pypi.org/packages/source/p/polars-u64-idx/polars_u64_idx-${{ version }}.tar.gz
sha256: a92fadacf59776bef2d777f99345c4d089cf4f8b3fd61f5728087bab27a46a75

build:
number: 0

requirements:
build:
- if: build_platform != target_platform
then:
- python
# there is no cross-python for linux-64 -> win-64
- if: target_platform != 'win-64'
then: cross-python_${{ target_platform }}
- crossenv
- maturin >=1.3.2,<2
- ${{ compiler('c') }}
- ${{ compiler('cxx') }}
# clang_win-64 already adds all required run_exports for the windows build
- if: not (build_platform != target_platform and target_platform == "win-64")
then:
- ${{ stdlib('c') }}
else:
- cargo-feature
- if: build_platform == 'win-64'
then:
- posix
- ${{ compiler('rust') }}
- cmake
- if: unix
then:
- make
- cargo-bundle-licenses
host:
- python
- pip
- maturin >=1.3.2,<2
- if: build_platform != target_platform and target_platform == "win-64"
then:
- mingw-w64-ucrt-x86_64-headers-git
run:
- python
- numpy >=1.16.0
- if: python<3.11
then:
- typing_extensions >=4.0.0
- if: python >=3.10
then:
- packaging

tests:
- python:
pip_check: true
imports:
- polars
- script:
- python -c "from polars import DataFrame"
- package_contents:
site_packages:
- polars/polars.abi3.so
- polars/dataframe/__init__.py
- ${{ polars_variant | replace('-', '_') }}-${{ version }}.dist-info/METADATA

about:
homepage: https://github.com/pola-rs/polars
license: MIT
license_file:
- LICENSE
- THIRDPARTY.yml
summary: Dataframes powered by a multithreaded, vectorized query engine, written in Rust
description: Polars is a DataFrame interface on top of an OLAP Query Engine implemented in Rust using Apache Arrow Columnar Format as the memory model.
documentation: https://docs.pola.rs
repository: https://github.com/pola-rs/polars

extra:
recipe-maintainers:
- borchero
- Maxyme
- timkpaine
- ritchie46
- sugatoray
- xhochy
- dhirschfeld
- pavelzw
- '0xbe7a'
17 changes: 17 additions & 0 deletions tests/test_v1_yaml/version_polars_variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
channel_sources:
- conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge
channel_targets:
- conda-forge main
c_compiler:
- clang # [win]
c_compiler_version:
- 17 # [win]
cxx_compiler:
- clangxx # [win]
cxx_compiler_version:
- 17 # [win]

polars_variant:
- polars # [not ppc64le]
- polars-lts-cpu
- polars-u64-idx # [not ppc64le]
Loading

0 comments on commit 733272b

Please sign in to comment.