From a4efa10c43e4ffdfbe6fe651da5bbf2a2efff217 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Tue, 3 Sep 2024 18:02:06 +0200 Subject: [PATCH] fix: change pin_compatible to match conda-build (#56) * fix: change pin_compatible to match conda-build * fix: need strict here --- conda_forge_feedstock_check_solvable/utils.py | 53 +++++++-- .../linux_64_python3.12.____cpython.yaml | 27 +++++ tests/biopython-feedstock/recipe/meta.yaml | 110 ++++++++++++++++++ tests/test_check_solvable.py | 10 ++ tests/test_utils.py | 10 +- 5 files changed, 195 insertions(+), 15 deletions(-) create mode 100644 tests/biopython-feedstock/.ci_support/linux_64_python3.12.____cpython.yaml create mode 100644 tests/biopython-feedstock/recipe/meta.yaml diff --git a/conda_forge_feedstock_check_solvable/utils.py b/conda_forge_feedstock_check_solvable/utils.py index 72f7451..9cd1ebb 100644 --- a/conda_forge_feedstock_check_solvable/utils.py +++ b/conda_forge_feedstock_check_solvable/utils.py @@ -601,7 +601,27 @@ def _strip_quotes(s): return s -def replace_pin_compatible(reqs, host_reqs): +def replace_pin_compatible(reqs, host_reqs, strict=False): + """Replace pin_compatible with the appropriate version constraint. + + Parameters + ---------- + reqs : list of str + The requirements to replace pin_compatible in. + host_reqs : list of str + The requirements from the host section which is used to determine the + compatibility ranges. + strict : bool, optional + If True, raise an error if the package is not found in the host section. + If False, just add the package without a version constraint. Default is False + to match conda-build behavior. + + Returns + ------- + list of str + The requirements with pin_compatible replaced with the appropriate version + constraint. + """ host_lookup = {req.split(" ")[0]: req.split(" ")[1:] for req in host_reqs} new_reqs = [] @@ -620,16 +640,27 @@ def replace_pin_compatible(reqs, host_reqs): name = _strip_quotes(parts[0].strip()) parts = parts[1:] - if name not in host_lookup: - raise ValueError( - "Very odd pinning: %s! Package %s not found in host %r!" - % (req, name, host_lookup) - ) - if not host_lookup[name]: - raise ValueError( - "Very odd pinning: %s! Package found in host but no version %r!" - % (req, host_lookup[name]) - ) + if name not in host_lookup or not host_lookup[name]: + if strict: + if name not in host_lookup: + raise ValueError( + "Very odd pinning: %s! Package %s not found in host %r!" + % (req, name, host_lookup) + ) + else: + raise ValueError( + ( + "Very odd pinning: %s! Package found in host " + "but no version %r!" + ) + % (req, host_lookup[name]) + ) + else: + if build: + new_reqs.append(name + " * " + build) + else: + new_reqs.append(name) + continue host_version = host_lookup[name][0] if len(host_lookup[name]) > 1: diff --git a/tests/biopython-feedstock/.ci_support/linux_64_python3.12.____cpython.yaml b/tests/biopython-feedstock/.ci_support/linux_64_python3.12.____cpython.yaml new file mode 100644 index 0000000..6c03157 --- /dev/null +++ b/tests/biopython-feedstock/.ci_support/linux_64_python3.12.____cpython.yaml @@ -0,0 +1,27 @@ +c_compiler: +- gcc +c_compiler_version: +- '12' +c_stdlib: +- sysroot +c_stdlib_version: +- '2.12' +cdt_name: +- cos6 +channel_sources: +- conda-forge +channel_targets: +- conda-forge main +docker_image: +- quay.io/condaforge/linux-anvil-cos7-x86_64 +pin_run_as_build: + python: + min_pin: x.x + max_pin: x.x +python: +- 3.12.* *_cpython +target_platform: +- linux-64 +zip_keys: +- - c_stdlib_version + - cdt_name diff --git a/tests/biopython-feedstock/recipe/meta.yaml b/tests/biopython-feedstock/recipe/meta.yaml new file mode 100644 index 0000000..d323237 --- /dev/null +++ b/tests/biopython-feedstock/recipe/meta.yaml @@ -0,0 +1,110 @@ +{% set name = "biopython" %} +{% set version = "1.84" %} +{% set sha256 = "60fbe6f996e8a6866a42698c17e552127d99a9aab3259d6249fbaabd0e0cc7b4" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + fn: {{ name }}-{{ version }}.tar.gz + url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz + sha256: {{ sha256 }} + +build: + number: 0 + script: {{ PYTHON }} -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv + skip: true # [py<39] + +requirements: + build: + - python # [build_platform != target_platform] + - cross-python_{{ target_platform }} # [build_platform != target_platform] + - {{ compiler('c') }} + - {{ stdlib("c") }} + host: + - python + - pip + run: + - python + - {{ pin_compatible('numpy') }} + +test: + imports: + - Bio + - Bio.Affy + - Bio.Align + - Bio.Align.Applications + - Bio.AlignIO + - Bio.Application + - Bio.Blast + - Bio.CAPS + - Bio.Cluster + - Bio.Compass + - Bio.Data + - Bio.Emboss + - Bio.Entrez + - Bio.ExPASy + - Bio.GenBank + - Bio.Geo + #Requires soft dependency reportlab + #- Bio.Graphics + #- Bio.Graphics.GenomeDiagram + - Bio.HMM + - Bio.KEGG + - Bio.KEGG.Compound + - Bio.KEGG.Enzyme + - Bio.KEGG.KGML + - Bio.KEGG.Map + - Bio.Medline + - Bio.NMR + - Bio.Nexus + - Bio.PDB + #Requires soft dependency mmtf-python + #- Bio.PDB.mmtf + - Bio.Pathway + - Bio.Pathway.Rep + - Bio.Phylo + - Bio.Phylo.Applications + - Bio.Phylo.PAML + - Bio.PopGen + - Bio.PopGen.GenePop + - Bio.Restriction + - Bio.SCOP + - Bio.SVDSuperimposer + - Bio.SearchIO + - Bio.SearchIO.BlastIO + - Bio.SearchIO.ExonerateIO + - Bio.SearchIO.HmmerIO + - Bio.SearchIO._model + - Bio.SeqIO + - Bio.SeqUtils + - Bio.Sequencing + - Bio.Sequencing.Applications + - Bio.SwissProt + - Bio.TogoWS + - Bio.UniGene + - Bio.UniProt + - Bio.codonalign + - Bio.cpairwise2 + - Bio.motifs + - Bio.motifs.applications + - Bio.motifs.jaspar + - Bio.phenotype + - BioSQL + +about: + home: http://biopython.org + license: LicenseRef-Biopython + license_file: LICENSE.rst + summary: Collection of freely available tools for computational molecular biology + description: | + Biopython is a collection of freely available Python tools for + computational molecular biology + doc_url: http://biopython.org + dev_url: https://github.com/biopython/biopython + +extra: + recipe-maintainers: + - souravsingh + - peterjc diff --git a/tests/test_check_solvable.py b/tests/test_check_solvable.py index 0f84146..3271370 100644 --- a/tests/test_check_solvable.py +++ b/tests/test_check_solvable.py @@ -190,6 +190,16 @@ def test_hpp_fcl_solvable_runs(solver): ) +@flaky +def test_biopython_solvable_runs(solver): + feedstock_dir = os.path.join(os.path.dirname(__file__), "biopython-feedstock") + is_recipe_solvable( + feedstock_dir, + solver=solver, + verbosity=VERB, + ) + + def clone_and_checkout_repo(base_path: pathlib.Path, origin_url: str, ref: str): subprocess.run( f"cd {base_path} && git clone {origin_url} repo", diff --git a/tests/test_utils.py b/tests/test_utils.py index b125e58..b2b258c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -145,21 +145,23 @@ def test_replace_pin_compatible(): def test_replace_pin_compatible_raises(): with pytest.raises(ValueError) as e: - replace_pin_compatible(["pin_compatible('foo') mpi_*"], []) + replace_pin_compatible(["pin_compatible('foo') mpi_*"], [], strict=True) assert "Package foo not found in host" in str(e.value) with pytest.raises(ValueError) as e: - replace_pin_compatible(["pin_compatible('foo') mpi_*"], ["foo"]) + replace_pin_compatible(["pin_compatible('foo') mpi_*"], ["foo"], strict=True) assert "Package found in host but no version" in str(e.value) with pytest.raises(ValueError) as e: replace_pin_compatible( - ["pin_compatible('foo', exact=True) mpi_*"], ["foo 14 dfgdfs"] + ["pin_compatible('foo', exact=True) mpi_*"], ["foo 14 dfgdfs"], strict=True ) assert "Build string cannot be given for pin_compatible with exact=True!" in str( e.value ) with pytest.raises(ValueError) as e: - replace_pin_compatible(["5 pin_compatible('foo') mpi_*"], ["foo 14 dfgdfs"]) + replace_pin_compatible( + ["5 pin_compatible('foo') mpi_*"], ["foo 14 dfgdfs"], strict=True + ) assert "Very odd" in str(e.value)