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

Capture any scripts generated by setup/build and include in wheel #531

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test for scripts generated in build.py
  • Loading branch information
robtaylor committed Nov 28, 2022
commit 182f66db4556d332e7ba6fcd7dd108c7988339ab
21 changes: 21 additions & 0 deletions tests/masonry/builders/fixtures/script_generated/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path
from setuptools.command.build_py import build_py


class BuildPyCommand(build_py):
def run(self):
with open('script_generated/generated/file.py', 'w') as out:
print("#!/bin/env python3\nprint('Success!')\n", file=out)
return super().run()


def build(setup_kwargs):
setup_kwargs.update(
{
"cmdclass": {
"build_py": BuildPyCommand,
},
"scripts": ["script_generated/generated/file.py"]
}

)
16 changes: 16 additions & 0 deletions tests/masonry/builders/fixtures/script_generated/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "script_generated"
version = "0.1"
description = ""
authors = ["Evgenii Gorchakov <[email protected]>", "Rob Taylor <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.8"

[build-system]
requires = ["poetry-core", "setuptools"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.build]
generate-setup-file = true
script = "build.py"
22 changes: 22 additions & 0 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ def test_build_wheel_extended() -> None:
assert whl.exists()
validate_wheel_contents(name="extended", version="0.1", path=whl.as_posix())


@pytest.mark.skipif(
sys.platform == "win32"
and sys.version_info <= (3, 6)
or platform.python_implementation().lower() == "pypy",
reason="Disable test on Windows for Python <=3.6 and for PyPy",
)
def test_build_wheel_script_generated() -> None:
with temporary_directory() as tmp_dir, cwd(
os.path.join(fixtures, "script_generated")
):
filename = api.build_wheel(tmp_dir)
whl = Path(tmp_dir) / filename
assert whl.exists()
validate_wheel_contents(
name="script_generated",
version="0.1",
path=whl.as_posix(),
data_files=["scripts/file.py"],
)


def test_build_sdist() -> None:
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
filename = api.build_sdist(tmp_dir)
Expand Down
10 changes: 9 additions & 1 deletion tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,24 @@ def subprocess_run(*args: str, **kwargs: Any) -> subprocess.CompletedProcess[str


def validate_wheel_contents(
name: str, version: str, path: str, files: list[str] | None = None
name: str,
version: str,
path: str,
files: list[str] | None = None,
data_files: list[str] | None = None,
) -> None:
dist_info = f"{name}-{version}.dist-info"
dist_data = f"{name}-{version}.data"
files = files or []
data_files = data_files or []

with zipfile.ZipFile(path) as z:
namelist = z.namelist()
# we use concatenation here for PY2 compat
for filename in ["WHEEL", "METADATA", "RECORD"] + files:
assert f"{dist_info}/{filename}" in namelist
for filename in data_files:
assert f"{dist_data}/{filename}" in namelist


def validate_sdist_contents(
Expand Down