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

Remove logic branching for conda_43/conda_44/conda_45/conda_46/conda_47 #4677

Merged
merged 9 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
90 changes: 31 additions & 59 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import conda_package_handling.api

# used to get version
from .conda_interface import env_path_backup_var_exists, conda_45, conda_46
from .conda_interface import env_path_backup_var_exists
from .conda_interface import prefix_placeholder
from .conda_interface import TemporaryDirectory
from .conda_interface import VersionOrder
Expand Down Expand Up @@ -1811,15 +1811,11 @@ def scan_metadata(path):
def _write_sh_activation_text(file_handle, m):
cygpath_prefix = "$(cygpath -u " if utils.on_win else ""
cygpath_suffix = " )" if utils.on_win else ""
activate_path = ''.join((cygpath_prefix,
os.path.join(utils.root_script_dir, 'activate').replace('\\', '\\\\'),
cygpath_suffix))

if conda_46:
py_flags = '-I -m' if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else '-m'
file_handle.write(
f"""eval "$('{sys.executable}' {py_flags} conda shell.bash hook)"\n"""
)

py_flags = '-I -m' if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else '-m'
file_handle.write(
f"""eval "$('{sys.executable}' {py_flags} conda shell.bash hook)"\n"""
)

if m.is_cross:
# HACK: we need both build and host envs "active" - i.e. on PATH,
Expand All @@ -1846,24 +1842,16 @@ def _write_sh_activation_text(file_handle, m):
host_prefix_path = ''.join((cygpath_prefix,
m.config.host_prefix.replace('\\', '\\\\'),
cygpath_suffix))
if conda_46:
file_handle.write(f"conda activate \"{host_prefix_path}\"\n")
else:
file_handle.write('source "{}" "{}"\n' .format(activate_path, host_prefix_path))
file_handle.write('unset CONDA_PATH_BACKUP\n')
file_handle.write('export CONDA_MAX_SHLVL=2\n')
file_handle.write(f"conda activate \"{host_prefix_path}\"\n")

# Write build prefix activation AFTER host prefix, so that its executables come first
build_prefix_path = ''.join((cygpath_prefix,
m.config.build_prefix.replace('\\', '\\\\'),
cygpath_suffix))

if conda_46:
# Do not stack against base env when not cross.
stack = '--stack' if m.is_cross else ''
file_handle.write(f"conda activate {stack} \"{build_prefix_path}\"\n")
else:
file_handle.write(f'source "{activate_path}" "{build_prefix_path}"\n')
# Do not stack against base env when not cross.
stack = '--stack' if m.is_cross else ''
file_handle.write(f"conda activate {stack} \"{build_prefix_path}\"\n")

