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

Fix: Exclude file from wheel when listed in gitignore and src layout is used #81

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 8 additions & 10 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,20 @@ def find_files_to_add(
to_add.add(include_file)
continue

if (
isinstance(include, PackageInclude)
and include.source
and self.format == "wheel"
):
source_root = include.base
else:
source_root = self._path

include_file = BuildIncludeFile(path=file, source_root=source_root)
include_file = BuildIncludeFile(path=file, source_root=self._path)

if self.is_excluded(
include_file.relative_to_source_root()
) and isinstance(include, PackageInclude):
continue

if (
abn marked this conversation as resolved.
Show resolved Hide resolved
isinstance(include, PackageInclude)
and include.source
and self.format == "wheel"
):
include_file.source_root = include.base

if file.suffix == ".pyc":
continue

Expand Down
2 changes: 1 addition & 1 deletion poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _write_metadata(self, wheel):
relative_path = "%s/%s" % (self.dist_info, path.relative_to(self._path))
self._add_file(wheel, path, relative_path)
else:
logger.debug("Skipping: %s", path.as_posix())
logger.debug("Skipping: %s" % path.as_posix())
abn marked this conversation as resolved.
Show resolved Hide resolved

with self._write_to_zip(wheel, self.dist_info + "/WHEEL") as f:
self._write_wheel_file(f)
Expand Down
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
==========
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
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"
]

# 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"
42 changes: 42 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from poetry.core.factory import Factory
from poetry.core.masonry.builders.wheel import WheelBuilder
from poetry.core.utils._compat import Path
from tests.masonry.builders.test_sdist import project


fixtures_dir = Path(__file__).parent / "fixtures"
Expand Down Expand Up @@ -228,3 +229,44 @@ def test_wheel_with_file_with_comma():
with zipfile.ZipFile(str(whl)) as z:
records = z.read("comma_file-1.2.3.dist-info/RECORD")
assert '\n"comma_file/a,b.py"' in records.decode()


def test_default_src_with_excluded_data(mocker):
# Patch git module to return specific excluded files
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = [
(
(
Path(__file__).parent
/ "fixtures"
/ "default_src_with_excluded_data"
/ "src"
/ "my_package"
/ "data"
/ "sub_data"
/ "data2.txt"
)
.relative_to(project("default_src_with_excluded_data"))
.as_posix()
)
]
poetry = Factory().create_poetry(project("default_src_with_excluded_data"))

builder = WheelBuilder(poetry)
builder.build()

whl = (
fixtures_dir
/ "default_src_with_excluded_data"
/ "dist"
/ "my_package-1.2.3-py3-none-any.whl"
)

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
names = z.namelist()
assert "my_package/__init__.py" in names
assert "my_package/data/data1.txt" in names
assert "my_package/data/sub_data/data2.txt" not in names
assert "my_package/data/sub_data/data3.txt" in names