From 2b2fd5b29992312ef356adab352c20db8d7ff13d Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 10 Nov 2023 17:21:11 +0100 Subject: [PATCH 1/7] Fix testing config monkeypatch for concurrent test flakiness The default_testing_config monkeypatching fixture was added in gh-4653 but did not consider "from .config import get_or_merge_config" cases in which get_or_merge_config is already bound and thus not patched. Signed-off-by: Marcel Bargull --- conda_build/config.py | 8 ++++++-- tests/conftest.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/conda_build/config.py b/conda_build/config.py index e1bba06518..2f29d63201 100644 --- a/conda_build/config.py +++ b/conda_build/config.py @@ -913,8 +913,7 @@ 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): if not config: config = Config(variant=variant) else: @@ -928,6 +927,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/conftest.py b/tests/conftest.py index 3aca5b4bc7..945277f4c1 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, @@ -121,11 +121,11 @@ 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) + return _get_or_merge_config(config or testing_config, variant, **kwargs) monkeypatch.setattr( conda_build.config, - "get_or_merge_config", + "_get_or_merge_config", get_or_merge_testing_config, ) From c6c0f67addabfdc8b105948800d83fe88a54d100 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 10 Nov 2023 17:50:48 +0100 Subject: [PATCH 2/7] main_build: Construct config via get_or_merge_config Helps tests with default_testing_config monkeypatch. Signed-off-by: Marcel Bargull --- conda_build/cli/main_build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index cba6fec6ff..267de15b09 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -15,7 +15,7 @@ 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 +514,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 From 82e50655c815fefa4692afb51962ee69f425282d Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 10 Nov 2023 18:28:36 +0100 Subject: [PATCH 3/7] Tests: Don't preset values for get_or_merge_config Otherwise default values set for testing_config before, e.g., environment variable-dependent config can be set in the tests. Example: tests/cli/test_main_build.py::test_conda_py_no_period failed since it sets CONDA_PY=36 but testing_config already had set it before. Signed-off-by: Marcel Bargull --- tests/conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 945277f4c1..df4ec8e79e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -81,7 +81,7 @@ 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, @@ -102,6 +102,8 @@ def boolify(v): exit_on_verify_error=exit_on_verify_error_default, conda_pkg_format=conda_pkg_format_default, ) + result = Config(**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,7 +123,11 @@ 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, From c435b10ef44e756c36b3605801d7430c58084460 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 10 Nov 2023 18:50:01 +0100 Subject: [PATCH 4/7] Tests: Don't test for semi-hard-coded paths Signed-off-by: Marcel Bargull --- tests/cli/test_main_metapackage.py | 12 ++++-------- tests/cli/test_main_render.py | 10 ++++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/cli/test_main_metapackage.py b/tests/cli/test_main_metapackage.py index 19312ae539..b11b4560eb 100644 --- a/tests/cli/test_main_metapackage.py +++ b/tests/cli/test_main_metapackage.py @@ -15,8 +15,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 +37,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 +59,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 +85,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..9c423d1b43 100644 --- a/tests/cli/test_main_render.py +++ b/tests/cli/test_main_render.py @@ -66,13 +66,12 @@ 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 +81,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", ) From 3c7330962ca1ee0687065361b5f996a4a9e8c753 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 10 Nov 2023 20:10:19 +0100 Subject: [PATCH 5/7] Tests: Fix duplicate variant kwarg Signed-off-by: Marcel Bargull --- tests/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index df4ec8e79e..9da98ee1d4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -87,7 +87,6 @@ def boolify(v): 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,7 +101,7 @@ def boolify(v): exit_on_verify_error=exit_on_verify_error_default, conda_pkg_format=conda_pkg_format_default, ) - result = Config(**testing_config_kwargs) + 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 From adabc082dce45308e9a39eacb469608041a737c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:01:38 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conda_build/cli/main_build.py | 6 +++++- tests/cli/test_main_metapackage.py | 1 - tests/cli/test_main_render.py | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index 267de15b09..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 get_channel_urls, get_or_merge_config, 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 diff --git a/tests/cli/test_main_metapackage.py b/tests/cli/test_main_metapackage.py index b11b4560eb..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 diff --git a/tests/cli/test_main_render.py b/tests/cli/test_main_render.py index 9c423d1b43..10ed9f803e 100644 --- a/tests/cli/test_main_render.py +++ b/tests/cli/test_main_render.py @@ -66,7 +66,9 @@ 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_config, 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) From d7e6aec5fad440e891d2deb6b88459fd098e48ad Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 17 Nov 2023 13:17:14 +0100 Subject: [PATCH 7/7] Add comment about _get_or_merge_config's purpose Signed-off-by: Marcel Bargull --- conda_build/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conda_build/config.py b/conda_build/config.py index 2f29d63201..09f3cbcb67 100644 --- a/conda_build/config.py +++ b/conda_build/config.py @@ -914,6 +914,8 @@ def __exit__(self, e_type, e_value, traceback): 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: