From fc150a58c492f29fdc2f3a4fbb56aa539046c6a6 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Tue, 6 Feb 2024 15:09:18 -0600 Subject: [PATCH] Remove return_outputs --- conda_build/cli/main_build.py | 36 ++++------- tests/cli/test_main_build.py | 111 +++++++++++++++++++++++----------- 2 files changed, 88 insertions(+), 59 deletions(-) diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py index 70bbd9c2ba..15463a11dc 100644 --- a/conda_build/cli/main_build.py +++ b/conda_build/cli/main_build.py @@ -11,7 +11,7 @@ from itertools import chain from os.path import abspath, expanduser, expandvars from pathlib import Path -from typing import Literal, Sequence, overload +from typing import Sequence from conda.auxlib.ish import dals from conda.common.io import dashlist @@ -522,20 +522,7 @@ def check_action(recipe, config): return api.check(recipe, config=config) -@overload -def execute(args: Sequence[str] | None, return_outputs: Literal[True]) -> list[str]: - ... - - -@overload -def execute(args: Sequence[str] | None, return_outputs: Literal[False]) -> int: - ... - - -def execute( - args: Sequence[str] | None = None, - return_outputs: bool = False, -) -> list[str] | int: +def execute(args: Sequence[str] | None = None) -> int: _, parsed = parse_args(args) config = get_or_merge_config(None, **parsed.__dict__) build.check_external() @@ -548,21 +535,20 @@ def execute( if "purge" in parsed.recipe: build.clean_build(config) - return [] + return 0 if "purge-all" in parsed.recipe: build.clean_build(config) config.clean_pkgs() - return [] + return 0 - outputs: list[str] = [] if parsed.output: config.verbose = False config.quiet = True config.debug = False - outputs = [output_action(recipe, config) for recipe in parsed.recipe] + for recipe in parsed.recipe: + output_action(recipe, config) elif parsed.test: - outputs = [] failed_recipes = [] recipes = chain.from_iterable( glob(abspath(recipe), recursive=True) if "*" in recipe else [recipe] @@ -584,11 +570,13 @@ def execute( else: print("All tests passed") elif parsed.source: - outputs = [source_action(recipe, config) for recipe in parsed.recipe] + for recipe in parsed.recipe: + source_action(recipe, config) elif parsed.check: - outputs = [check_action(recipe, config) for recipe in parsed.recipe] + for recipe in parsed.recipe: + check_action(recipe, config) else: - outputs = api.build( + api.build( parsed.recipe, post=parsed.post, test_run_post=parsed.test_run_post, @@ -604,4 +592,4 @@ def execute( if not parsed.output and len(utils.get_build_folders(config.croot)) > 0: build.print_build_intermediate_warning(config) - return outputs if return_outputs else 0 + return 0 diff --git a/tests/cli/test_main_build.py b/tests/cli/test_main_build.py index 2358ee0caa..04c2cda7ba 100644 --- a/tests/cli/test_main_build.py +++ b/tests/cli/test_main_build.py @@ -130,15 +130,23 @@ def test_build_output_build_path_multiple_recipes( assert output.rstrip().splitlines() == test_paths, error -def test_slash_in_recipe_arg_keeps_build_id(testing_workdir, testing_config): +def test_slash_in_recipe_arg_keeps_build_id( + testing_workdir: str, testing_config: Config +): args = [ os.path.join(metadata_dir, "has_prefix_files"), "--croot", testing_config.croot, "--no-anaconda-upload", ] - outputs = main_build.execute(args, return_outputs=True) - data = package_has_file(outputs[0], "binary-has-prefix", refresh_mode="forced") + main_build.execute(args) + + output = os.path.join( + testing_config.croot, + testing_config.host_subdir, + "conda-build-test-has-prefix-files-1.0-0.tar.bz2", + ) + data = package_has_file(output, "binary-has-prefix", refresh_mode="forced") assert data if hasattr(data, "decode"): data = data.decode("UTF-8") @@ -157,7 +165,7 @@ def test_build_long_test_prefix_default_enabled(mocker, testing_workdir): main_build.execute(args) -def test_build_no_build_id(testing_workdir, testing_config): +def test_build_no_build_id(testing_workdir: str, testing_config: Config): args = [ os.path.join(metadata_dir, "has_prefix_files"), "--no-build-id", @@ -166,8 +174,14 @@ def test_build_no_build_id(testing_workdir, testing_config): "--no-activate", "--no-anaconda-upload", ] - outputs = main_build.execute(args, return_outputs=True) - data = package_has_file(outputs[0], "binary-has-prefix", refresh_mode="forced") + main_build.execute(args) + + output = os.path.join( + testing_config.croot, + testing_config.host_subdir, + "conda-build-test-has-prefix-files-1.0-0.tar.bz2", + ) + data = package_has_file(output, "binary-has-prefix", refresh_mode="forced") assert data if hasattr(data, "decode"): data = data.decode("UTF-8") @@ -191,7 +205,7 @@ def test_build_multiple_recipes(testing_metadata, testing_workdir, testing_confi main_build.execute(args) -def test_build_output_folder(testing_workdir: str, testing_metadata): +def test_build_output_folder(testing_workdir: str, testing_metadata: MetaData): api.output_yaml(testing_metadata, "meta.yaml") out = Path(testing_workdir, "out") @@ -207,9 +221,10 @@ def test_build_output_folder(testing_workdir: str, testing_metadata): "--output-folder", str(out), ] - output = main_build.execute(args, return_outputs=True)[0] + main_build.execute(args) + assert ( - out / testing_metadata.config.host_subdir / os.path.basename(output) + out / testing_metadata.config.host_subdir / testing_metadata.pkg_fn() ).is_file() @@ -375,38 +390,53 @@ def test_activate_scripts_not_included(testing_workdir): assert not package_has_file(out, f) -def test_relative_path_croot(conda_build_test_recipe_envvar: str): +def test_relative_path_croot( + conda_build_test_recipe_envvar: str, testing_config: Config +): # this tries to build a package while specifying the croot with a relative path: # conda-build --no-test --croot ./relative/path + empty_sections = Path(metadata_dir, "empty_with_build_script") + croot = Path(".", "relative", "path") - empty_sections = os.path.join(metadata_dir, "empty_with_build_script") - croot_rel = os.path.join(".", "relative", "path") - args = ["--no-anaconda-upload", "--croot", croot_rel, empty_sections] - outputfile = main_build.execute(args, return_outputs=True) + args = ["--no-anaconda-upload", f"--croot={croot}", str(empty_sections)] + main_build.execute(args) - assert len(outputfile) == 1 - assert os.path.isfile(outputfile[0]) + assert len(list(croot.glob("**/*.tar.bz2"))) == 1 + assert ( + croot / testing_config.subdir / "empty_with_build_script-0.0-0.tar.bz2" + ).is_file() -def test_relative_path_test_artifact(conda_build_test_recipe_envvar: str): +def test_relative_path_test_artifact( + conda_build_test_recipe_envvar: str, testing_config: Config +): # this test builds a package into (cwd)/relative/path and then calls: # conda-build --test ./relative/path/{platform}/{artifact}.tar.bz2 - - empty_sections = os.path.join(metadata_dir, "empty_with_build_script") - croot_rel = os.path.join(".", "relative", "path") - croot_abs = os.path.abspath(os.path.normpath(croot_rel)) + empty_sections = Path(metadata_dir, "empty_with_build_script") + croot_rel = Path(".", "relative", "path") + croot_abs = croot_rel.resolve() # build the package - args = ["--no-anaconda-upload", "--no-test", "--croot", croot_abs, empty_sections] - output_file_abs = main_build.execute(args, return_outputs=True) - assert len(output_file_abs) == 1 + args = [ + "--no-anaconda-upload", + "--no-test", + f"--croot={croot_abs}", + str(empty_sections), + ] + main_build.execute(args) - output_file_rel = os.path.join( - croot_rel, os.path.relpath(output_file_abs[0], croot_abs) - ) + assert len(list(croot_abs.glob("**/*.tar.bz2"))) == 1 # run the test stage with relative path - args = ["--no-anaconda-upload", "--test", output_file_rel] + args = [ + "--no-anaconda-upload", + "--test", + os.path.join( + croot_rel, + testing_config.subdir, + "empty_with_build_script-0.0-0.tar.bz2", + ), + ] main_build.execute(args) @@ -414,17 +444,28 @@ def test_relative_path_test_recipe(conda_build_test_recipe_envvar: str): # this test builds a package into (cwd)/relative/path and then calls: # conda-build --test --croot ./relative/path/ /abs/path/to/recipe - empty_sections = os.path.join(metadata_dir, "empty_with_build_script") - croot_rel = os.path.join(".", "relative", "path") - croot_abs = os.path.abspath(os.path.normpath(croot_rel)) + empty_sections = Path(metadata_dir, "empty_with_build_script") + croot_rel = Path(".", "relative", "path") + croot_abs = croot_rel.resolve() # build the package - args = ["--no-anaconda-upload", "--no-test", "--croot", croot_abs, empty_sections] - output_file_abs = main_build.execute(args, return_outputs=True) - assert len(output_file_abs) == 1 + args = [ + "--no-anaconda-upload", + "--no-test", + f"--croot={croot_abs}", + str(empty_sections), + ] + main_build.execute(args) + + assert len(list(croot_abs.glob("**/*.tar.bz2"))) == 1 # run the test stage with relative croot - args = ["--no-anaconda-upload", "--test", "--croot", croot_rel, empty_sections] + args = [ + "--no-anaconda-upload", + "--test", + f"--croot={croot_rel}", + str(empty_sections), + ] main_build.execute(args)