Skip to content

Commit

Permalink
Handle nested wildcards in package includes correctly. Fixes: #1379.
Browse files Browse the repository at this point in the history
Use compat `Path`.
  • Loading branch information
kasteph committed Jan 6, 2020
1 parent 3cf8b31 commit f133e9e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions poetry/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def check_elements(self): # type: () -> PackageInclude
# Probably glob
self._is_package = True

# The __init__.py file should be first
# Packages no longer need an __init__.py in python3
root = self._elements[0]
if root.name != "__init__.py":
raise ValueError("{} is not a package.".format(root))
if root.name == "__init__.py":
pass

self._package = root.parent.name
else:
Expand Down
Empty file added tests/masonry/utils/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions tests/masonry/utils/test_package_include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from poetry.masonry.utils.package_include import PackageInclude
from poetry.utils._compat import Path


fixtures_dir = Path(__file__).parent / "fixtures"
with_includes = fixtures_dir / "with_includes"


def test_package_include_with_multiple_dirs():
pkg_include = PackageInclude(base=fixtures_dir, include="with_includes")
assert pkg_include.elements == [
with_includes / "__init__.py",
with_includes / "bar",
with_includes / "bar/baz.py",
with_includes / "extra_package",
with_includes / "extra_package/some_dir",
with_includes / "extra_package/some_dir/foo.py",
with_includes / "extra_package/some_dir/quux.py",
]


def test_package_include_with_simple_dir():
pkg_include = PackageInclude(base=with_includes, include="bar")
assert pkg_include.elements == [with_includes / "bar/baz.py"]


def test_package_include_with_nested_dir():
pkg_include = PackageInclude(base=with_includes, include="extra_package/**/*.py")
assert pkg_include.elements == [
with_includes / "extra_package/some_dir/foo.py",
with_includes / "extra_package/some_dir/quux.py",
]

0 comments on commit f133e9e

Please sign in to comment.