Skip to content

Commit

Permalink
Adjust imports
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Apr 17, 2024
1 parent 6a609ee commit 210c30a
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from conda.base.context import context
from conda.gateways.disk.read import compute_sum

from . import exceptions, utils, variants
from . import exceptions, utils
from .conda_interface import MatchSpec
from .config import Config, get_or_merge_config
from .features import feature_list
Expand All @@ -34,6 +34,15 @@
insert_variant_versions,
on_win,
)
from .variants import (
dict_of_lists_to_list_of_dicts,
find_used_variables_in_batch_script,
find_used_variables_in_shell_script,
find_used_variables_in_text,
get_default_variant,
get_vars,
list_of_dicts_to_dict_of_lists,
)

if TYPE_CHECKING:
from typing import Literal
Expand Down Expand Up @@ -156,7 +165,7 @@ def get_selectors(config: Config) -> dict[str, bool]:
if arch == "32":
d["x86"] = plat.endswith(("-32", "-64"))

defaults = variants.get_default_variant(config)
defaults = get_default_variant(config)
py = config.variant.get("python", defaults["python"])
# there are times when python comes in as a tuple
if not hasattr(py, "split"):
Expand Down Expand Up @@ -2448,9 +2457,7 @@ def append_parent_metadata(self, out_metadata):

def get_reduced_variant_set(self, used_variables):
# reduce variable space to limit work we need to do
full_collapsed_variants = variants.list_of_dicts_to_dict_of_lists(
self.config.variants
)
full_collapsed_variants = list_of_dicts_to_dict_of_lists(self.config.variants)
reduced_collapsed_variants = full_collapsed_variants.copy()
reduce_keys = set(self.config.variants[0].keys()) - set(used_variables)

Expand Down Expand Up @@ -2482,7 +2489,7 @@ def get_reduced_variant_set(self, used_variables):
# save only one element from this key
reduced_collapsed_variants[key] = utils.ensure_list(next(iter(values)))

out = variants.dict_of_lists_to_list_of_dicts(reduced_collapsed_variants)
out = dict_of_lists_to_list_of_dicts(reduced_collapsed_variants)
return out

def get_output_metadata_set(
Expand Down Expand Up @@ -2633,12 +2640,7 @@ def get_output_metadata_set(
return output_tuples

def get_loop_vars(self):
_variants = (
self.config.input_variants
if hasattr(self.config, "input_variants")
else self.config.variants
)
return variants.get_vars(_variants)
return get_vars(getattr(self.config, "input_variants", self.config.variants))

def get_used_loop_vars(self, force_top_level=False, force_global=False):
loop_vars = self.get_loop_vars()
Expand Down Expand Up @@ -2825,7 +2827,7 @@ def _get_used_vars_meta_yaml(self, force_top_level=False, force_global=False):
apply_selectors=False,
)

all_used_selectors = variants.find_used_variables_in_text(
all_used_selectors = find_used_variables_in_text(
variant_keys, recipe_text, selectors_only=True
)

Expand All @@ -2834,7 +2836,7 @@ def _get_used_vars_meta_yaml(self, force_top_level=False, force_global=False):
force_global=force_global,
apply_selectors=True,
)
all_used_reqs = variants.find_used_variables_in_text(
all_used_reqs = find_used_variables_in_text(
variant_keys, recipe_text, selectors_only=False
)

Expand All @@ -2845,9 +2847,7 @@ def _get_used_vars_meta_yaml(self, force_top_level=False, force_global=False):
if force_global:
used = all_used
else:
requirements_used = variants.find_used_variables_in_text(
variant_keys, reqs_text
)
requirements_used = find_used_variables_in_text(variant_keys, reqs_text)
outside_reqs_used = all_used - requirements_used

requirements_used = trim_build_only_deps(self, requirements_used)
Expand All @@ -2860,16 +2860,12 @@ def _get_used_vars_build_scripts(self):
buildsh = os.path.join(self.path, "build.sh")
if os.path.isfile(buildsh):
used_vars.update(
variants.find_used_variables_in_shell_script(
self.config.variant, buildsh
)
find_used_variables_in_shell_script(self.config.variant, buildsh)
)
bldbat = os.path.join(self.path, "bld.bat")
if self.config.platform == "win" and os.path.isfile(bldbat):
used_vars.update(
variants.find_used_variables_in_batch_script(
self.config.variant, bldbat
)
find_used_variables_in_batch_script(self.config.variant, bldbat)
)
return used_vars

Expand All @@ -2882,15 +2878,11 @@ def _get_used_vars_output_script(self):
script = os.path.join(self.path, this_output["script"])
if os.path.splitext(script)[1] == ".sh":
used_vars.update(
variants.find_used_variables_in_shell_script(
self.config.variant, script
)
find_used_variables_in_shell_script(self.config.variant, script)
)
elif os.path.splitext(script)[1] == ".bat":
used_vars.update(
variants.find_used_variables_in_batch_script(
self.config.variant, script
)
find_used_variables_in_batch_script(self.config.variant, script)
)
else:
log = utils.get_logger(__name__)
Expand All @@ -2901,7 +2893,7 @@ def _get_used_vars_output_script(self):
return used_vars

def get_variants_as_dict_of_lists(self):
return variants.list_of_dicts_to_dict_of_lists(self.config.variants)
return list_of_dicts_to_dict_of_lists(self.config.variants)

def clean(self):
"""This ensures that clean is called with the correct build id"""
Expand Down

0 comments on commit 210c30a

Please sign in to comment.