Commit f0948384 by Sébastien Eustace

Fix excluded files appearing in package_data

Fixes #431
parent 11c62cb8
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
- Fixed a recursion error on duplicate dependencies with only different extras. - Fixed a recursion error on duplicate dependencies with only different extras.
- Fixed handling of extras. - Fixed handling of extras.
- Fixed duplicate entries in both sdist and wheel. - Fixed duplicate entries in both sdist and wheel.
- Fixed excluded files appearing in the `package_data` of the generated `setup.py`.
## [0.11.5] - 2018-09-04 ## [0.11.5] - 2018-09-04
......
...@@ -223,8 +223,7 @@ class SdistBuilder(Builder): ...@@ -223,8 +223,7 @@ class SdistBuilder(Builder):
return encode(pkg_info) return encode(pkg_info)
@classmethod def find_packages(self, include):
def find_packages(cls, include):
""" """
Discover subpackages and data. Discover subpackages and data.
...@@ -255,6 +254,7 @@ class SdistBuilder(Builder): ...@@ -255,6 +254,7 @@ class SdistBuilder(Builder):
# Relative to the top-level package # Relative to the top-level package
return pkg_name, rel_path return pkg_name, rel_path
excluded_files = self.find_excluded_files()
for path, dirnames, filenames in os.walk(str(base), topdown=True): for path, dirnames, filenames in os.walk(str(base), topdown=True):
if os.path.basename(path) == "__pycache__": if os.path.basename(path) == "__pycache__":
continue continue
...@@ -270,10 +270,28 @@ class SdistBuilder(Builder): ...@@ -270,10 +270,28 @@ class SdistBuilder(Builder):
packages.append(".".join([pkg_name] + parts)) packages.append(".".join([pkg_name] + parts))
else: else:
pkg, from_nearest_pkg = find_nearest_pkg(from_top_level) pkg, from_nearest_pkg = find_nearest_pkg(from_top_level)
pkg_data[pkg].append(pjoin(from_nearest_pkg, "*"))
data_elements = [
f.relative_to(self._path)
for f in Path(path).glob("*")
if not f.is_dir()
]
data = [e for e in data_elements if e not in excluded_files]
if not data:
continue
if len(data) == len(data_elements):
pkg_data[pkg].append(pjoin(from_nearest_pkg, "*"))
else:
for d in data:
if d.is_dir():
continue
pkg_data[pkg] += [pjoin(from_nearest_pkg, d.name) for d in data]
# Sort values in pkg_data # Sort values in pkg_data
pkg_data = {k: sorted(v) for (k, v) in pkg_data.items()} pkg_data = {k: sorted(v) for (k, v) in pkg_data.items() if v}
return pkgdir, sorted(packages), pkg_data return pkgdir, sorted(packages), pkg_data
......
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.
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"
readme = "README.rst"
homepage = "https://poetry.eustace.io/"
repository = "https://github.com/sdispater/poetry"
documentation = "https://poetry.eustace.io/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"
...@@ -406,6 +406,7 @@ def test_package_with_include(mocker): ...@@ -406,6 +406,7 @@ def test_package_with_include(mocker):
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns) exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert "package_dir" not in ns assert "package_dir" not in ns
assert ns["packages"] == ["extra_dir", "extra_dir.sub_pkg", "package_with_include"] assert ns["packages"] == ["extra_dir", "extra_dir.sub_pkg", "package_with_include"]
assert ns["package_data"] == {"": ["*"]}
assert ns["modules"] == ["my_module"] assert ns["modules"] == ["my_module"]
builder.build() builder.build()
...@@ -431,6 +432,58 @@ def test_package_with_include(mocker): ...@@ -431,6 +432,58 @@ def test_package_with_include(mocker):
assert "with-include-1.2.3/PKG-INFO" in names assert "with-include-1.2.3/PKG-INFO" in names
def test_default_with_excluded_data(mocker):
# Patch git module to return specific excluded files
p = mocker.patch("poetry.vcs.git.Git.get_ignored_files")
p.return_value = [
str(
Path(__file__).parent
/ "fixtures"
/ "default_with_excluded_data"
/ "my_package"
/ "data"
/ "sub_data"
/ "data2.txt"
)
]
poetry = Poetry.create(project("default_with_excluded_data"))
builder = SdistBuilder(poetry, NullEnv(), NullIO())
# Check setup.py
setup = builder.build_setup()
setup_ast = ast.parse(setup)
setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert "package_dir" not in ns
assert ns["packages"] == ["my_package"]
assert ns["package_data"] == {
"": ["*"],
"my_package": ["data/*", "data/sub_data/data3.txt"],
}
builder.build()
sdist = (
fixtures_dir / "default_with_excluded_data" / "dist" / "my-package-1.2.3.tar.gz"
)
assert sdist.exists()
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert len(names) == len(set(names))
assert "my-package-1.2.3/LICENSE" in names
assert "my-package-1.2.3/README.rst" in names
assert "my-package-1.2.3/my_package/__init__.py" in names
assert "my-package-1.2.3/my_package/data/data1.txt" in names
assert "my-package-1.2.3/pyproject.toml" in names
assert "my-package-1.2.3/setup.py" in names
assert "my-package-1.2.3/PKG-INFO" in names
def test_proper_python_requires_if_single_version_specified(): def test_proper_python_requires_if_single_version_specified():
poetry = Poetry.create(project("simple_version")) poetry = Poetry.create(project("simple_version"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment