Skip to content

Commit

Permalink
conda-build CLI overrode condarc's zstd_compression_level with the de…
Browse files Browse the repository at this point in the history
…fault value (#4650)

Fix #4649.
  • Loading branch information
mbargull authored Nov 29, 2022
1 parent add8303 commit 05dc55a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions conda_build/cli/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions news/gh-4650-fix-cli-zstd-level-override-gh-4649.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

* fix: `conda-build` CLI overrode `condarc`'s `zstd_compression_level` with the default value
52 changes: 48 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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')
Expand All @@ -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])
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 05dc55a

Please sign in to comment.