From 4f7d44a2dfc2527a22b5c3f69e867e5f2e6e1908 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sat, 21 Jan 2023 15:06:54 +0100 Subject: [PATCH] build: do not generate setup.py by default (#318) Co-authored-by: finswimmer --- .../core/json/schemas/poetry-schema.json | 2 +- src/poetry/core/packages/project_package.py | 2 +- .../builders/fixtures/extended/pyproject.toml | 1 + .../fixtures/src_extended/pyproject.toml | 4 ++- tests/masonry/builders/test_complete.py | 25 ------------------- tests/masonry/builders/test_sdist.py | 2 -- 6 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/poetry/core/json/schemas/poetry-schema.json b/src/poetry/core/json/schemas/poetry-schema.json index 9b39a1047..a7fc59eee 100644 --- a/src/poetry/core/json/schemas/poetry-schema.json +++ b/src/poetry/core/json/schemas/poetry-schema.json @@ -635,7 +635,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" diff --git a/src/poetry/core/packages/project_package.py b/src/poetry/core/packages/project_package.py index 3af4eb16e..c993fc991 100644 --- a/src/poetry/core/packages/project_package.py +++ b/src/poetry/core/packages/project_package.py @@ -87,4 +87,4 @@ def __hash__(self) -> int: return super(Package, self).__hash__() 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) diff --git a/tests/masonry/builders/fixtures/extended/pyproject.toml b/tests/masonry/builders/fixtures/extended/pyproject.toml index 6266092b7..9b3330713 100644 --- a/tests/masonry/builders/fixtures/extended/pyproject.toml +++ b/tests/masonry/builders/fixtures/extended/pyproject.toml @@ -13,3 +13,4 @@ homepage = "https://python-poetry.org/" [tool.poetry.build] script = "build.py" +generate-setup-file = true diff --git a/tests/masonry/builders/fixtures/src_extended/pyproject.toml b/tests/masonry/builders/fixtures/src_extended/pyproject.toml index f8e8bd810..9b3330713 100644 --- a/tests/masonry/builders/fixtures/src_extended/pyproject.toml +++ b/tests/masonry/builders/fixtures/src_extended/pyproject.toml @@ -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 diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 9e4b27abc..7a5aebdea 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -1,6 +1,5 @@ from __future__ import annotations -import ast import os import platform import re @@ -12,7 +11,6 @@ from pathlib import Path from typing import TYPE_CHECKING -from typing import Any from typing import Iterator import pytest @@ -540,30 +538,10 @@ def test_package_with_include(mocker: MockerFixture) -> None: 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 - file = tar.extractfile("with_include-1.2.3/setup.py") - assert file - setup = file.read() - setup_ast = ast.parse(setup) - - setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)] - ns: dict[str, Any] = {} - 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() @@ -612,7 +590,6 @@ def test_respect_format_for_explicit_included_files() -> None: 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" @@ -625,5 +602,3 @@ def test_respect_format_for_explicit_included_files() -> None: assert "exclude_whl_include_sdist/compiled/source.c" not in names assert "exclude_whl_include_sdist/compiled/source.h" not in names assert "exclude_whl_include_sdist/cython_code.pyx" not in names - - pass diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index a308cac7e..644ae5efe 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -492,7 +492,6 @@ def get_ignored_files(self, folder: Path | None = None) -> list[str]: 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(): @@ -523,7 +522,6 @@ def test_src_excluded_nested_data() -> None: 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