Skip to content

Commit

Permalink
build: do not generate setup.py by default (#318)
Browse files Browse the repository at this point in the history
Co-authored-by: finswimmer <finswimmer77@gmail.com>
  • Loading branch information
abn and finswimmer authored Jan 21, 2023
1 parent 128c2cf commit 4f7d44a
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 30 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 @@ -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"
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 @@ -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)
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
25 changes: 0 additions & 25 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 All @@ -12,7 +11,6 @@

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

import pytest
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand All @@ -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
2 changes: 0 additions & 2 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4f7d44a

Please sign in to comment.