Skip to content

Commit

Permalink
fix: change pin_compatible to match conda-build (#56)
Browse files Browse the repository at this point in the history
* fix: change pin_compatible to match conda-build

* fix: need strict here
  • Loading branch information
beckermr committed Sep 3, 2024
1 parent 9f4502f commit a4efa10
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 15 deletions.
53 changes: 42 additions & 11 deletions conda_forge_feedstock_check_solvable/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
110 changes: 110 additions & 0 deletions tests/biopython-feedstock/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/test_check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a4efa10

Please sign in to comment.