Skip to content

Commit

Permalink
Fix spaces in scripts shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Oct 27, 2024
1 parent 140e388 commit 140132d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,41 @@ def test_builder_installs_proper_files_for_standard_packages(
assert fox_script == tmp_venv._bin_dir.joinpath("fox").read_text(encoding="utf-8")


def test_builder_generates_scripts_with_escaped_shebang_when_spaces_in_path(
simple_poetry: Poetry,
tmp_path: Path,
fixture_dir: FixtureDirGetter,
) -> None:
simple_poetry = Factory().create_poetry(fixture_dir("simple_project"))
env_manager = EnvManager(simple_poetry)
venv_path = tmp_path / "path with space" / "venv"
env_manager.build_venv(venv_path)
tmp_venv = VirtualEnv(venv_path)

builder = EditableBuilder(simple_poetry, tmp_venv, NullIO())

builder.build()

assert tmp_venv._bin_dir.joinpath("baz").exists()

expected_shebang = f"""/bin/sh
'''exec' '{tmp_path}/path with space/venv/bin/python' "$0" "$@"
' '''"""

baz_script = f"""\
#!{expected_shebang}
# -*- coding: utf-8 -*-
import re
import sys
from bar import baz
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\\.pyw|\\.exe)?$", "", sys.argv[0])
sys.exit(baz.boom.bim())
"""

assert baz_script == tmp_venv._bin_dir.joinpath("baz").read_text(encoding="utf-8")


def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
mocker: MockerFixture, extended_poetry: Poetry, tmp_path: Path
) -> None:
Expand Down

0 comments on commit 140132d

Please sign in to comment.