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

Raise a more explicit error when include is not a package #123

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions poetry/core/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from .include import Include


class NotAPackageError(ValueError):
pass


class PackageInclude(Include):
def __init__(self, base, include, formats=None, source=None):
self._package = None
Expand Down Expand Up @@ -61,7 +65,7 @@ def check_elements(self): # type: () -> PackageInclude
self._package = root.parent.name

if not self.is_stub_only() and not self.has_modules():
raise ValueError("{} is not a package.".format(root.name))
raise NotAPackageError("{} is not a package.".format(root.name))

else:
if root.is_dir():
Expand All @@ -70,7 +74,7 @@ def check_elements(self): # type: () -> PackageInclude
self._elements = sorted(list(root.glob("**/*")))

if not self.is_stub_only() and not self.has_modules():
raise ValueError("{} is not a package.".format(root.name))
raise NotAPackageError("{} is not a package.".format(root.name))

self._is_package = True
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/masonry/utils/test_package_include.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from poetry.core.masonry.utils.package_include import NotAPackageError
from poetry.core.masonry.utils.package_include import PackageInclude
from poetry.core.utils._compat import Path

Expand Down Expand Up @@ -37,7 +38,7 @@ def test_package_include_with_nested_dir():


def test_package_include_with_no_python_files_in_dir():
with pytest.raises(ValueError) as e:
with pytest.raises(NotAPackageError) as e:
PackageInclude(base=with_includes, include="not_a_python_pkg")

assert str(e.value) == "not_a_python_pkg is not a package."
Expand Down