Skip to content

Commit 14c5f7b

Browse files
abnSecrus
authored andcommitted
build: do not generate setup.py by default
This is the first step in removing setup file generation from Poetry projects. With this change, projects that require a setup.py to be generated when a build script is used needs to explicitly set `tool.poetry.build.generate-setup-file`, introduced in python-poetry#26, to `true` in `pyproject.toml`. Co-authored-by: Bartosz Sokorski <[email protected]>
1 parent 5a273c3 commit 14c5f7b

File tree

6 files changed

+6
-30
lines changed

6 files changed

+6
-30
lines changed

src/poetry/core/json/schemas/poetry-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@
634634
"generate-setup-file": {
635635
"type": "boolean",
636636
"description": "Generate and include a setup.py file in sdist.",
637-
"default": true
637+
"default": false
638638
},
639639
"script": {
640640
"$ref": "#/definitions/build-script"

src/poetry/core/packages/project_package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ def __hash__(self) -> int:
8787
return super(Package, self).__hash__()
8888

8989
def build_should_generate_setup(self) -> bool:
90-
return self.build_config.get("generate-setup-file", True)
90+
return self.build_config.get("generate-setup-file", False)

tests/masonry/builders/fixtures/extended/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ homepage = "https://python-poetry.org/"
1313

1414
[tool.poetry.build]
1515
script = "build.py"
16+
generate-setup-file = true

tests/masonry/builders/fixtures/src_extended/pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ readme = "README.rst"
1111

1212
homepage = "https://python-poetry.org/"
1313

14-
build = "build.py"
14+
[tool.poetry.build]
15+
script = "build.py"
16+
generate-setup-file = true

tests/masonry/builders/test_complete.py

-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import ast
43
import os
54
import platform
65
import re
@@ -12,7 +11,6 @@
1211

1312
from pathlib import Path
1413
from typing import TYPE_CHECKING
15-
from typing import Any
1614
from typing import Iterator
1715

1816
import pytest
@@ -540,30 +538,10 @@ def test_package_with_include(mocker: MockerFixture) -> None:
540538
assert "with_include-1.2.3/package_with_include/__init__.py" in names
541539
assert "with_include-1.2.3/tests/__init__.py" in names
542540
assert "with_include-1.2.3/pyproject.toml" in names
543-
assert "with_include-1.2.3/setup.py" in names
544541
assert "with_include-1.2.3/PKG-INFO" in names
545542
assert "with_include-1.2.3/for_wheel_only/__init__.py" not in names
546543
assert "with_include-1.2.3/src/src_package/__init__.py" in names
547544

548-
file = tar.extractfile("with_include-1.2.3/setup.py")
549-
assert file
550-
setup = file.read()
551-
setup_ast = ast.parse(setup)
552-
553-
setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
554-
ns: dict[str, Any] = {}
555-
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
556-
assert ns["package_dir"] == {"": "src"}
557-
assert ns["packages"] == [
558-
"extra_dir",
559-
"extra_dir.sub_pkg",
560-
"package_with_include",
561-
"src_package",
562-
"tests",
563-
]
564-
assert ns["package_data"] == {"": ["*"]}
565-
assert ns["modules"] == ["my_module"]
566-
567545
whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl"
568546

569547
assert whl.exists()
@@ -612,7 +590,6 @@ def test_respect_format_for_explicit_included_files() -> None:
612590
in names
613591
)
614592
assert "exclude_whl_include_sdist-0.1.0/pyproject.toml" in names
615-
assert "exclude_whl_include_sdist-0.1.0/setup.py" in names
616593
assert "exclude_whl_include_sdist-0.1.0/PKG-INFO" in names
617594

618595
whl = module_path / "dist" / "exclude_whl_include_sdist-0.1.0-py3-none-any.whl"
@@ -625,5 +602,3 @@ def test_respect_format_for_explicit_included_files() -> None:
625602
assert "exclude_whl_include_sdist/compiled/source.c" not in names
626603
assert "exclude_whl_include_sdist/compiled/source.h" not in names
627604
assert "exclude_whl_include_sdist/cython_code.pyx" not in names
628-
629-
pass

tests/masonry/builders/test_sdist.py

-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ def get_ignored_files(self, folder: Path | None = None) -> list[str]:
478478
assert "my_package-1.2.3/my_package/__init__.py" in names
479479
assert "my_package-1.2.3/my_package/data/data1.txt" in names
480480
assert "my_package-1.2.3/pyproject.toml" in names
481-
assert "my_package-1.2.3/setup.py" in names
482481
assert "my_package-1.2.3/PKG-INFO" in names
483482
# all last modified times should be set to a valid timestamp
484483
for tarinfo in tar.getmembers():
@@ -509,7 +508,6 @@ def test_src_excluded_nested_data() -> None:
509508
assert "my_package-1.2.3/LICENSE" in names
510509
assert "my_package-1.2.3/README.rst" in names
511510
assert "my_package-1.2.3/pyproject.toml" in names
512-
assert "my_package-1.2.3/setup.py" in names
513511
assert "my_package-1.2.3/PKG-INFO" in names
514512
assert "my_package-1.2.3/my_package/__init__.py" in names
515513
assert "my_package-1.2.3/my_package/data/sub_data/data2.txt" not in names

0 commit comments

Comments
 (0)