Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PEP517 check suite and support disabling setup.py for sdists #26

Merged
merged 6 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Integration

on: [push, pull_request]

jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install tox
shell: bash
run: pip install --upgrade tox

- name: Execute integration tests
shell: bash
run: tox -e integration
60 changes: 56 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def create_poetry(self, cwd=None): # type: (Optional[Path]) -> Poetry
break

if "build" in local_config:
package.build = local_config["build"]
build = local_config["build"]
if not isinstance(build, dict):
build = {"script": build}
package.build_config = build or {}

if "include" in local_config:
package.include = local_config["include"]
Expand Down
28 changes: 26 additions & 2 deletions poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@
}
},
"build": {
"type": "string",
"description": "The file used to build extensions."
"$ref": "#/definitions/build-section"
},
"source": {
"type": "array",
Expand Down Expand Up @@ -526,6 +525,31 @@
"description": "Declare this repository as secondary, i.e. it will only be looked up last for packages."
}
}
},
"build-script": {
"type": "string",
"description": "The python script file used to build extensions."
},
"build-config": {
"type": "object",
"description": "Build specific configurations.",
"additionalProperties": false,
"properties": {
"generate-setup-file": {
"type": "boolean",
"description": "Generate and include a setup.py file in sdist.",
"default": true
},
"script": {
"$ref": "#/definitions/build-script"
}
}
},
"build-section": {
"oneOf": [
{"$ref": "#/definitions/build-script"},
{"$ref": "#/definitions/build-config"}
]
}
}
}
4 changes: 2 additions & 2 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def find_files_to_add(self, exclude_build=True): # type: (bool) -> list

# If a build script is specified and explicitely required
# we add it to the list of files
if self._package.build and not exclude_build:
to_add.append(Path(self._package.build))
if self._package.build_script and not exclude_build:
to_add.append(Path(self._package.build_script))

return sorted(to_add)

Expand Down
15 changes: 8 additions & 7 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.package.build_config.get("generate-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 All @@ -112,9 +113,9 @@ def build_setup(self): # type: () -> bytes
package_dir = {}

# If we have a build script, use it
if self._package.build:
if self._package.build_script:
after += [
"from {} import *".format(self._package.build.split(".")[0]),
"from {} import *".format(self._package.build_script.split(".")[0]),
"build(setup_kwargs)",
]

Expand Down
6 changes: 3 additions & 3 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def build(self):
logger.info(" - Built {}".format(self.wheel_filename))

def _build(self, wheel):
if self._package.build:
if self._package.build_script:
with SdistBuilder(poetry=self._poetry).setup_py() as setup:
# We need to place ourselves in the temporary
# directory in order to build the package
Expand Down Expand Up @@ -223,7 +223,7 @@ def dist_info_name(self, distribution, version): # type: (...) -> str

@property
def tag(self):
if self._package.build:
if self._package.build_script:
tag = next(sys_tags())
tag = (tag.interpreter, tag.abi, tag.platform)
else:
Expand Down Expand Up @@ -305,7 +305,7 @@ def _write_wheel_file(self, fp):
fp.write(
wheel_file_template.format(
version=__version__,
pure_lib="true" if self._package.build is None else "false",
pure_lib="true" if self._package.build_script is None else "false",
tag=self.tag,
)
)
Expand Down
8 changes: 7 additions & 1 deletion poetry/core/packages/project_package.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from poetry.core.semver import VersionRange
from poetry.core.semver import parse_constraint
from poetry.core.version.markers import parse_marker
Expand All @@ -10,7 +12,7 @@ class ProjectPackage(Package):
def __init__(self, name, version, pretty_version=None):
super(ProjectPackage, self).__init__(name, version, pretty_version)

self.build = None
self.build_config = dict()
self.packages = []
self.include = []
self.exclude = []
Expand All @@ -19,6 +21,10 @@ def __init__(self, name, version, pretty_version=None):
if self._python_versions == "*":
self._python_constraint = parse_constraint("~2.7 || >=3.4")

@property
def build_script(self): # type: () -> Optional[str]
return self.build_config.get("script")

def is_root(self):
return True

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)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ cleo = "^0.7.6"
tomlkit = "^0.5.8"
vendoring = {version = "^0.2.2", python = "~3.8"}
isort = "^4.3.21"
pep517 = "^0.8.2"
"backports.tempfile" = {version = "^1.0", python = "~2.7"}

[tool.intreehooks]
build-backend = "poetry.core.masonry.api"
Expand Down
71 changes: 71 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from typing import Callable

import pytest

from poetry.core.utils._compat import Path
from tests.utils import tempfile


def pytest_addoption(parser):
parser.addoption(
"--integration",
action="store_true",
dest="integration",
default=False,
help="enable integration tests",
)


def pytest_configure(config):
config.addinivalue_line("markers", "integration: mark integration tests")

if not config.option.integration:
setattr(config.option, "markexpr", "not integration")


def get_project_from_dir(base_directory): # type: (Path) -> Callable[[str], Path]
def get(name): # type: (str) -> Path
path = base_directory / name
if not path.exists():
raise FileNotFoundError(str(path))
return path

return get


@pytest.fixture(scope="session")
def project_source_root(): # type: () -> Path
return Path(__file__).parent.parent


@pytest.fixture(scope="session")
def project_source_test_root(): # type: () -> Path
return Path(__file__).parent


@pytest.fixture(scope="session")
def common_fixtures_directory(project_source_test_root): # type: (Path) -> Path
return project_source_test_root / "fixtures"


@pytest.fixture(scope="session")
def common_project(common_fixtures_directory): # type: (Path) -> Callable[[str], Path]
return get_project_from_dir(common_fixtures_directory)


@pytest.fixture(scope="session")
def masonry_fixtures_directory(project_source_test_root): # type: (Path) -> Path
return project_source_test_root / "masonry" / "builders" / "fixtures"


@pytest.fixture(scope="session")
def masonry_project(
masonry_fixtures_directory,
): # type: (Path) -> Callable[[str], Path]
return get_project_from_dir(masonry_fixtures_directory)


@pytest.fixture
def temporary_directory(): # type: () -> Path
with tempfile.TemporaryDirectory(prefix="poetry-core") as tmp:
yield Path(tmp)
Empty file added tests/integration/__init__.py
Empty file.
Loading