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

Replace sys.exit in conda_build.build.handle_anaconda_upload #5369

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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)