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

Fix spaces in scripts shebang #9802

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 6 additions & 18 deletions src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from installer.scripts import Script
from installer.utils import get_launcher_kind
from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.utils.package_include import PackageInclude
Expand All @@ -27,15 +29,6 @@
from poetry.poetry import Poetry
from poetry.utils.env import Env

SCRIPT_TEMPLATE = """\
#!{python}
import sys
from {module} import {callable_holder}

if __name__ == '__main__':
sys.exit({callable_}())
"""

WINDOWS_CMD_TEMPLATE = """\
@echo off\r\n"{python}" "%~dp0\\{script}" %*\r\n
"""
Expand Down Expand Up @@ -176,21 +169,16 @@ def _add_scripts(self) -> list[Path]:

raise ValueError(msg)

callable_holder = callable_.split(".", 1)[0]

script_file = scripts_path.joinpath(name)
self._debug(
f" - Adding the <c2>{name}</c2> script to <b>{scripts_path}</b>"
)
with script_file.open("w", encoding="utf-8") as f:
f.write(
decode(
SCRIPT_TEMPLATE.format(
python=self._env.python,
module=module,
callable_holder=callable_holder,
callable_=callable_,
)
str(
Script(name, module, callable_, "console")
.generate(str(self._env.python), get_launcher_kind())[1]
.decode()
)
)

Expand Down
53 changes: 47 additions & 6 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,38 +213,79 @@

baz_script = f"""\
#!{tmp_venv.python}
# -*- coding: utf-8 -*-
import re
import sys
from bar import baz

if __name__ == '__main__':
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")

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.10) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f1/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f1/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.10) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.11) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.11) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.12) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.12) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.13) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.13) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.9) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS aarch64 (Python 3.9) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/g6/rgtlsw6n123b0gt5483s5_cm0000gn/T/pytest-of-runner/pytest-0/popen-gw2/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.10) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.10) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.11) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f1/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f1/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.11) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.12) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.12) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f1/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw1/test_builder_installs_proper_f1/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.9) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.9) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw0/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.13) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project_legacy] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw3/test_builder_installs_proper_f0/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw3/test_builder_installs_proper_f0/venv/bin/python ? ^^ - ' ''' # -*- 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())

Check failure on line 225 in tests/masonry/builders/test_editable_builder.py

View workflow job for this annotation

GitHub Actions / macOS x86_64 (Python 3.13) / pytest

test_builder_installs_proper_files_for_standard_packages[simple_project] assert '#!/private/v...boom.bim())\n' == "#!/bin/sh\n'...boom.bim())\n" - #!/bin/sh - '''exec' /private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw3/test_builder_installs_proper_f2/venv/bin/python "$0" "$@" ? ^^^^^^^^^ ---------- + #!/private/var/folders/nj/wh528zms06j9t8y7bmlvpmjm0000gn/T/pytest-of-runner/pytest-0/popen-gw3/test_builder_installs_proper_f2/venv/bin/python ? ^^ - ' ''' # -*- 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())

foo_script = f"""\
#!{tmp_venv.python}
# -*- coding: utf-8 -*-
import re
import sys
from foo import bar

if __name__ == '__main__':
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\\.pyw|\\.exe)?$", "", sys.argv[0])
sys.exit(bar())
"""

assert foo_script == tmp_venv._bin_dir.joinpath("foo").read_text(encoding="utf-8")

fox_script = f"""\
#!{tmp_venv.python}
# -*- coding: utf-8 -*-
import re
import sys
from fuz.foo import bar

if __name__ == '__main__':
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\\.pyw|\\.exe)?$", "", sys.argv[0])
sys.exit(bar.baz())
"""

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
Loading