Skip to content

Commit

Permalink
Merge f556242 into a04dba9
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed May 2, 2024
2 parents a04dba9 + f556242 commit aa8c338
Show file tree
Hide file tree
Showing 36 changed files with 2,187 additions and 336 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ nppBackup/
.mypy_cache/

conda_smithy/_version.py
.pixi/*
42 changes: 36 additions & 6 deletions conda_smithy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import tempfile

from textwrap import dedent
from typing import Literal, Optional, Union

import conda # noqa
import conda_build.api
from conda_build.metadata import MetaData
from rattler_build_conda_compat.render import MetaData as RattlerMetaData
from rattler_build_conda_compat.utils import has_recipe as has_rattler_recipe

import conda_smithy.cirun_utils
from conda_smithy.utils import get_feedstock_name_from_meta, merge_dict
Expand All @@ -21,6 +24,7 @@
from . import feedstock_io
from . import lint_recipe
from . import __version__
from .utils import CONDA_BUILD, RATTLER_BUILD


if sys.version_info[0] == 2:
Expand All @@ -31,7 +35,9 @@ def default_feedstock_config_path(feedstock_directory):
return os.path.join(feedstock_directory, "conda-forge.yml")


def generate_feedstock_content(target_directory, source_recipe_dir):
def generate_feedstock_content(
target_directory, source_recipe_dir, conda_build_tool: Optional[str] = None
):
target_directory = os.path.abspath(target_directory)
recipe_dir = "recipe"
target_recipe_dir = os.path.join(target_directory, recipe_dir)
Expand All @@ -50,13 +56,16 @@ def generate_feedstock_content(target_directory, source_recipe_dir):
).with_traceback(sys.exc_info()[2])

forge_yml = default_feedstock_config_path(target_directory)
yaml = YAML()
if not os.path.exists(forge_yml):
with feedstock_io.write_file(forge_yml) as fh:
fh.write("{}")
if conda_build_tool:
yaml.dump({"conda_build_tool": conda_build_tool}, fh)
else:
fh.write("{}")

# merge in the existing configuration in the source recipe directory
forge_yml_recipe = os.path.join(source_recipe_dir, "conda-forge.yml")
yaml = YAML()
if os.path.exists(forge_yml_recipe):
feedstock_io.remove_file(
os.path.join(target_recipe_dir, "conda-forge.yml")
Expand Down Expand Up @@ -123,10 +132,23 @@ def __call__(self, args):
)

# Get some information about the source recipe.
if args.recipe_directory:
# detect if it's old recipe or new one
meta: Union[MetaData, RattlerMetaData]

build_tool = CONDA_BUILD

# detect what recipe ( meta.yaml or recipe.yaml ) we should render
if has_rattler_recipe(args.recipe_directory):
build_tool = RATTLER_BUILD

if build_tool == CONDA_BUILD:
meta = MetaData(args.recipe_directory)
else:
meta = None
meta = RattlerMetaData(args.recipe_directory)

conda_build_tool: Optional[str] = (
RATTLER_BUILD if isinstance(meta, RattlerMetaData) else None
)

feedstock_directory = args.feedstock_directory.format(
package=argparse.Namespace(name=meta.name())
Expand All @@ -137,7 +159,9 @@ def __call__(self, args):

os.makedirs(feedstock_directory)
subprocess.check_call(["git", "init"], cwd=feedstock_directory)
generate_feedstock_content(feedstock_directory, args.recipe_directory)
generate_feedstock_content(
feedstock_directory, args.recipe_directory, conda_build_tool
)
subprocess.check_call(
["git", "commit", "-m", msg], cwd=feedstock_directory
)
Expand Down Expand Up @@ -608,6 +632,11 @@ def __init__(self, parser):
)
scp = self.subcommand_parser
scp.add_argument("--conda-forge", action="store_true")
scp.add_argument(
"--feedstock-dir",
default=None,
help="feedstock directory",
)
scp.add_argument("recipe_directory", default=[os.getcwd()], nargs="*")

def __call__(self, args):
Expand All @@ -617,6 +646,7 @@ def __call__(self, args):
os.path.join(recipe),
conda_forge=args.conda_forge,
return_hints=True,
feedstock_dir=args.feedstock_dir,
)
if lints:
all_good = False
Expand Down
100 changes: 78 additions & 22 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
import conda_build.render
import conda_build.utils
import conda_build.variants
import conda_build.conda_interface
import conda_build.render
from conda.models.match_spec import MatchSpec
from conda_build.metadata import get_selectors

from copy import deepcopy

from conda_build import __version__ as conda_build_version
from jinja2 import FileSystemLoader
from jinja2.sandbox import SandboxedEnvironment
Expand All @@ -62,7 +69,9 @@
)

from . import __version__

from rattler_build_conda_compat.render import render as rattler_render
from rattler_build_conda_compat.loader import parse_recipe_config_file
from .utils import RATTLER_BUILD

conda_forge_content = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -523,7 +532,6 @@ def _collapse_subpackage_variants(
)

all_variants.add(conda_build.utils.HashableDict(meta.config.variant))

if not meta.noarch:
is_noarch = False

Expand Down Expand Up @@ -894,10 +902,16 @@ def _render_ci_provider(
if ver:
os.environ["DEFAULT_LINUX_VERSION"] = ver

# detect if it's rattler-build recipe
if forge_config["conda_build_tool"] == RATTLER_BUILD:
recipe_file = "recipe.yaml"
else:
recipe_file = "meta.yaml"

# detect if `compiler('cuda')` is used in meta.yaml,
# and set appropriate environment variable
with open(
os.path.join(forge_dir, forge_config["recipe_dir"], "meta.yaml")
os.path.join(forge_dir, forge_config["recipe_dir"], recipe_file)
) as f:
meta_lines = f.readlines()
# looking for `compiler('cuda')` with both quote variants;
Expand All @@ -922,6 +936,25 @@ def _render_ci_provider(
os.path.join(forge_dir, forge_config["recipe_dir"]), config=config
)

# If we are using new recipe
# we also load rattler-build variants.yaml
if recipe_file == "recipe.yaml":
# get_selectors from conda-build return namespace
# so it is usefull to reuse it here
namespace = get_selectors(config)
variants_path = os.path.join(
forge_dir, forge_config["recipe_dir"], "variants.yaml"
)
if os.path.exists(variants_path):
new_spec = parse_recipe_config_file(variants_path, namespace)
specs = {
"combined_spec": combined_variant_spec,
"variants.yaml": new_spec,
}
combined_variant_spec = conda_build.variants.combine_specs(
specs
)

migrated_combined_variant_spec = migrate_combined_spec(
combined_variant_spec,
forge_dir,
Expand Down Expand Up @@ -976,17 +1009,28 @@ def _render_ci_provider(
channel_sources = migrated_combined_variant_spec.get(
"channel_sources", [""]
)[0].split(",")
metas = conda_build.api.render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
platform=platform,
arch=arch,
ignore_system_variants=True,
variants=migrated_combined_variant_spec,
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=channel_sources,
)

if recipe_file == "recipe.yaml":
metas = rattler_render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
platform=platform,
arch=arch,
ignore_system_variants=True,
variants=migrated_combined_variant_spec,
channel_urls=channel_sources,
)
else:
metas = conda_build.api.render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
platform=platform,
arch=arch,
ignore_system_variants=True,
variants=migrated_combined_variant_spec,
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=channel_sources,
)
finally:
if os.path.exists(_recipe_cbc + ".conda.smithy.bak"):
os.rename(_recipe_cbc + ".conda.smithy.bak", _recipe_cbc)
Expand Down Expand Up @@ -1914,14 +1958,24 @@ def render_README(jinja_env, forge_config, forge_dir, render_info=None):

if len(metas) == 0:
try:
metas = conda_build.api.render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
exclusive_config_file=forge_config["exclusive_config_file"],
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
trim_skip=False,
)
if forge_config["conda_build_tool"] == RATTLER_BUILD:
metas = rattler_render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
exclusive_config_file=forge_config[
"exclusive_config_file"
],
)
else:
metas = conda_build.api.render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
exclusive_config_file=forge_config[
"exclusive_config_file"
],
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
trim_skip=False,
)
metas = [m[0] for m in metas]
except Exception:
raise RuntimeError(
Expand Down Expand Up @@ -2205,6 +2259,8 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None):
config["conda_build_tool_deps"] = "conda-build boa"
elif config["conda_build_tool"] == "conda-build+conda-libmamba-solver":
config["conda_build_tool_deps"] = "conda-build conda-libmamba-solver"
elif config["conda_build_tool"] == "rattler-build":
config["conda_build_tool_deps"] = "rattler-build"
else:
config["conda_build_tool_deps"] = "conda-build"

Expand Down
3 changes: 2 additions & 1 deletion conda_smithy/data/conda-forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,8 @@
"conda-build",
"conda-build+classic",
"conda-build+conda-libmamba-solver",
"mambabuild"
"mambabuild",
"rattler-build"
],
"type": "string"
},
Expand Down

0 comments on commit aa8c338

Please sign in to comment.