Skip to content

Commit 13e605c

Browse files
committed
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 #26, to `true` in `pyproject.toml`.
1 parent d6d33de commit 13e605c

File tree

6 files changed

+6
-25
lines changed

6 files changed

+6
-25
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@
666666
"generate-setup-file": {
667667
"type": "boolean",
668668
"description": "Generate and include a setup.py file in sdist.",
669-
"default": true
669+
"default": false
670670
},
671671
"script": {
672672
"$ref": "#/definitions/build-script"

src/poetry/core/packages/project_package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ def urls(self) -> dict[str, Any]:
7272
return urls
7373

7474
def build_should_generate_setup(self) -> bool:
75-
return self.build_config.get("generate-setup-file", True)
75+
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

-20
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
@@ -536,28 +535,10 @@ def test_package_with_include(mocker: MockerFixture):
536535
assert "with-include-1.2.3/package_with_include/__init__.py" in names
537536
assert "with-include-1.2.3/tests/__init__.py" in names
538537
assert "with-include-1.2.3/pyproject.toml" in names
539-
assert "with-include-1.2.3/setup.py" in names
540538
assert "with-include-1.2.3/PKG-INFO" in names
541539
assert "with-include-1.2.3/for_wheel_only/__init__.py" not in names
542540
assert "with-include-1.2.3/src/src_package/__init__.py" in names
543541

544-
setup = tar.extractfile("with-include-1.2.3/setup.py").read()
545-
setup_ast = ast.parse(setup)
546-
547-
setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
548-
ns = {}
549-
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
550-
assert ns["package_dir"] == {"": "src"}
551-
assert ns["packages"] == [
552-
"extra_dir",
553-
"extra_dir.sub_pkg",
554-
"package_with_include",
555-
"src_package",
556-
"tests",
557-
]
558-
assert ns["package_data"] == {"": ["*"]}
559-
assert ns["modules"] == ["my_module"]
560-
561542
whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl"
562543

563544
assert whl.exists()
@@ -606,7 +587,6 @@ def test_respect_format_for_explicit_included_files():
606587
in names
607588
)
608589
assert "exclude-whl-include-sdist-0.1.0/pyproject.toml" in names
609-
assert "exclude-whl-include-sdist-0.1.0/setup.py" in names
610590
assert "exclude-whl-include-sdist-0.1.0/PKG-INFO" in names
611591

612592
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
@@ -461,7 +461,6 @@ def test_default_with_excluded_data(mocker: MockerFixture):
461461
assert "my-package-1.2.3/my_package/__init__.py" in names
462462
assert "my-package-1.2.3/my_package/data/data1.txt" in names
463463
assert "my-package-1.2.3/pyproject.toml" in names
464-
assert "my-package-1.2.3/setup.py" in names
465464
assert "my-package-1.2.3/PKG-INFO" in names
466465
# all last modified times should be set to a valid timestamp
467466
for tarinfo in tar.getmembers():
@@ -492,7 +491,6 @@ def test_src_excluded_nested_data():
492491
assert "my-package-1.2.3/LICENSE" in names
493492
assert "my-package-1.2.3/README.rst" in names
494493
assert "my-package-1.2.3/pyproject.toml" in names
495-
assert "my-package-1.2.3/setup.py" in names
496494
assert "my-package-1.2.3/PKG-INFO" in names
497495
assert "my-package-1.2.3/my_package/__init__.py" in names
498496
assert "my-package-1.2.3/my_package/data/sub_data/data2.txt" not in names

0 commit comments

Comments
 (0)