Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Sep 20, 2024
1 parent d644905 commit 3b23858
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 50 deletions.
95 changes: 60 additions & 35 deletions conda_forge_feedstock_check_solvable/check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import conda_forge_feedstock_check_solvable.utils
from conda_forge_feedstock_check_solvable.mamba_solver import mamba_solver_factory
from conda_forge_feedstock_check_solvable.rattler_build import invoke_rattler_build
from conda_forge_feedstock_check_solvable.rattler_solver import rattler_solver_factory
from conda_forge_feedstock_check_solvable.utils import (
MAX_GLIBC_MINOR,
Expand All @@ -24,7 +25,6 @@
print_warning,
remove_reqs_by_name,
replace_pin_compatible,
suppress_output,
)
from conda_forge_feedstock_check_solvable.virtual_packages import (
virtual_package_repodata,
Expand Down Expand Up @@ -132,7 +132,12 @@ def _is_recipe_solvable(
print_warning(errors[-1])
return False, errors, {}

if not os.path.exists(os.path.join(feedstock_dir, "recipe", "meta.yaml")):
meta_exists = os.path.exists(os.path.join(feedstock_dir, "recipe", "meta.yaml"))
recipe_exists = os.path.exists(
os.path.join(feedstock_dir, "recipe", "recipe.yaml")
)

if not (meta_exists or recipe_exists):
errors.append(
"No `recipe/meta.yaml` file found! This issue is quite weird and "
"someone should investigate!",
Expand Down Expand Up @@ -187,8 +192,8 @@ def _is_recipe_solvable(


def _is_recipe_solvable_on_platform(
recipe_dir,
cbc_path,
recipe_dir: str,
cbc_path: str,
platform,
arch,
build_platform_arch=None,
Expand Down Expand Up @@ -234,43 +239,63 @@ def _is_recipe_solvable_on_platform(
# it would be used in a real build
print_debug("rendering recipe with conda build")

with suppress_output():
for att in range(2):
timeout_timer.raise_for_timeout()
try:
if att == 1:
os.system("rm -f %s/conda_build_config.yaml" % recipe_dir)
config = conda_build.config.get_or_merge_config(
None,
platform=platform,
arch=arch,
variant_config_files=[cbc_path],
)
cbc, _ = conda_build.variants.get_package_combined_spec(
recipe_dir,
config=config,
)
except Exception as e:
if att == 0:
pass
else:
raise e

# with suppress_output():
for att in range(2):
timeout_timer.raise_for_timeout()
try:
if att == 1:
os.system("rm -f %s/conda_build_config.yaml" % recipe_dir)
config = conda_build.config.get_or_merge_config(
None,
platform=platform,
arch=arch,
variant_config_files=[cbc_path],
)
cbc, _ = conda_build.variants.get_package_combined_spec(
recipe_dir,
config=config,
)
except Exception as e:
if att == 0:
pass
else:
raise e

timeout_timer.raise_for_timeout()

# now we render the meta.yaml into an actual recipe
metas = conda_build_api_render(
# now we render the meta.yaml into an actual recipe
print("Recipe dir: ", recipe_dir)

if os.path.exists(os.path.join(recipe_dir, "recipe.yaml")):
print("Recipe YAMLING!")
# this is a rattler-build recipe so we can invoke rattler-build with
# the new `cbc`.
solvable, errors = invoke_rattler_build(
recipe_dir,
platform=platform,
arch=arch,
ignore_system_variants=True,
channels=channel_sources,
build_platform=f"{platform}-{arch}",
host_platform=f"{platform}-{arch}",
variants=cbc,
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=channel_sources,
)

if errors:
print_warning("Rattler build errors: %s", errors)
errors = [f"Rattler build errors: {errors}"]

return solvable, errors

metas = conda_build_api_render(
recipe_dir,
platform=platform,
arch=arch,
ignore_system_variants=True,
variants=cbc,
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=channel_sources,
)

timeout_timer.raise_for_timeout()

# get build info
Expand Down
33 changes: 18 additions & 15 deletions conda_forge_feedstock_check_solvable/rattler_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import os
import subprocess

from conda_forge_feedstock_check_solvable.virtual_packages import (
virtual_package_repodata,
)
Expand All @@ -9,7 +10,9 @@ def run_rattler_build(command):
try:
# Run the command and capture output
print(" ".join(command))
result = subprocess.run(command, shell=True, check=False, capture_output=True, text=True)
result = subprocess.run(
command, shell=True, check=False, capture_output=True, text=True
)

# Get the status code
status_code = result.returncode
Expand All @@ -23,7 +26,9 @@ def run_rattler_build(command):
return -1, "", str(e)


def invoke_rattler_build(recipe_dir: str, channels, build_platform, host_platform, variants) -> (bool, str):
def invoke_rattler_build(
recipe_dir: str, channels, build_platform, host_platform, variants
) -> (bool, str):
print("invoke_rattler_build")
virtual_package_repo_url = virtual_package_repodata()

Expand All @@ -35,21 +40,19 @@ def invoke_rattler_build(recipe_dir: str, channels, build_platform, host_platfor

variants_args = []
# for v in variants:
# variants_args.extend(["-m", v])
args = [
"rattler-build",
"build", "--recipe",
recipe_dir] + channels_args + \
["--target-platform", host_platform, "--build-platform", build_platform] + \
variants_args + \
["--render-only", "--with-solve"]
# variants_args.extend(["-m", v])
args = (
["rattler-build", "build", "--recipe", recipe_dir]
+ channels_args
+ ["--target-platform", host_platform, "--build-platform", build_platform]
+ variants_args
+ ["--render-only", "--with-solve"]
)
print(" ".join(args))

recipe = os.path.join(recipe_dir, "recipe.yaml")
status, out, err = run_rattler_build([
"rattler-build",
"build", "--recipe",
recipe] # + channels_args + \
status, out, err = run_rattler_build(
["rattler-build", "build", "--recipe", recipe] # + channels_args + \
# ["--target-platform", host_platform, "--build-platform", build_platform] + \
# variants_args + \
# ["--render-only", "--with-solve"]
Expand Down
18 changes: 18 additions & 0 deletions tests/test_check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,21 @@ def test_pillow_solvable(tmp_path, solver):
pprint.pprint(solvable_by_variant)
assert solvable, pprint.pformat(errors)
assert any("python3.10" in k for k in solvable_by_variant)


def test_jolt_physics_rattler(tmp_path):
"""test the new recipe format"""
feedstock_dir = clone_and_checkout_repo(
tmp_path,
"https://github.com/conda-forge/jolt-physics-feedstock",
ref="main",
)
solvable, errors, solvable_by_variant = is_recipe_solvable(
feedstock_dir,
solver="rattler",
verbosity=VERB,
timeout=None,
fail_fast=True,
)
pprint.pprint(solvable_by_variant)
assert solvable, pprint.pformat(errors)

0 comments on commit 3b23858

Please sign in to comment.