Skip to content

Commit

Permalink
Prepare deprecation of full index and action usage
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Jan 26, 2024
1 parent 6e3e9f5 commit 17a7d9a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 62 deletions.
30 changes: 15 additions & 15 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ def create_build_envs(m: MetaData, notest):
m.config._merge_build_host = m.build_is_host

if m.is_cross and not m.build_is_host:
host_actions = environ.get_install_actions(
host_precs = environ.get_package_records(
m.config.host_prefix,
tuple(host_ms_deps),
"host",
Expand All @@ -2325,7 +2325,7 @@ def create_build_envs(m: MetaData, notest):
)
environ.create_env(
m.config.host_prefix,
host_actions,
host_precs,
env="host",
config=m.config,
subdir=m.config.host_subdir,
Expand All @@ -2334,7 +2334,7 @@ def create_build_envs(m: MetaData, notest):
)
if m.build_is_host:
build_ms_deps.extend(host_ms_deps)
build_actions = environ.get_install_actions(
build_precs = environ.get_package_records(
m.config.build_prefix,
tuple(build_ms_deps),
"build",
Expand All @@ -2360,7 +2360,7 @@ def create_build_envs(m: MetaData, notest):
*utils.ensure_list(m.get_value("requirements/run", [])),
]
# make sure test deps are available before taking time to create build env
environ.get_install_actions(
environ.get_package_records(
m.config.test_prefix,
tuple(test_run_ms_deps),
"test",
Expand Down Expand Up @@ -2397,7 +2397,7 @@ def create_build_envs(m: MetaData, notest):
):
environ.create_env(
m.config.build_prefix,
build_actions,
build_precs,
env="build",
config=m.config,
subdir=m.config.build_subdir,
Expand Down Expand Up @@ -2435,8 +2435,8 @@ def build(
return default_return

log = utils.get_logger(__name__)
host_actions = []
build_actions = []
host_precs = []
build_precs = []
output_metas = []

with utils.path_prepended(m.config.build_prefix):
Expand Down Expand Up @@ -2779,7 +2779,7 @@ def build(
host_ms_deps = m.ms_depends("host")
sub_build_ms_deps = m.ms_depends("build")
if m.is_cross and not m.build_is_host:
host_actions = environ.get_install_actions(
host_precs = environ.get_package_records(
m.config.host_prefix,
tuple(host_ms_deps),
"host",
Expand All @@ -2796,7 +2796,7 @@ def build(
)
environ.create_env(
m.config.host_prefix,
host_actions,
host_precs,
env="host",
config=m.config,
subdir=subdir,
Expand All @@ -2806,7 +2806,7 @@ def build(
else:
# When not cross-compiling, the build deps aggregate 'build' and 'host'.
sub_build_ms_deps.extend(host_ms_deps)
build_actions = environ.get_install_actions(
build_precs = environ.get_package_records(
m.config.build_prefix,
tuple(sub_build_ms_deps),
"build",
Expand All @@ -2823,7 +2823,7 @@ def build(
)
environ.create_env(
m.config.build_prefix,
build_actions,
build_precs,
env="build",
config=m.config,
subdir=m.config.build_subdir,
Expand Down Expand Up @@ -3481,7 +3481,7 @@ def test(
utils.rm_rf(metadata.config.test_prefix)

try:
actions = environ.get_install_actions(
precs = environ.get_package_records(
metadata.config.test_prefix,
tuple(specs),
"host",
Expand Down Expand Up @@ -3523,7 +3523,7 @@ def test(
with env_var("CONDA_PATH_CONFLICT", conflict_verbosity, reset_context):
environ.create_env(
metadata.config.test_prefix,
actions,
precs,
config=metadata.config,
env="host",
subdir=subdir,
Expand Down Expand Up @@ -3819,7 +3819,7 @@ def build_tree(
with TemporaryDirectory(
prefix="_", suffix=r_string
) as tmpdir:
actions = environ.get_install_actions(
precs = environ.get_package_records(
tmpdir,
specs,
env="run",
Expand All @@ -3839,7 +3839,7 @@ def build_tree(
# make sure to download that package to the local cache if not there
local_file = execute_download_actions(
meta,
actions,
precs,
"host",
package_subset=[dep],
require_files=True,
Expand Down
76 changes: 59 additions & 17 deletions conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
LockError,
MatchSpec,
NoPackagesFoundError,
PackageRecord,
PaddingError,
ProgressiveFetchExtract,
TemporaryDirectory,
Expand All @@ -45,6 +46,7 @@
reset_context,
root_dir,
)
from .deprecations import deprecated
from .exceptions import BuildLockError, DependencyNeedsBuildingError
from .features import feature_list
from .index import get_build_index
Expand Down Expand Up @@ -851,6 +853,7 @@ def package_specs(self):
last_index_ts = 0


@deprecated("24.1.0", "24.3.0", addendum="Use `get_package_records` instead.")
def get_install_actions(
prefix,
specs,
Expand Down Expand Up @@ -1001,9 +1004,44 @@ def get_install_actions(
return actions


def get_package_records(
prefix,
specs,
env,
retries=0,
subdir=None,
verbose=True,
debug=False,
locking=True,
bldpkgs_dirs=None,
timeout=900,
disable_pip=False,
max_env_retry=3,
output_folder=None,
channel_urls=None,
):
return get_install_actions(
prefix=prefix,
specs=specs,
env=env,
retries=retries,
subdir=subdir,
verbose=verbose,
debug=debug,
locking=locking,
bldpkgs_dirs=bldpkgs_dirs,
timeout=timeout,
disable_pip=disable_pip,
max_env_retry=max_env_retry,
output_folder=output_folder,
channel_urls=channel_urls,
).get(LINK_ACTION, [])


@deprecated.argument("24.1.0", "24.3.0", "specs_or_actions", rename="specs_or_precs")
def create_env(
prefix,
specs_or_actions,
specs_or_precs,
env,
config,
subdir,
Expand Down Expand Up @@ -1031,17 +1069,20 @@ def create_env(
# if os.path.isdir(prefix):
# utils.rm_rf(prefix)

if specs_or_actions: # Don't waste time if there is nothing to do
if specs_or_precs: # Don't waste time if there is nothing to do
log.debug("Creating environment in %s", prefix)
log.debug(str(specs_or_actions))
log.debug(str(specs_or_precs))

if not locks:
locks = utils.get_conda_operation_locks(config)
try:
with utils.try_acquire_locks(locks, timeout=config.timeout):
# input is a list - it's specs in MatchSpec format
if not hasattr(specs_or_actions, "keys"):
specs = list(set(specs_or_actions))
# input is a list of specs in MatchSpec format
if not (
hasattr(specs_or_precs, "keys")
or isinstance(specs_or_precs[0], PackageRecord)
):
specs = list(set(specs_or_precs))
actions = get_install_actions(
prefix,
tuple(specs),
Expand All @@ -1058,7 +1099,10 @@ def create_env(
channel_urls=tuple(config.channel_urls),
)
else:
actions = specs_or_actions
if not hasattr(specs_or_precs, "keys"):
actions = {LINK_ACTION: specs_or_precs}
else:
actions = specs_or_precs
index, _, _ = get_build_index(
subdir=subdir,
bldpkgs_dir=config.bldpkgs_dir,
Expand All @@ -1070,13 +1114,13 @@ def create_env(
timeout=config.timeout,
)
utils.trim_empty_keys(actions)
_display_actions(actions)
_display_actions(prefix, actions)
if utils.on_win:
for k, v in os.environ.items():
os.environ[k] = str(v)
with env_var("CONDA_QUIET", not config.verbose, reset_context):
with env_var("CONDA_JSON", not config.verbose, reset_context):
_execute_actions(actions)
_execute_actions(prefix, actions)
except (
SystemExit,
PaddingError,
Expand Down Expand Up @@ -1136,7 +1180,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1167,7 +1211,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1205,7 +1249,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1314,12 +1358,11 @@ def install_actions(prefix, index, specs):
del install_actions


def _execute_actions(actions):
def _execute_actions(prefix, actions):
# This is copied over from https://github.com/conda/conda/blob/23.11.0/conda/plan.py#L575
# but reduced to only the functionality actually used within conda-build.

assert PREFIX_ACTION in actions and actions[PREFIX_ACTION]
prefix = actions[PREFIX_ACTION]
assert prefix

if LINK_ACTION not in actions:
log.debug(f"action {LINK_ACTION} not in actions")
Expand Down Expand Up @@ -1348,11 +1391,10 @@ def _execute_actions(actions):
unlink_link_transaction.execute()


def _display_actions(actions):
def _display_actions(prefix, actions):
# This is copied over from https://github.com/conda/conda/blob/23.11.0/conda/plan.py#L58
# but reduced to only the functionality actually used within conda-build.

prefix = actions.get(PREFIX_ACTION)
builder = ["", "## Package Plan ##\n"]
if prefix:
builder.append(" environment location: %s" % prefix)
Expand Down
Loading

0 comments on commit 17a7d9a

Please sign in to comment.