Skip to content

Commit

Permalink
BUG fix bug in getting run exports, refactor a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Jun 1, 2024
1 parent 2598319 commit 3e281eb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 45 deletions.
6 changes: 3 additions & 3 deletions conda_forge_feedstock_check_solvable/check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
print_info,
print_warning,
remove_reqs_by_name,
suppress_conda_build_logging,
suppress_output,
)


Expand Down Expand Up @@ -239,7 +239,7 @@ def _is_recipe_solvable_on_platform(
# it would be used in a real build
print_debug("rendering recipe with conda build")

with suppress_conda_build_logging():
with suppress_output():
for att in range(2):
try:
if att == 1:
Expand Down Expand Up @@ -282,7 +282,7 @@ def _is_recipe_solvable_on_platform(
# now we loop through each one and check if we can solve it
# we check run and host and ignore the rest
print_debug("getting mamba solver")
with suppress_conda_build_logging():
with suppress_output():
solver = _mamba_factory(tuple(channel_sources), f"{platform}-{arch}")
build_solver = _mamba_factory(
tuple(channel_sources),
Expand Down
43 changes: 30 additions & 13 deletions conda_forge_feedstock_check_solvable/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def print_debug(fmt, *args):


@contextlib.contextmanager
def suppress_conda_build_logging():
def suppress_output():
if "CONDA_FORGE_FEEDSTOCK_CHECK_SOLVABLE_DEBUG" in os.environ:
suppress = False
else:
Expand Down Expand Up @@ -258,7 +258,7 @@ def _get_run_export_download(c, pkg):
run_exports[key] = set(run_exports.get(key, []))

except Exception as e:
print("Could not get run exports for %s: %s", pkg, repr(e))
print(f"Could not get run exports for {pkg}: {repr(e)}")
run_exports = None
pass

Expand Down Expand Up @@ -299,6 +299,8 @@ def get_run_export(full_channel_url, filename):
Each is tried in turn and the first that works is used.
"""
print_debug(f"RUN EXPORTS: {full_channel_url} {filename}")

if "https://" in full_channel_url:
https = _strip_anaconda_tokens(full_channel_url)
channel_url = https.rsplit("/", maxsplit=1)[0]
Expand Down Expand Up @@ -329,20 +331,35 @@ def get_run_export(full_channel_url, filename):
if not rx:
cd = download_channeldata(channel_url)
if cd.get("packages", {}).get(name, {}).get("run_exports", {}):
artifact_data = get_artifact_info_as_json(
channel,
subdir,
filename,
)
if artifact_data is not None:
rx = (
artifact_data.get("rendered_recipe", {})
.get("build", {})
.get("run_exports", {})
try:
print_debug(
"RUN EXPORTS: using conda-forge-metadata for %s/%s/%s",
channel,
subdir,
filename,
)
with suppress_output():
artifact_data = get_artifact_info_as_json(
channel,
subdir,
filename,
)
if artifact_data is not None:
rx = (
artifact_data.get("rendered_recipe", {})
.get("build", {})
.get("run_exports", {})
)
except Exception as e:
print_debug(
"RUN EXPORT: could not get run_exports from conda-forge-metadata: %s",
repr(e),
)
artifact_data = None
rx = {}

# Third source: download from the full artifact
if not rx:
if not rx and artifact_data is None:
print_info(
"RUN EXPORTS: downloading package %s/%s/%s"
% (channel_url, subdir, filename),
Expand Down
36 changes: 7 additions & 29 deletions tests/test_mamba_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
_mamba_factory,
virtual_package_repodata,
)
from conda_forge_feedstock_check_solvable.utils import (
apply_pins,
convert_spec_to_conda_build,
suppress_conda_build_logging,
)
from conda_forge_feedstock_check_solvable.utils import apply_pins, suppress_output

FEEDSTOCK_DIR = os.path.join(os.path.dirname(__file__), "test_feedstock")

Expand Down Expand Up @@ -82,7 +78,7 @@ def test_mamba_solver_apply_pins(tmp_path):
)
import conda_build.api

with suppress_conda_build_logging():
with suppress_output():
config = conda_build.config.get_or_merge_config(
None,
platform="linux",
Expand Down Expand Up @@ -130,7 +126,7 @@ def test_mamba_solver_apply_pins(tmp_path):

@flaky
def test_mamba_solver_constraints():
with suppress_conda_build_logging():
with suppress_output():
solver = _mamba_factory(("conda-forge",), "osx-64")
solvable, err, solution = solver.solve(
["simplejson"], constraints=["python=3.10", "zeromq=4.2"]
Expand All @@ -146,7 +142,7 @@ def test_mamba_solver_constraints():

@flaky
def test_mamba_solver_constraints_unsolvable():
with suppress_conda_build_logging():
with suppress_output():
solver = MambaSolver(("conda-forge",), "osx-64")
solvable, err, solution = solver.solve(
["simplejson"], constraints=["python=3.10", "python=3.11"]
Expand All @@ -156,7 +152,7 @@ def test_mamba_solver_constraints_unsolvable():

@flaky
def test_mamba_solver_nvcc():
with suppress_conda_build_logging():
with suppress_output():
virtual_packages = virtual_package_repodata()
solver = MambaSolver([virtual_packages, "conda-forge", "defaults"], "linux-64")
out = solver.solve(
Expand Down Expand Up @@ -522,24 +518,6 @@ def test_is_recipe_solvable_notok(feedstock_dir):
assert not is_recipe_solvable(feedstock_dir)[0]


@pytest.mark.parametrize(
"inreq,outreq",
[
("blah 1.1*", "blah 1.1.*"),
("blah * *_osx", "blah * *_osx"),
("blah 1.1", "blah 1.1.*"),
("blah =1.1", "blah 1.1.*"),
("blah * *_osx", "blah * *_osx"),
("blah 1.2 *_osx", "blah 1.2.* *_osx"),
("blah >=1.1", "blah >=1.1"),
("blah >=1.1|5|>=5,<10|19.0", "blah >=1.1|5.*|>=5,<10|19.0.*"),
("blah >=1.1|5| >=5 , <10 |19.0", "blah >=1.1|5.*|>=5,<10|19.0.*"),
],
)
def testconvert_spec_to_conda_build(inreq, outreq):
assert convert_spec_to_conda_build(inreq) == outreq


@flaky
def test_virtual_package(feedstock_dir, tmp_path_factory):
recipe_file = os.path.join(feedstock_dir, "recipe", "meta.yaml")
Expand Down Expand Up @@ -586,7 +564,7 @@ def test_virtual_package(feedstock_dir, tmp_path_factory):

@flaky
def test_mamba_solver_hangs():
with suppress_conda_build_logging():
with suppress_output():
solver = _mamba_factory(("conda-forge", "defaults"), "osx-64")
res = solver.solve(
[
Expand Down Expand Up @@ -622,7 +600,7 @@ def test_mamba_solver_hangs():
)
assert res[0]

with suppress_conda_build_logging():
with suppress_output():
solver = _mamba_factory(("conda-forge", "defaults"), "linux-64")
res = solver.solve(
[
Expand Down
33 changes: 33 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from conda_forge_feedstock_check_solvable.utils import (
convert_spec_to_conda_build,
get_run_export,
)

@pytest.mark.parametrize(
"inreq,outreq",
[
("blah 1.1*", "blah 1.1.*"),
("blah * *_osx", "blah * *_osx"),
("blah 1.1", "blah 1.1.*"),
("blah =1.1", "blah 1.1.*"),
("blah * *_osx", "blah * *_osx"),
("blah 1.2 *_osx", "blah 1.2.* *_osx"),
("blah >=1.1", "blah >=1.1"),
("blah >=1.1|5|>=5,<10|19.0", "blah >=1.1|5.*|>=5,<10|19.0.*"),
("blah >=1.1|5| >=5 , <10 |19.0", "blah >=1.1|5.*|>=5,<10|19.0.*"),
],
)
def test_convert_spec_to_conda_build(inreq, outreq):
assert convert_spec_to_conda_build(inreq) == outreq


@pytest.mark.parametrize(
"full_channel_url,filename,expected",
[
("https://conda.anaconda.org/conda-forge/osx-arm64", "openjdk-22.0.1-hbeb2e11_0.conda", None),
],
)
def test_utils_get_run_export(full_channel_url, filename, expected):
get_run_export(full_channel_url, filename) == expected

0 comments on commit 3e281eb

Please sign in to comment.