Skip to content

Commit

Permalink
Include files from include in pyproject.toml in the given format.
Browse files Browse the repository at this point in the history
  • Loading branch information
kasteph committed Mar 29, 2020
1 parent b18781a commit c6401a2
Show file tree
Hide file tree
Showing 37 changed files with 807 additions and 546 deletions.
1,068 changes: 528 additions & 540 deletions poetry/core/json/schemas/poetry-schema.json

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,28 @@ def __init__(

packages.append(p)

includes = []
for include in self._package.include:
if isinstance(include, dict):
formats = include.get("format", [])
if formats and not isinstance(formats, list):
formats = [formats]

if (
formats
and self.format
and self.format not in formats
and not ignore_packages_formats
):
continue

includes.append(include)

self._module = Module(
self._package.name,
self._path.as_posix(),
packages=packages,
includes=self._package.include,
includes=includes,
)
self._meta = Metadata.from_package(self._package)

Expand Down Expand Up @@ -127,6 +144,15 @@ def find_files_to_add(self, exclude_build=True): # type: (bool) -> list
continue

if file.is_dir():
if self.format == "sdist" or self.format in include.formats:
for f in Path(file).glob("**/*"):
included = f.relative_to(self._path)
if (
included not in to_add
and not f.is_dir()
and not self.is_excluded(included)
):
to_add.append(included)
continue

file = file.relative_to(self._path)
Expand Down
11 changes: 10 additions & 1 deletion poetry/core/masonry/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ def __init__(self, name, directory=".", packages=None, includes=None):
)

for include in includes:
self._includes.append(Include(self._path, include))
if isinstance(include, dict):
formats = include.get("format")
if formats and not isinstance(formats, list):
formats = [formats]

self._includes.append(
Include(self._path, include["include"], formats=formats)
)
else:
self._includes.append(Include(self._path, include))

@property
def name(self): # type: () -> str
Expand Down
113 changes: 113 additions & 0 deletions pyproject.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[tool.poetry]
name = "poetry-core"
version = "1.0.0a5"
description = "Core utilities for Poetry"
authors = ["Sébastien Eustace <sebastien@eustace.io>"]

license = "MIT"

readme = "README.md"

homepage = "https://github.com/python-poetry/core"
repository = "https://github.com/python-poetry/core"

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

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

packages = [
{include = "poetry"},
{include = "tests", format = "sdist"},
]

[tool.poetry.dependencies]
python = "~2.7 || ^3.5"

typing = {version = "^3.7.4.1", python = "~2.7"}

[tool.poetry.dev-dependencies]
pre-commit = "^1.10"
pytest = "^4.6"
pytest-cov = "^2.8.1"
pytest-mock = "^2.0.0"
tox = "^3.0"
cleo = "^0.7.6"
tomlkit = "^0.5.8"
vendoring = {version = "^0.2.2", python = "~3.8"}
isort = "^4.3.21"

