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

Remove sys.exit from develop.py #5453

Merged
merged 6 commits into from
Aug 12, 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
22 changes: 13 additions & 9 deletions conda_build/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import shutil
import sys
from os.path import abspath, exists, expanduser, isdir, join
from pathlib import Path
from typing import TYPE_CHECKING

from .exceptions import CondaBuildUserError
from .os_utils.external import find_executable
from .post import mk_relative_osx
from .utils import check_call_env, get_site_packages, on_mac, rec_glob

if TYPE_CHECKING:
from pathlib import Path


def relink_sharedobjects(pkg_path, build_prefix):
"""
Expand Down Expand Up @@ -56,13 +62,13 @@ def write_to_conda_pth(sp_dir, pkg_path):
print("added " + pkg_path)


def get_setup_py(path_):
"""Return full path to setup.py or exit if not found"""
def get_setup_py(path_: Path) -> Path:
"""Return full path to setup.py or raise error if not found"""
# build path points to source dir, builds are placed in the
setup_py = join(path_, "setup.py")

if not exists(setup_py):
sys.exit(f"No setup.py found in {path_}. Exiting.")
raise CondaBuildUserError(f"No setup.py found in {path_}.")

return setup_py

Expand Down Expand Up @@ -136,12 +142,10 @@ def execute(
uninstall: bool = False,
) -> None:
if not isdir(prefix):
sys.exit(
f"""\
Error: environment does not exist: {prefix}
#
# Use 'conda create' to create the environment first.
#"""
raise CondaBuildUserError(
f"Error: environment does not exist: {prefix}\n"
f"\n"
f"Use 'conda create' to create the environment first."
)

assert find_executable("python", prefix=prefix)
Expand Down
20 changes: 19 additions & 1 deletion tests/test_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import pytest

from conda_build.develop import _uninstall, write_to_conda_pth
from conda_build.develop import _uninstall, execute, get_setup_py, write_to_conda_pth
from conda_build.exceptions import CondaBuildUserError
from conda_build.utils import rm_rf

from .utils import thisdir
Expand Down Expand Up @@ -99,3 +100,20 @@ def test_uninstall(site_packages: Path, conda_pth: Path):
_uninstall(site_packages, path)

assert list(filter(None, conda_pth.read_text().split("\n"))) == develop_paths


def test_get_setup_py(tmp_path: Path):
setup_py_path = tmp_path / "setup.py"
setup_py_path.touch()
result = get_setup_py(str(tmp_path))
assert "setup.py" in result

with pytest.raises(CondaBuildUserError, match="No setup.py found in "):
get_setup_py("/path/to/non-existent")


def test_execute_error_nonexistent_prefix():
with pytest.raises(
CondaBuildUserError, match="Error: environment does not exist: "
):
execute("/path/to/non-existent/prefix", "python", "setup.py", "install")
Loading