diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index 5f45b96605..8582247606 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -160,8 +160,8 @@ def parse_args(args): help=("When building v2 packages, set the compression level used by " "conda-package-handling. Defaults to the maximum."), type=int, - choices=range(1, 22), - default=zstd_compression_level_default, + choices=range(1, 23), + default=cc_conda_build.get('zstd_compression_level', zstd_compression_level_default), ) pypi_grp = p.add_argument_group("PyPI upload parameters (twine)") pypi_grp.add_argument( diff --git a/news/gh-4650-fix-cli-zstd-level-override-gh-4649.md b/news/gh-4650-fix-cli-zstd-level-override-gh-4649.md new file mode 100644 index 0000000000..1bae50d432 --- /dev/null +++ b/news/gh-4650-fix-cli-zstd-level-override-gh-4649.md @@ -0,0 +1,3 @@ +### Bug fixes + +* fix: `conda-build` CLI overrode `condarc`'s `zstd_compression_level` with the default value diff --git a/tests/test_cli.py b/tests/test_cli.py index c958ff66de..765456daec 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,11 +13,11 @@ import pytest -from conda_build.conda_interface import download, reset_context +from conda_build.conda_interface import cc_conda_build, context, download, reset_context from conda_build.tarcheck import TarCheck from conda_build import api -from conda_build.config import Config +from conda_build.config import Config, zstd_compression_level_default from conda_build.utils import get_site_packages, on_win, get_build_folders, package_has_file, tar_xf from conda_build.conda_interface import TemporaryDirectory from conda_build.exceptions import DependencyNeedsBuildingError @@ -34,6 +34,14 @@ import conda_build.cli.main_index as main_index +def _reset_config(search_path=None): + reset_context(search_path) + cc_conda_build.clear() + cc_conda_build.update( + context.conda_build if hasattr(context, 'conda_build') else {} + ) + + @pytest.mark.sanity def test_build(): args = ['--no-anaconda-upload', os.path.join(metadata_dir, "empty_sections"), '--no-activate', @@ -492,7 +500,8 @@ def test_purge_all(testing_workdir, testing_metadata): assert not any(os.path.isfile(fn) for fn in outputs) -def test_no_force_upload(mocker, testing_workdir, testing_metadata): +@pytest.mark.serial +def test_no_force_upload(mocker, testing_workdir, testing_metadata, request): with open(os.path.join(testing_workdir, '.condarc'), 'w') as f: f.write('anaconda_upload: True\n') f.write('conda_build:\n') @@ -501,7 +510,8 @@ def test_no_force_upload(mocker, testing_workdir, testing_metadata): api.output_yaml(testing_metadata, 'meta.yaml') args = ['--no-force-upload', testing_workdir] call = mocker.patch.object(conda_build.build.subprocess, 'call') - reset_context(testing_workdir) + request.addfinalizer(_reset_config) + _reset_config([os.path.join(testing_workdir, '.condarc')]) main_build.execute(args) pkg = api.get_output_file_path(testing_metadata) assert call.called_once_with(['anaconda', 'upload', pkg]) @@ -691,6 +701,40 @@ def test_long_test_prefix(additional_args, is_long_test_prefix): assert config.long_test_prefix is is_long_test_prefix +@pytest.mark.serial +@pytest.mark.parametrize( + 'zstd_level_condarc, zstd_level_cli', + [ + (None, None), + (1, None), + (1, 2), + ], +) +def test_zstd_compression_level(testing_workdir, request, zstd_level_condarc, zstd_level_cli): + assert zstd_compression_level_default not in {zstd_level_condarc, zstd_level_cli} + if zstd_level_condarc: + with open(os.path.join(testing_workdir, '.condarc'), 'w') as f: + print( + 'conda_build:', + f' zstd_compression_level: {zstd_level_condarc}', + sep='\n', + file=f, + ) + request.addfinalizer(_reset_config) + _reset_config([os.path.join(testing_workdir, '.condarc')]) + args = ['non_existing_recipe'] + if zstd_level_cli: + args.append(f'--zstd-compression-level={zstd_level_cli}') + parser, args = main_build.parse_args(args) + config = Config(**args.__dict__) + if zstd_level_cli: + assert config.zstd_compression_level == zstd_level_cli + elif zstd_level_condarc: + assert config.zstd_compression_level == zstd_level_condarc + else: + assert config.zstd_compression_level == zstd_compression_level_default + + def test_user_warning(tmpdir, recwarn): dir_recipe_path = tmpdir.mkdir("recipe-path") recipe = dir_recipe_path.join("meta.yaml")