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 3 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
23 changes: 14 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,11 @@ 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
Use 'conda create' to create the environment first.
"""
beeankha marked this conversation as resolved.
Show resolved Hide resolved
)

assert find_executable("python", prefix=prefix)
Expand Down
24 changes: 23 additions & 1 deletion tests/test_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
Simple tests for testing functions in develop module - lower level than going through API.
"""

from os.path import join
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Generator

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 +102,22 @@ 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(conda_pth: Path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conda_pth fixture you use here does not appear to be used since it's overwritten on line 109?

with TemporaryDirectory() as tmpdir:
conda_pth = Path(tmpdir)
setup_py_path = join(conda_pth, "setup.py")
open(setup_py_path, "x").close()
result = get_setup_py(str(conda_pth))
assert "setup.py" in result
beeankha marked this conversation as resolved.
Show resolved Hide resolved

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