From 14c5f7ba55319e2045156c137c8de52f29cdf090 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 1 Apr 2022 23:02:26 +0200 Subject: [PATCH] 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`. Co-authored-by: Bartosz Sokorski --- .../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 a3a09738c..d952faf93 100644 --- a/src/poetry/core/json/schemas/poetry-schema.json +++ b/src/poetry/core/json/schemas/poetry-schema.json @@ -634,7 +634,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 09f545c92..db822e549 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -478,7 +478,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(): @@ -509,7 +508,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