Skip to content

Commit

Permalink
build: do not generate setup.py by default
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
abn committed Apr 1, 2022
1 parent d6d33de commit 13e605c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
"generate-setup-file": {
"type": "boolean",
"description": "Generate and include a setup.py file in sdist.",
"default": true
"default": false
},
"script": {
"$ref": "#/definitions/build-script"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/packages/project_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def urls(self) -> dict[str, Any]:
return urls

def build_should_generate_setup(self) -> bool:
return self.build_config.get("generate-setup-file", True)
return self.build_config.get("generate-setup-file", False)
1 change: 1 addition & 0 deletions tests/masonry/builders/fixtures/extended/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ homepage = "https://python-poetry.org/"

[tool.poetry.build]
script = "build.py"
generate-setup-file = true
4 changes: 3 additions & 1 deletion tests/masonry/builders/fixtures/src_extended/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ readme = "README.rst"

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

build = "build.py"
[tool.poetry.build]
script = "build.py"
generate-setup-file = true
20 changes: 0 additions & 20 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import ast
import os
import platform
import re
Expand Down Expand Up @@ -536,28 +535,10 @@ def test_package_with_include(mocker: MockerFixture):
assert "with-include-1.2.3/package_with_include/__init__.py" in names
assert "with-include-1.2.3/tests/__init__.py" in names
assert "with-include-1.2.3/pyproject.toml" in names
assert "with-include-1.2.3/setup.py" in names
assert "with-include-1.2.3/PKG-INFO" in names
assert "with-include-1.2.3/for_wheel_only/__init__.py" not in names
assert "with-include-1.2.3/src/src_package/__init__.py" in names

setup = tar.extractfile("with-include-1.2.3/setup.py").read()
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert ns["package_dir"] == {"": "src"}
assert ns["packages"] == [
"extra_dir",
"extra_dir.sub_pkg",
"package_with_include",
"src_package",
"tests",
]
assert ns["package_data"] == {"": ["*"]}
assert ns["modules"] == ["my_module"]

whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl"

assert whl.exists()
Expand Down Expand Up @@ -606,7 +587,6 @@ def test_respect_format_for_explicit_included_files():
in names
)
assert "exclude-whl-include-sdist-0.1.0/pyproject.toml" in names
assert "exclude-whl-include-sdist-0.1.0/setup.py" in names
assert "exclude-whl-include-sdist-0.1.0/PKG-INFO" in names

whl = module_path / "dist" / "exclude_whl_include_sdist-0.1.0-py3-none-any.whl"
Expand Down
2 changes: 0 additions & 2 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def test_default_with_excluded_data(mocker: MockerFixture):
assert "my-package-1.2.3/my_package/__init__.py" in names
assert "my-package-1.2.3/my_package/data/data1.txt" in names
assert "my-package-1.2.3/pyproject.toml" in names
assert "my-package-1.2.3/setup.py" in names
assert "my-package-1.2.3/PKG-INFO" in names
# all last modified times should be set to a valid timestamp
for tarinfo in tar.getmembers():
Expand Down Expand Up @@ -492,7 +491,6 @@ def test_src_excluded_nested_data():
assert "my-package-1.2.3/LICENSE" in names
assert "my-package-1.2.3/README.rst" in names
assert "my-package-1.2.3/pyproject.toml" in names
assert "my-package-1.2.3/setup.py" in names
assert "my-package-1.2.3/PKG-INFO" in names
assert "my-package-1.2.3/my_package/__init__.py" in names
assert "my-package-1.2.3/my_package/data/sub_data/data2.txt" not in names
Expand Down

0 comments on commit 13e605c

Please sign in to comment.