from conda_build.os_utils.external import find_executable
ccache = find_executable('ccache', m.config.build_prefix, False)
Expand Down Expand Up @@ -2723,35 +2711,27 @@ def write_test_scripts(metadata, env_vars, py_files, pl_files, lua_files, r_file
if not utils.on_win:
tf.write(f'set {trace}-e\n')
if metadata.config.activate and not metadata.name() == 'conda':
ext = ".bat" if utils.on_win else ""
if conda_46:
if utils.on_win:
tf.write(
'set "CONDA_SHLVL=" '
'&& @CALL {}\\condabin\\conda_hook.bat {}'
'&& set CONDA_EXE={python_exe}'
'&& set CONDA_PYTHON_EXE={python_exe}'
'&& set _CE_I={}'
'&& set _CE_M=-m'
'&& set _CE_CONDA=conda\n'.format(
sys.prefix,
'--dev' if metadata.config.debug else '',
"-i" if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else "",
python_exe=sys.executable
)
)
else:
py_flags = '-I -m' if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else '-m'
tf.write(
f"""eval "$('{sys.executable}' {py_flags} conda shell.bash hook)"\n"""
if utils.on_win:
tf.write(
'set "CONDA_SHLVL=" '
'&& @CALL {}\\condabin\\conda_hook.bat {}'
'&& set CONDA_EXE={python_exe}'
'&& set CONDA_PYTHON_EXE={python_exe}'
'&& set _CE_I={}'
'&& set _CE_M=-m'
'&& set _CE_CONDA=conda\n'.format(
sys.prefix,
'--dev' if metadata.config.debug else '',
"-i" if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else "",
python_exe=sys.executable
)
tf.write(f'conda activate "{metadata.config.test_prefix}"\n')
)
else:
tf.write('{source} "{conda_root}activate{ext}" "{test_env}"\n'.format(
conda_root=utils.root_script_dir + os.path.sep,
source="call" if utils.on_win else "source",
ext=ext,
test_env=metadata.config.test_prefix))
py_flags = '-I -m' if os.environ.get("_CONDA_BUILD_ISOLATED_ACTIVATION") else '-m'
tf.write(
f"""eval "$('{sys.executable}' {py_flags} conda shell.bash hook)"\n"""
)
tf.write(f'conda activate "{metadata.config.test_prefix}"\n')
if utils.on_win:
tf.write("IF %ERRORLEVEL% NEQ 0 exit /B 1\n")
# In-case people source this, it's essential errors are not fatal in an interactive shell.
Expand Down Expand Up @@ -3414,13 +3394,5 @@ def is_package_built(metadata, env, include_local=True):

spec = MatchSpec(name=metadata.name(), version=metadata.version(), build=metadata.build_id())

if conda_45:
from conda.api import SubdirData
return bool(SubdirData.query_all(spec, channels=urls, subdirs=(subdir, "noarch")))
else:
index, _, _ = get_build_index(subdir=subdir, bldpkgs_dir=metadata.config.bldpkgs_dir,
output_folder=metadata.config.output_folder, channel_urls=urls,
debug=metadata.config.debug, verbose=metadata.config.verbose,
locking=metadata.config.locking, timeout=metadata.config.timeout,
clear_cache=True)
return any(spec.match(prec) for prec in index.values())
from conda.api import SubdirData
return bool(SubdirData.query_all(spec, channels=urls, subdirs=(subdir, "noarch")))
10 changes: 6 additions & 4 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def try_exports(module, attr):
conda_48 = True
conda_411 = True

if conda_44:
from conda.exports import display_actions, execute_actions, execute_plan, install_actions
else:
from conda.plan import display_actions, execute_actions, execute_plan, install_actions
from conda.exports import ( # noqa: E402
display_actions,
execute_actions,
execute_plan,
install_actions,
)

display_actions, execute_actions, execute_plan = display_actions, execute_actions, execute_plan
install_actions = install_actions
Expand Down
8 changes: 2 additions & 6 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
TemporaryDirectory)
from .conda_interface import execute_actions
from .conda_interface import pkgs_dirs
from .conda_interface import conda_43
from .conda_interface import specs_from_url
from .utils import CONDA_PACKAGE_EXTENSION_V1, CONDA_PACKAGE_EXTENSION_V2

Expand Down Expand Up @@ -69,10 +68,7 @@ def bldpkg_path(m):

def actions_to_pins(actions):
specs = []
if conda_43:
spec_name = lambda x: x.dist_name
else:
spec_name = lambda x: str(x)
spec_name = lambda x: x.dist_name
if 'LINK' in actions:
specs = [' '.join(spec_name(spec).split()[0].rsplit('-', 2)) for spec in actions['LINK']]
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
return specs
Expand Down Expand Up @@ -310,7 +306,7 @@ def execute_download_actions(m, actions, env, package_subset=None, require_files
# ran through all pkgs_dirs, and did not find package or folder. Download it.
# TODO: this is a vile hack reaching into conda's internals. Replace with
# proper conda API when available.
if not pkg_loc and conda_43:
if not pkg_loc:
try:
pkg_record = [_ for _ in index if _.dist_name == pkg_dist][0]
# the conda 4.4 API uses a single `link_prefs` kwarg
Expand Down
72 changes: 14 additions & 58 deletions conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from .conda_interface import StringIO # noqa
from .conda_interface import VersionOrder, MatchSpec # noqa
from .conda_interface import cc_conda_build # noqa
from .conda_interface import conda_43, conda_46, Dist # noqa
from .conda_interface import Dist # noqa
from .conda_interface import context # noqa
from .conda_interface import download, TemporaryDirectory, get_conda_channel, CondaHTTPError # noqa
# NOQA because it is not used in this file.
Expand Down Expand Up @@ -1504,36 +1504,7 @@ def filter_info_files(files_list, prefix):


def rm_rf(path, config=None):
if conda_46:
return _rm_rf(path)
if os.path.isdir(path):
try:
# subprocessing to delete large folders can be quite a bit faster
if on_win:
subprocess.check_call(f'rd /s /q {path}', shell=True)
else:
try:
os.makedirs('.empty')
except:
pass
del_dir_cmd = 'rsync -a --delete .empty {}/'
subprocess.check_call(del_dir_cmd.format(path).split())
try:
shutil.rmtree('.empty')
except:
pass
# we don't really care about errors that much. People can and should
# clean out their folders once in a while with "purge"
except:
pass

conda_log_level = logging.WARN
if config and config.debug:
conda_log_level = logging.DEBUG
with LoggingContext(conda_log_level):
# this clears out the path from conda's cache, which otherwise thinks
# that things are still installed here
_rm_rf(path)
return _rm_rf(path)
mbargull marked this conversation as resolved.
Show resolved Hide resolved


# https://stackoverflow.com/a/31459386/1170370
Expand Down Expand Up @@ -1832,8 +1803,7 @@ def match_peer_job(target_matchspec, other_m, this_m=None):
match_dict = {'name': other_m.name(),
'version': other_m.version(),
'build': '', }
if conda_43:
match_dict = Dist(name=match_dict['name'],
match_dict = Dist(name=match_dict['name'],
dist_name='-'.join((match_dict['name'],
match_dict['version'],
match_dict['build'])),
Expand Down Expand Up @@ -1878,10 +1848,9 @@ def sha256_checksum(filename, buffersize=65536):


def write_bat_activation_text(file_handle, m):
if conda_46:
file_handle.write('call "{conda_root}\\..\\condabin\\conda_hook.bat"\n'.format(
conda_root=root_script_dir,
))
file_handle.write('call "{conda_root}\\..\\condabin\\conda_hook.bat"\n'.format(
conda_root=root_script_dir,
))
if m.is_cross:
# HACK: we need both build and host envs "active" - i.e. on PATH,
# and with their activate.d scripts sourced. Conda only
Expand All @@ -1905,29 +1874,16 @@ def write_bat_activation_text(file_handle, m):
os.makedirs(dirname(history_file))
open(history_file, 'a').close()

if conda_46:
file_handle.write('call "{conda_root}\\..\\condabin\\conda.bat" activate "{prefix}"\n'.format(
conda_root=root_script_dir,
prefix=m.config.host_prefix,
))
else:
file_handle.write('call "{conda_root}\\activate.bat" "{prefix}"\n'.format(
conda_root=root_script_dir,
prefix=m.config.host_prefix))
# removing this placeholder should make conda double-activate with conda 4.3
file_handle.write('set "PATH=%PATH:CONDA_PATH_PLACEHOLDER;=%"\n')
file_handle.write('set CONDA_MAX_SHLVL=2\n')

# Write build prefix activation AFTER host prefix, so that its executables come first
if conda_46:
file_handle.write('call "{conda_root}\\..\\condabin\\conda.bat" activate --stack "{prefix}"\n'.format(
file_handle.write('call "{conda_root}\\..\\condabin\\conda.bat" activate "{prefix}"\n'.format(
conda_root=root_script_dir,
prefix=m.config.build_prefix,
prefix=m.config.host_prefix,
))
else:
file_handle.write('call "{conda_root}\\activate.bat" "{prefix}"\n'.format(
conda_root=root_script_dir,
prefix=m.config.build_prefix))

# Write build prefix activation AFTER host prefix, so that its executables come first
file_handle.write('call "{conda_root}\\..\\condabin\\conda.bat" activate --stack "{prefix}"\n'.format(
conda_root=root_script_dir,
prefix=m.config.build_prefix,
))
from conda_build.os_utils.external import find_executable
ccache = find_executable('ccache', m.config.build_prefix, False)
if ccache:
Expand Down
19 changes: 19 additions & 0 deletions news/4677-remove-pre-conda413-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### Deprecations

* Removed conda <4.13 logic. (#4677)

### Docs

* <news item>

### Other

* <news item>
10 changes: 0 additions & 10 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
OverLinkingError, OverDependingError)
from conda_build.conda_interface import reset_context
from conda.exceptions import ClobberError, CondaMultiError
from conda_build.conda_interface import conda_47

from .utils import is_valid_dir, metadata_dir, fail_dir, add_mangling, numpy_installed

Expand Down Expand Up @@ -781,15 +780,6 @@ def test_noarch_python_1(testing_config):
assert 'package_metadata_version' in extra


@pytest.mark.sanity
@pytest.mark.xfail(conda_47, reason="parallel verify/execute in conda 4.7 breaks legacy noarch, which depends on having the env files present before pre-link scripts are run.")
mbargull marked this conversation as resolved.
Show resolved Hide resolved
def test_legacy_noarch_python(testing_config):
output = api.build(os.path.join(metadata_dir, "_legacy_noarch_python"),
config=testing_config)[0]
# make sure that the package is going into the noarch folder
assert os.path.basename(os.path.dirname(output)) == 'noarch'


@pytest.mark.sanity
def test_skip_compile_pyc(testing_config):
outputs = api.build(os.path.join(metadata_dir, "skip_compile_pyc"), config=testing_config)
Expand Down
25 changes: 9 additions & 16 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import conda_package_handling.api
import pytest
from unittest import mock
from conda_build.conda_interface import conda_47, context
from conda_build.conda_interface import context
from conda_build.utils import copy_into, rm_rf

import conda_build.api
Expand Down Expand Up @@ -1134,29 +1134,22 @@ def test_current_index_reduces_space():
"one-gets-filtered-1.3.10-h7b6447c_3.tar.bz2",
}
# conda 4.7 removes .tar.bz2 files in favor of .conda files
if conda_47:
tar_bz2_keys.remove("one-gets-filtered-1.3.10-h7b6447c_3.tar.bz2")
tar_bz2_keys.remove("one-gets-filtered-1.3.10-h7b6447c_3.tar.bz2")

# .conda files will replace .tar.bz2 files. Older packages that are necessary for satisfiability will remain
assert set(trimmed_repodata["packages"].keys()) == tar_bz2_keys
if conda_47:
assert set(trimmed_repodata["packages.conda"].keys()) == {
"one-gets-filtered-1.3.10-h7b6447c_3.conda"
}
assert set(trimmed_repodata["packages.conda"].keys()) == {
"one-gets-filtered-1.3.10-h7b6447c_3.conda"
}

# we can keep more than one version series using a collection of keys
trimmed_repodata = conda_build.index._build_current_repodata(
"linux-64", repodata, {"one-gets-filtered": ["1.2", "1.3"]}
)
if conda_47:
assert set(trimmed_repodata["packages.conda"].keys()) == {
"one-gets-filtered-1.2.11-h7b6447c_3.conda",
"one-gets-filtered-1.3.10-h7b6447c_3.conda",
}
else:
assert set(trimmed_repodata["packages"].keys()) == tar_bz2_keys | {
"one-gets-filtered-1.2.11-h7b6447c_3.tar.bz2"
}
assert set(trimmed_repodata["packages.conda"].keys()) == {
"one-gets-filtered-1.2.11-h7b6447c_3.conda",
"one-gets-filtered-1.3.10-h7b6447c_3.conda",
}


def test_current_index_version_keys_keep_older_packages(testing_workdir):
Expand Down