Skip to content

Commit d919556

Browse files
abnfinswimmer
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`.
1 parent 269f940 commit d919556

File tree

6 files changed

+6
-27
lines changed

6 files changed

+6
-27
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

-22
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
@@ -540,30 +539,10 @@ def test_package_with_include(mocker: MockerFixture) -> None:
540539
assert "with-include-1.2.3/package_with_include/__init__.py" in names
541540
assert "with-include-1.2.3/tests/__init__.py" in names
542541
assert "with-include-1.2.3/pyproject.toml" in names
543-
assert "with-include-1.2.3/setup.py" in names
544542
assert "with-include-1.2.3/PKG-INFO" in names
545543
assert "with-include-1.2.3/for_wheel_only/__init__.py" not in names
546544
assert "with-include-1.2.3/src/src_package/__init__.py" in names
547545

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-
567546
whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl"
568547

569548
assert whl.exists()
@@ -612,7 +591,6 @@ def test_respect_format_for_explicit_included_files() -> None:
612591
in names
613592
)
614593
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
616594
assert "exclude-whl-include-sdist-0.1.0/PKG-INFO" in names
617595

618596
whl = module_path / "dist" / "exclude_whl_include_sdist-0.1.0-py3-none-any.whl"

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)