Skip to content

Commit

Permalink
Replace sys.exit in conda_build.build.bundle_conda (#5367)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard authored Jun 11, 2024
1 parent bf79003 commit 3515dbe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
15 changes: 9 additions & 6 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,13 +1753,16 @@ def bundle_conda(
output["script"],
args[0],
)
if "system32" in args[0] and "bash" in args[0]:
print(
"ERROR :: WSL bash.exe detected, this will not work (PRs welcome!). Please\n"
" use MSYS2 packages. Add `m2-base` and more (depending on what your"
" script needs) to `requirements/build` instead."
if (
# WSL bash is always the same path, it is an alias to the default
# distribution as configured by the user
on_win and Path("C:\\Windows\\System32\\bash.exe").samefile(args[0])
):
raise CondaBuildUserError(
"WSL bash.exe is not supported. Please use MSYS2 packages. Add "
"`m2-base` and more (depending on what your script needs) to "
"`requirements/build` instead."
)
sys.exit(1)
else:
args = interpreter.split(" ")

Expand Down
24 changes: 24 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
from typing import TYPE_CHECKING

import pytest
from conda.common.compat import on_win

from conda_build import api, build
from conda_build.exceptions import CondaBuildUserError

from .utils import get_noarch_python_meta, metadata_dir

if TYPE_CHECKING:
from pytest_mock import MockerFixture

from conda_build.metadata import MetaData


Expand Down Expand Up @@ -345,3 +348,24 @@ def test_copy_readme(testing_metadata: MetaData, readme: str):
Path(testing_metadata.config.work_dir, readme).touch()
build.copy_readme(testing_metadata)
assert Path(testing_metadata.config.info_dir, readme).exists()


@pytest.mark.skipif(not on_win, reason="WSL is only on Windows")
def test_wsl_unsupported(
testing_metadata: MetaData,
mocker: MockerFixture,
tmp_path: Path,
):
mocker.patch(
"conda_build.os_utils.external.find_executable",
return_value="C:\\Windows\\System32\\bash.exe",
)

(script := tmp_path / "install.sh").touch()
with pytest.raises(CondaBuildUserError):
build.bundle_conda(
output={"script": script},
metadata=testing_metadata,
env={},
stats={},
)

0 comments on commit 3515dbe

Please sign in to comment.