Skip to content

Commit

Permalink
Replace sys.exit in conda_build.build.handle_anaconda_upload (#5369)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeankha authored Jun 17, 2024
1 parent 45be77d commit 7328626
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,10 @@ def build_tree(
return list(built_packages.keys())


def handle_anaconda_upload(paths, config):
def handle_anaconda_upload(
paths: Iterable[str | os.PathLike | Path],
config: Config,
) -> None:
from .os_utils.external import find_executable

paths = utils.ensure_list(paths)
Expand Down Expand Up @@ -4011,15 +4014,15 @@ def handle_anaconda_upload(paths, config):
"# To have conda build upload to anaconda.org automatically, use\n"
f"# {prompter}conda config --set anaconda_upload yes\n"
)
no_upload_message += f"anaconda upload{joiner}" + joiner.join(paths)
no_upload_message += f"anaconda upload{joiner}" + joiner.join(map(str, paths))

if not upload:
print(no_upload_message)
return

if not anaconda:
print(no_upload_message)
sys.exit(
raise CondaBuildUserError(
"Error: cannot locate anaconda command (required for upload)\n"
"# Try:\n"
f"# {prompter}conda install anaconda-client"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
if TYPE_CHECKING:
from pytest_mock import MockerFixture

from conda_build.config import Config
from conda_build.metadata import MetaData


Expand Down Expand Up @@ -369,3 +370,14 @@ def test_wsl_unsupported(
env={},
stats={},
)


def test_handle_anaconda_upload(testing_config: Config, mocker: MockerFixture):
mocker.patch(
"conda_build.os_utils.external.find_executable",
return_value=None,
)
testing_config.anaconda_upload = True

with pytest.raises(CondaBuildUserError):
build.handle_anaconda_upload((), testing_config)

0 comments on commit 7328626

Please sign in to comment.