Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare deprecation of full index and action usage #5152

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
80 changes: 61 additions & 19 deletions conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 @@ -849,7 +850,7 @@ def package_specs(self):
last_index_ts = 0


def get_install_actions(
def get_package_records(
prefix,
specs,
env,
Expand Down Expand Up @@ -996,12 +997,49 @@ def get_install_actions(
utils.trim_empty_keys(actions)
cached_actions[(specs, env, subdir, channel_urls, disable_pip)] = actions.copy()
last_index_ts = index_ts
return actions
return actions.get(LINK_ACTION, [])


@deprecated("24.1.0", "24.3.0", addendum="Use `get_package_records` instead.")
def get_install_actions(
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,
):
precs = get_package_records(
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,
)
return {PREFIX_ACTION: prefix, LINK_ACTION: precs}


@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 @@ -1029,17 +1067,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 @@ -1056,7 +1097,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 @@ -1068,13 +1112,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 @@ -1134,7 +1178,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1165,7 +1209,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1203,7 +1247,7 @@ def create_env(
)
create_env(
prefix,
specs_or_actions,
specs_or_precs,
config=config,
subdir=subdir,
env=env,
Expand Down Expand Up @@ -1312,12 +1356,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 @@ -1346,11 +1389,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
Loading