Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nonzero exit for conda-build entrypoint #5169

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions conda_build/cli/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def check_action(recipe, config):
return api.check(recipe, config=config)


def execute(args: Sequence[str] | None = None):
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 @@ -535,21 +535,20 @@ def execute(args: Sequence[str] | None = None):

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 = None
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:
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
outputs = []
failed_recipes = []
recipes = chain.from_iterable(
glob(abspath(recipe), recursive=True) if "*" in recipe else [recipe]
Expand All @@ -571,11 +570,13 @@ def execute(args: Sequence[str] | None = None):
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 @@ -590,4 +591,5 @@ def execute(args: Sequence[str] | None = None):

if not parsed.output and len(utils.get_build_folders(config.croot)) > 0:
build.print_build_intermediate_warning(config)
return outputs

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
_, parsed = parse_args(args)
files = parsed.files
del parsed.__dict__["files"]

for f in files:
f = abspath(expanduser(f))
api.convert(f, **parsed.__dict__)

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_parser() -> ArgumentParser:
return p


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
parser = get_parser()
parsed = parser.parse_args(args)

Expand Down Expand Up @@ -118,3 +118,5 @@ def execute(args: Sequence[str] | None = None):
f"Error: conda-debug encountered the following error:\n{e}", file=sys.stderr
)
sys.exit(1)

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
_, parsed = parse_args(args)
prefix = determine_target_prefix(context, parsed)
api.develop(
Expand All @@ -87,3 +87,5 @@ def execute(args: Sequence[str] | None = None):
clean=parsed.clean,
uninstall=parsed.uninstall,
)

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
parser, parsed = parse_args(args)

if not parsed.subcommand:
Expand Down Expand Up @@ -221,3 +221,5 @@ def execute(args: Sequence[str] | None = None):
pprint(api.inspect_hash_inputs(parsed.packages))
else:
parser.error(f"Unrecognized subcommand: {parsed.subcommand}.")

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_metapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
_, args = parse_args(args)
channel_urls = args.__dict__.get("channel") or args.__dict__.get("channels") or ()
api.create_metapackage(channel_urls=channel_urls, **args.__dict__)

return 0
43 changes: 22 additions & 21 deletions conda_build/cli/main_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .. import __version__, api
from ..conda_interface import ArgumentParser, add_parser_channels, cc_conda_build
from ..config import get_channel_urls, get_or_merge_config
from ..deprecations import deprecated
from ..utils import LoggingContext
from ..variants import get_package_variants, set_language_env_vars

Expand Down Expand Up @@ -189,7 +190,8 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None, print_results: bool = True):
@deprecated.argument("24.1.1", "24.3.0", "print_results")
def execute(args: Sequence[str] | None = None) -> int:
_, parsed = parse_args(args)

config = get_or_merge_config(None, **parsed.__dict__)
Expand Down Expand Up @@ -221,24 +223,23 @@ def execute(args: Sequence[str] | None = None, print_results: bool = True):
f"Only one will be written to the file you specified ({parsed.file})."
)

if print_results:
if parsed.output:
with LoggingContext(logging.CRITICAL + 1):
paths = api.get_output_file_paths(metadata_tuples, config=config)
print("\n".join(sorted(paths)))
if parsed.file:
m = metadata_tuples[-1][0]
api.output_yaml(m, parsed.file, suppress_outputs=True)
else:
logging.basicConfig(level=logging.INFO)
for m, _, _ in metadata_tuples:
print("--------------")
print("Hash contents:")
print("--------------")
pprint(m.get_hash_contents())
print("----------")
print("meta.yaml:")
print("----------")
print(api.output_yaml(m, parsed.file, suppress_outputs=True))
if parsed.output:
with LoggingContext(logging.CRITICAL + 1):
paths = api.get_output_file_paths(metadata_tuples, config=config)
print("\n".join(sorted(paths)))
if parsed.file:
m = metadata_tuples[-1][0]
api.output_yaml(m, parsed.file, suppress_outputs=True)
else:
return metadata_tuples
logging.basicConfig(level=logging.INFO)
for m, _, _ in metadata_tuples:
print("--------------")
print("Hash contents:")
print("--------------")
pprint(m.get_hash_contents())
print("----------")
print("meta.yaml:")
print("----------")
print(api.output_yaml(m, parsed.file, suppress_outputs=True))

return 0
4 changes: 3 additions & 1 deletion conda_build/cli/main_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_args(args: Sequence[str] | None) -> tuple[ArgumentParser, Namespace]:
return parser, parser.parse_args(args)


def execute(args: Sequence[str] | None = None):
def execute(args: Sequence[str] | None = None) -> int:
parser, parsed = parse_args(args)
config = Config(**parsed.__dict__)

Expand All @@ -62,3 +62,5 @@ def execute(args: Sequence[str] | None = None):
version=parsed.version,
config=config,
)

return 0
36 changes: 20 additions & 16 deletions conda_build/plugin.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

from typing import Sequence

import conda.plugins


# lazy-import to avoid nasty import-time side effects when not using conda-build
def build(*args, **kwargs):
def build(args: Sequence[str]) -> int:
from .cli.main_build import execute

execute(*args, **kwargs)
return execute(args)


def convert(*args, **kwargs):
def convert(args: Sequence[str]) -> int:
from .cli.main_convert import execute

execute(*args, **kwargs)
return execute(args)


def debug(*args, **kwargs):
def debug(args: Sequence[str]) -> int:
from .cli.main_debug import execute

execute(*args, **kwargs)
return execute(args)


def develop(*args, **kwargs):
def develop(args: Sequence[str]) -> int:
from .cli.main_develop import execute

execute(*args, **kwargs)
return execute(args)


def inspect(*args, **kwargs):
def inspect(args: Sequence[str]) -> int:
from .cli.main_inspect import execute

execute(*args, **kwargs)
return execute(args)


def metapackage(*args, **kwargs):
def metapackage(args: Sequence[str]) -> int:
from .cli.main_metapackage import execute

execute(*args, **kwargs)
return execute(args)


def render(*args, **kwargs):
def render(args: Sequence[str]) -> int:
from .cli.main_render import execute

execute(*args, **kwargs)
return execute(args)


def skeleton(*args, **kwargs):
def skeleton(args: Sequence[str]) -> int:
from .cli.main_skeleton import execute

execute(*args, **kwargs)
return execute(args)


@conda.plugins.hookimpl
Expand Down
19 changes: 19 additions & 0 deletions news/5169-fix-nonzero-exitcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix nonzero exitcode on success. (#5167 via #5169)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Loading
Loading