diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index cba6fec6ff..73da5bdec6 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -15,7 +15,11 @@ from .. import api, build, source, utils from ..conda_interface import add_parser_channels, binstar_upload, cc_conda_build -from ..config import Config, get_channel_urls, zstd_compression_level_default +from ..config import ( + get_channel_urls, + get_or_merge_config, + zstd_compression_level_default, +) from ..deprecations import deprecated from ..utils import LoggingContext from .actions import KeyValueAction @@ -514,7 +518,7 @@ def check_action(recipe, config): def execute(args): _parser, args = parse_args(args) - config = Config(**args.__dict__) + config = get_or_merge_config(None, **args.__dict__) build.check_external() # change globals in build module, see comment there as well diff --git a/conda_build/config.py b/conda_build/config.py index e1bba06518..09f3cbcb67 100644 --- a/conda_build/config.py +++ b/conda_build/config.py @@ -913,8 +913,9 @@ def __exit__(self, e_type, e_value, traceback): self.clean(remove_folders=False) -def get_or_merge_config(config, variant=None, **kwargs): - """Always returns a new object - never changes the config that might be passed in.""" +def _get_or_merge_config(config, variant=None, **kwargs): + # This function should only ever be called via get_or_merge_config. + # It only exists for us to monkeypatch a default config when running tests. if not config: config = Config(variant=variant) else: @@ -928,6 +929,11 @@ def get_or_merge_config(config, variant=None, **kwargs): return config +def get_or_merge_config(config, variant=None, **kwargs): + """Always returns a new object - never changes the config that might be passed in.""" + return _get_or_merge_config(config, variant=variant, **kwargs) + + def get_channel_urls(args): channel_urls = args.get("channel") or args.get("channels") or () final_channel_urls = [] diff --git a/tests/cli/test_main_metapackage.py b/tests/cli/test_main_metapackage.py index 19312ae539..44ec145264 100644 --- a/tests/cli/test_main_metapackage.py +++ b/tests/cli/test_main_metapackage.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: BSD-3-Clause import json import os -import sys from glob import glob from conda_build.cli import main_metapackage @@ -15,8 +14,7 @@ def test_metapackage(testing_config, testing_workdir): main_metapackage.execute(args) test_path = glob( os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_config.host_subdir, "metapackage_test-1.0-0.tar.bz2", ) @@ -38,8 +36,7 @@ def test_metapackage_build_number(testing_config, testing_workdir): main_metapackage.execute(args) test_path = glob( os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_config.host_subdir, "metapackage_test_build_number-1.0-1.tar.bz2", ) @@ -61,8 +58,7 @@ def test_metapackage_build_string(testing_config, testing_workdir): main_metapackage.execute(args) test_path = glob( os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_config.host_subdir, "metapackage_test_build_string-1.0-frank*.tar.bz2", ) @@ -88,8 +84,7 @@ def test_metapackage_metadata(testing_config, testing_workdir): test_path = glob( os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_config.host_subdir, "metapackage_testing_metadata-1.0-0.tar.bz2", ) diff --git a/tests/cli/test_main_render.py b/tests/cli/test_main_render.py index 7f385118cc..10ed9f803e 100644 --- a/tests/cli/test_main_render.py +++ b/tests/cli/test_main_render.py @@ -66,13 +66,14 @@ def test_render_without_channel_fails(tmp_path): ), f"Expected to get only base package name because it should not be found, but got :{required_package_string}" -def test_render_output_build_path(testing_workdir, testing_metadata, capfd, caplog): +def test_render_output_build_path( + testing_workdir, testing_config, testing_metadata, capfd, caplog +): api.output_yaml(testing_metadata, "meta.yaml") args = ["--output", testing_workdir] main_render.execute(args) test_path = os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_metadata.config.host_subdir, "test_render_output_build_path-1.0-1.tar.bz2", ) @@ -82,15 +83,14 @@ def test_render_output_build_path(testing_workdir, testing_metadata, capfd, capl def test_render_output_build_path_and_file( - testing_workdir, testing_metadata, capfd, caplog + testing_workdir, testing_config, testing_metadata, capfd, caplog ): api.output_yaml(testing_metadata, "meta.yaml") rendered_filename = "out.yaml" args = ["--output", "--file", rendered_filename, testing_workdir] main_render.execute(args) test_path = os.path.join( - sys.prefix, - "conda-bld", + testing_config.croot, testing_metadata.config.host_subdir, "test_render_output_build_path_and_file-1.0-1.tar.bz2", ) diff --git a/tests/conftest.py b/tests/conftest.py index 3aca5b4bc7..9da98ee1d4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ import conda_build.config from conda_build.config import ( Config, + _get_or_merge_config, _src_cache_root_default, conda_pkg_format_default, enable_static_default, @@ -21,7 +22,6 @@ error_overlinking_default, exit_on_verify_error_default, filename_hashing_default, - get_or_merge_config, ignore_verify_codes_default, no_rewrite_stdout_env_default, noarch_python_build_age_default, @@ -81,13 +81,12 @@ def testing_config(testing_workdir): def boolify(v): return v == "true" - result = Config( + testing_config_kwargs = dict( croot=testing_workdir, anaconda_upload=False, verbose=True, activate=False, debug=False, - variant=None, test_run_post=False, # These bits ensure that default values are used instead of any # present in ~/.condarc @@ -102,6 +101,8 @@ def boolify(v): exit_on_verify_error=exit_on_verify_error_default, conda_pkg_format=conda_pkg_format_default, ) + result = Config(variant=None, **testing_config_kwargs) + result._testing_config_kwargs = testing_config_kwargs assert result.no_rewrite_stdout_env is False assert result._src_cache_root is None assert result.src_cache_root == testing_workdir @@ -121,11 +122,15 @@ def default_testing_config(testing_config, monkeypatch, request): return def get_or_merge_testing_config(config, variant=None, **kwargs): - return get_or_merge_config(config or testing_config, variant, **kwargs) + merged_kwargs = {} + if not config: + merged_kwargs.update(testing_config._testing_config_kwargs) + merged_kwargs.update(kwargs) + return _get_or_merge_config(config, variant, **merged_kwargs) monkeypatch.setattr( conda_build.config, - "get_or_merge_config", + "_get_or_merge_config", get_or_merge_testing_config, )