[tool.intreehooks]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| poetry/core/_vendor/*
)/
'''

[tool.isort]
line_length = 88
force_single_line = true
atomic = true
include_trailing_comma = true
lines_after_imports = 2
lines_between_types = 1
multi_line_output = 3
use_parentheses = true
not_skip = "__init__.py"
skip_glob = ["*/setup.py", "*/poetry/core/_vendor/*"]
filter_files = true

known_first_party = "poetry.core"
known_third_party = ["poetry.core._vendor"]

[tool.vendoring]
destination = "poetry/core/_vendor/"
requirements = "poetry/core/_vendor/vendor.txt"
namespace = "poetry.core._vendor"

protected-files = ["__init__.py", "README.md", "vendor.txt"]
patches-dir = "vendors/patches"

[tool.vendoring.transformations]
substitute = [
{ match='poetry.core._vendor.typing ', replace="from typing " },
]
drop = [
"bin/",
"*.so",
"typing.*",
"jsonschema/tests/"
]

[tool.vendoring.typing-stubs]
six = ["six.__init__", "six.moves.__init__", "six.moves.configparser"]
appdirs = []
contextlib2 = []

[tool.vendoring.license.directories]


[tool.vendoring.license.fallback-urls]
pathlib2 = "https://raw.githubusercontent.com/mcmtroffaes/pathlib2/develop/LICENSE.rst"
pyrsistent = "https://raw.githubusercontent.com/tobgu/pyrsistent/master/LICENCE.mit"

[build-system]
requires = ["intreehooks"]
build-backend = "intreehooks:loader"
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/masonry/builders/fixtures/with_include_inline_table/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2018 Sébastien Eustace

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.2.3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[tool.poetry]
name = "with-include"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
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"
]

packages = [
{ include = "src_package", from = "src"},
]

include = [
{ include = "notes.txt", format = "sdist"},
{ include = "tests", format = "sdist" },
{ include = "wheel_only.txt", format = "wheel" }
]


# Requirements
[tool.poetry.dependencies]
python = "^3.6"
cleo = "^0.6"
cachy = { version = "^0.2.0", extras = ["msgpack"] }

pendulum = { version = "^1.4", optional = true }

[tool.poetry.dev-dependencies]
pytest = "~3.4"

[tool.poetry.extras]
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
Empty file.
Empty file.
Empty file.
Empty file.
8 changes: 4 additions & 4 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,22 @@ def test_package_src():


def test_package_with_include(mocker):
module_path = fixtures_dir / "with-include"
module_path = fixtures_dir / "with_include"

# Patch git module to return specific excluded files
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = [
str(
Path(__file__).parent
/ "fixtures"
/ "with-include"
/ "with_include"
/ "extra_dir"
/ "vcs_excluded.txt"
),
str(
Path(__file__).parent
/ "fixtures"
/ "with-include"
/ "with_include"
/ "extra_dir"
/ "sub_pkg"
/ "vcs_excluded.txt"
Expand All @@ -411,7 +411,7 @@ def test_package_with_include(mocker):
builder = CompleteBuilder(Factory().create_poetry(module_path))
builder.build()

sdist = fixtures_dir / "with-include" / "dist" / "with-include-1.2.3.tar.gz"
sdist = fixtures_dir / "with_include" / "dist" / "with-include-1.2.3.tar.gz"

assert sdist.exists()

Expand Down
39 changes: 39 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,42 @@ def test_proper_python_requires_if_three_digits_precision_version_specified():
parsed = p.parsestr(to_str(pkg_info))

assert parsed["Requires-Python"] == "==2.7.15"


def test_includes():
poetry = Factory().create_poetry(project("with_include"))

builder = SdistBuilder(poetry)

builder.build()

sdist = fixtures_dir / "with_include" / "dist" / "with-include-1.2.3.tar.gz"

assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in tar.getnames()
assert "with-include-1.2.3/notes.txt" in tar.getnames()


def test_includes_with_inline_table():
poetry = Factory().create_poetry(project("with_include_inline_table"))

builder = SdistBuilder(poetry)

builder.build()

sdist = (
fixtures_dir
/ "with_include_inline_table"
/ "dist"
/ "with-include-1.2.3.tar.gz"
)

assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "with-include-1.2.3/wheel_only.txt" not in tar.getnames()
assert "with-include-1.2.3/notes.txt" in tar.getnames()
assert "with-include-1.2.3/tests/__init__.py" in tar.getnames()
assert "with-include-1.2.3/tests/test_foo/test.py" in tar.getnames()
13 changes: 13 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,16 @@ def test_dist_info_file_permissions():
z.getinfo("my_package-1.2.3.dist-info/entry_points.txt").external_attr
== 0o644 << 16
)


def test_wheel_includes_inline_table():
module_path = fixtures_dir / "with_include_inline_table"
WheelBuilder.make(Factory().create_poetry(module_path))

whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl"

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
assert "wheel_only.txt" in z.namelist()
assert "notes.txt" not in z.namelist()

0 comments on commit c6401a2

Please sign in to comment.