Skip to content

Commit

Permalink
allow disabling setup.py for sdist
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Apr 18, 2020
1 parent 7d9bf48 commit 4d07541
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
12 changes: 12 additions & 0 deletions poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
"type": "array",
"description": "A list of files and folders to exclude."
},
"config": {
"type": "object",
"description": "Project specific poetry configuration",
"properties": {
"disable-setup-file": {
"type": "boolean",
"description": "Disable inclusion of setup.py file in sdist.",
"default": false
}
},
"additionalProperties": true
},
"dependencies": {
"type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that are required to run this package.",
Expand Down
11 changes: 6 additions & 5 deletions poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ def build(self, target_dir=None): # type: (Path) -> Path
else:
tar.addfile(tar_info) # Symlinks & ?

setup = self.build_setup()
tar_info = tarfile.TarInfo(pjoin(tar_dir, "setup.py"))
tar_info.size = len(setup)
tar_info.mtime = time.time()
tar.addfile(tar_info, BytesIO(setup))
if not self._poetry.get_project_config("disable-setup-file", False):
setup = self.build_setup()
tar_info = tarfile.TarInfo(pjoin(tar_dir, "setup.py"))
tar_info.size = len(setup)
tar_info.mtime = time.time()
tar.addfile(tar_info, BytesIO(setup))

pkg_info = self.build_pkg_info()

Expand Down
5 changes: 5 additions & 0 deletions poetry/core/poetry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from typing import Any

from .packages import ProjectPackage
from .utils._compat import Path
from .utils.toml_file import TomlFile
Expand All @@ -25,3 +27,6 @@ def package(self): # type: () -> ProjectPackage
@property
def local_config(self): # type: () -> dict
return self._local_config

def get_project_config(self, config, default=None): # type: (str, Any) -> Any
return self._local_config.get("config", {}).get(config, default)
10 changes: 10 additions & 0 deletions tests/integration/test_pep517.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import pytest

from pep517.check import check
from tests.utils import temporary_project_directory


@pytest.mark.xfail
def test_pep517_simple_project(common_project):
with temporary_project_directory(common_project("simple_project")) as path:
assert check(path)


@pytest.mark.xfail
def test_pep517_src_extended(masonry_project):
with temporary_project_directory(masonry_project("src_extended")) as path:
assert check(path)


@pytest.mark.xfail
def test_pep517_disable_setup_py(masonry_project):
with temporary_project_directory(masonry_project("disable_setup_py")) as path:
assert check(path)
Empty file.
35 changes: 35 additions & 0 deletions tests/masonry/builders/fixtures/disable_setup_py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Poetry Team <noreply@python-poetry.org>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

[tool.poetry.config]
disable-setup-file = true

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"

[tool.poetry.extras]

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
my-script = "my_package:main"
20 changes: 20 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,23 @@ def test_excluded_subpackage():
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)

assert ns["packages"] == ["example"]


def test_sdist_disable_setup_py():
module_path = fixtures_dir / "disable_setup_py"
poetry = Factory().create_poetry(module_path)

builder = SdistBuilder(poetry)
builder.build()

sdist = module_path / "dist" / "my-package-1.2.3.tar.gz"

assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert set(tar.getnames()) == {
"my-package-1.2.3/README.rst",
"my-package-1.2.3/pyproject.toml",
"my-package-1.2.3/PKG-INFO",
"my-package-1.2.3/my_package/__init__.py",
}
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def temporary_project_directory(path):
assert (path / "pyproject.toml").exists()

with tempfile.TemporaryDirectory(prefix="poetry-core-pep517") as tmp:
shutil.copytree(str(path), tmp)
shutil.copytree(str(path), tmp, dirs_exist_ok=True)
toml = TomlFile(str(Path(tmp) / "pyproject.toml"))
data = toml.read()
data.update(__patch__)
Expand Down

0 comments on commit 4d07541

Please sign in to comment.