Skip to content

Commit

Permalink
Prepare deprecation of full index and action usage (#5152)
Browse files Browse the repository at this point in the history
Co-authored-by: Ken Odegard <kodegard@anaconda.com>
  • Loading branch information
mbargull and kenodegard committed Jan 31, 2024
1 parent 0435053 commit 7dbf29e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 64 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@
* Mark `conda_build.conda_interface.linked` as pending deprecation. (#5074)
* Mark `conda_build.conda_interface.linked_data` as pending deprecation. (#5074)
* Mark `conda_build.utils.linked_data_no_multichannels` as pending deprecation. (#5074)
* Mark `conda_build.environ.get_install_actions` as pending deprecation in favor of `conda_build.environ.get_package_records`. (#5152)
* Mark `conda_build.environ.create_env(specs_or_actions)` as pending deprecation in favor of `conda_build.environ.create_env(specs_or_precs)`. (#5152)
* Mark `conda_build.index.channel_data` as pending deprecation. (#5152)
* Mark `conda_build.index._determine_namespace` as pending deprecation. (#5152)
* Mark `conda_build.index._make_seconds` as pending deprecation. (#5152)
* Mark `conda_build.index.REPODATA_VERSION` as pending deprecation. (#5152)
* Mark `conda_build.index.CHANNELDATA_VERSION` as pending deprecation. (#5152)
* Mark `conda_build.index.REPODATA_JSON_FN` as pending deprecation. (#5152)
* Mark `conda_build.index.REPODATA_FROM_PKGS_JSON_FN` as pending deprecation. (#5152)
* Mark `conda_build.index.CHANNELDATA_FIELDS` as pending deprecation. (#5152)
* Mark `conda_build.index._clear_newline_chars` as pending deprecation. (#5152)
* Mark `conda_build.index._apply_instructions` as pending deprecation. (#5152)
* Mark `conda_build.index._get_jinja2_environment` as pending deprecation. (#5152)
* Mark `conda_build.index._maybe_write` as pending deprecation. (#5152)
* Mark `conda_build.index._maybe_build_string` as pending deprecation. (#5152)
* Mark `conda_build.index._warn_on_missing_dependencies` as pending deprecation. (#5152)
* Mark `conda_build.index._cache_post_install_details` as pending deprecation. (#5152)
* Mark `conda_build.index._cache_recipe` as pending deprecation. (#5152)
* Mark `conda_build.index._cache_run_exports` as pending deprecation. (#5152)
* Mark `conda_build.index._cache_icon` as pending deprecation. (#5152)
* Mark `conda_build.index._make_subdir_index_html` as pending deprecation. (#5152)
* Mark `conda_build.index._make_channeldata_index_html` as pending deprecation. (#5152)
* Mark `conda_build.index._get_source_repo_git_info` as pending deprecation. (#5152)
* Mark `conda_build.index._cache_info_file` as pending deprecation. (#5152)
* Mark `conda_build.index._alternate_file_extension` as pending deprecation. (#5152)
* Mark `conda_build.index._get_resolve_object` as pending deprecation. (#5152)
* Mark `conda_build.index._get_newest_versions` as pending deprecation. (#5152)
* Mark `conda_build.index._add_missing_deps` as pending deprecation. (#5152)
* Mark `conda_build.index._add_prev_ver_for_features` as pending deprecation. (#5152)
* Mark `conda_build.index._shard_newest_packages` as pending deprecation. (#5152)
* Mark `conda_build.index._build_current_repodata` as pending deprecation. (#5152)
* Mark `conda_build.index.ChannelIndex` as pending deprecation. (#5152)
* Mark `conda_build.render.actions_to_pins` as pending deprecation. (#5152)
* Mark `conda_build.render.execute_download_actions(actions)` as pending deprecation in favor of `conda_build.render.execute_download_actions(precs)`. (#5152)
* Mark `conda_build.render.get_upstream_pins(actions)` as pending deprecation in favor of `conda_build.render.get_upstream_pins(precs)`. (#5152)
* Remove `conda_build.api.update_index`. (#5151)
* Remove `conda_build.cli.main_build.main`. (#5151)
* Remove `conda_build.cli.main_convert.main`. (#5151)
Expand Down
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

0 comments on commit 7dbf29e

Please sign in to comment.