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

convert_script_files does not require script to exist #710

Merged
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
19 changes: 10 additions & 9 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,16 @@ def convert_script_files(self) -> list[Path]:

abs_path = Path.joinpath(self._path, source)

if not abs_path.exists():
raise RuntimeError(
f"{abs_path} in script specification ({name}) is not found."
)

if not abs_path.is_file():
raise RuntimeError(
f"{abs_path} in script specification ({name}) is not a file."
)
if not self._package.build_script:
# scripts can be generated by build_script, in this case they do not exist here
if not abs_path.exists():
raise RuntimeError(
f"{abs_path} in script specification ({name}) is not found."
)
if not abs_path.is_file():
raise RuntimeError(
f"{abs_path} in script specification ({name}) is not a file."
)

script_files.append(abs_path)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Module 1
========
14 changes: 14 additions & 0 deletions tests/masonry/builders/fixtures/generated_script_file/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path
from setuptools.command.build_py import build_py


class BuildPyCommand(build_py):
def run(self):
with open("generated_script_file/generated/script.sh", "w", encoding="utf-8") as f:
f.write('#!/usr/bin/env bash\n\necho "Hello World!"\n')
ret = super().run()
return ret


def build(setup_kwargs):
setup_kwargs["cmdclass"] = {"build_py": BuildPyCommand}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "generated_script_file"
version = "0.1"
description = "Some description."
authors = [
"Poetry Maintainers <noreply@python-poetry.org>"
]
license = "MIT"
readme = "README.rst"

[tool.poetry.scripts]
sh-script = { reference = "generated_script_file/generated/script.sh", type = "file" }

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[build-system]
requires = ["poetry-core", "setuptools"]
build-backend = "poetry.core.masonry.api"
17 changes: 17 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,20 @@ def test_build_py_only_included() -> None:

with zipfile.ZipFile(str(whl)) as z:
assert "build_with_build_py_only/generated/file.py" in z.namelist()


def test_generated_script_file(tmp_path: Path) -> None:
"""Tests that a file that is generated by build.py can be used as script."""
root = fixtures_dir / "generated_script_file"
radoering marked this conversation as resolved.
Show resolved Hide resolved
# test only works on a fresh root without already generated script file:
tmp_root = tmp_path / "generated_script_file"
shutil.copytree(root, tmp_root)

WheelBuilder.make(Factory().create_poetry(tmp_root))

whl = next((tmp_root / "dist").glob("generated_script_file-0.1-*.whl"))

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
assert "generated_script_file-0.1.data/scripts/script.sh" in z.namelist()