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 28, 2020
1 parent b18781a commit 9f9c96d
Show file tree
Hide file tree
Showing 35 changed files with 708 additions and 559 deletions.
1,071 changes: 531 additions & 540 deletions poetry/core/json/schemas/poetry-schema.json

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
logger = logging.getLogger(__name__)


class Builder(object):
class Builder:
AVAILABLE_PYTHONS = {"2", "2.7", "3", "3.4", "3.5", "3.6", "3.7"}

format = None
Expand Down Expand Up @@ -61,11 +61,31 @@ def __init__(

packages.append(p)

includes = []
for include in self._package.include:
if isinstance(include, str):
includes.append(include)
continue

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 +147,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
12 changes: 11 additions & 1 deletion poetry/core/masonry/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ def __init__(self, name, directory=".", packages=None, includes=None):
)

for include in includes:
self._includes.append(Include(self._path, include))
if isinstance(include, str):
self._includes.append(Include(self._path, include))
continue

formats = include.get("format")
if formats and not isinstance(formats, list):
formats = [formats]

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

@property
def name(self): # type: () -> str
Expand Down
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
58 changes: 46 additions & 12 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ def test_default_with_excluded_data(mocker):
p.return_value = [
(
(
Path(__file__).parent
/ "fixtures"
/ "default_with_excluded_data"
/ "my_package"
/ "data"
/ "sub_data"
/ "data2.txt"
Path(__file__).parent
/ "fixtures"
/ "default_with_excluded_data"
/ "my_package"
/ "data"
/ "sub_data"
/ "data2.txt"
)
.relative_to(project("default_with_excluded_data"))
.as_posix()
.relative_to(project("default_with_excluded_data"))
.as_posix()
)
]
poetry = Factory().create_poetry(project("default_with_excluded_data"))
Expand All @@ -392,7 +392,7 @@ def test_default_with_excluded_data(mocker):
builder.build()

sdist = (
fixtures_dir / "default_with_excluded_data" / "dist" / "my-package-1.2.3.tar.gz"
fixtures_dir / "default_with_excluded_data" / "dist" / "my-package-1.2.3.tar.gz"
)

assert sdist.exists()
Expand Down Expand Up @@ -439,8 +439,8 @@ def test_src_excluded_nested_data():
assert "my-package-1.2.3/my_package/puplic/publicdata.txt" in names
assert "my-package-1.2.3/my_package/public/item1/itemdata1.txt" not in names
assert (
"my-package-1.2.3/my_package/public/item1/subitem/subitemdata.txt"
not in names
"my-package-1.2.3/my_package/public/item1/subitem/subitemdata.txt"
not in names
)
assert "my-package-1.2.3/my_package/public/item2/itemdata2.txt" not in names

Expand All @@ -465,3 +465,37 @@ 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()
12 changes: 12 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,15 @@ 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 9f9c96d

Please sign in to comment.