Skip to content

Commit

Permalink
Remove return_outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Feb 6, 2024
1 parent c96f916 commit 33ce6b6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 57 deletions.
32 changes: 10 additions & 22 deletions conda_build/cli/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -555,14 +542,13 @@ def execute(
config.clean_pkgs()
return []

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]
Expand All @@ -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,
Expand All @@ -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
111 changes: 76 additions & 35 deletions tests/cli/test_main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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",
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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()


Expand Down Expand Up @@ -375,56 +390,82 @@ 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)


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)


Expand Down

0 comments on commit 33ce6b6

Please sign in to comment.