From 5d60c591e7bfb700b70af32a6a7e71e4646e896c Mon Sep 17 00:00:00 2001 From: Arkelis Date: Wed, 6 Jan 2021 23:32:00 +0100 Subject: [PATCH 1/3] Explicit error when include is not a package ValueError was raised, raise NotAPackageError instead. --- poetry/core/masonry/utils/package_include.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/poetry/core/masonry/utils/package_include.py b/poetry/core/masonry/utils/package_include.py index 47345765f..4a7bd8cfb 100644 --- a/poetry/core/masonry/utils/package_include.py +++ b/poetry/core/masonry/utils/package_include.py @@ -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 @@ -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(): @@ -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: From a634cf54c8ce4f70a778c3ec45d0b790c60325cc Mon Sep 17 00:00:00 2001 From: Arkelis Date: Thu, 7 Jan 2021 09:02:18 +0100 Subject: [PATCH 2/3] Update test_package_include_with_no_python_files_in_dir --- tests/masonry/utils/test_package_include.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/masonry/utils/test_package_include.py b/tests/masonry/utils/test_package_include.py index 0db1ff6da..78e636810 100644 --- a/tests/masonry/utils/test_package_include.py +++ b/tests/masonry/utils/test_package_include.py @@ -1,6 +1,6 @@ import pytest -from poetry.core.masonry.utils.package_include import PackageInclude +from poetry.core.masonry.utils.package_include import NotAPackageError, PackageInclude from poetry.core.utils._compat import Path @@ -37,7 +37,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." From 1ff4c6f8271e9bb1c1b4728cdc5c4d4a351188f4 Mon Sep 17 00:00:00 2001 From: Guillaume Fayard Date: Thu, 7 Jan 2021 09:32:16 +0100 Subject: [PATCH 3/3] Fix import format --- tests/masonry/utils/test_package_include.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/masonry/utils/test_package_include.py b/tests/masonry/utils/test_package_include.py index 78e636810..dd5ecc2bb 100644 --- a/tests/masonry/utils/test_package_include.py +++ b/tests/masonry/utils/test_package_include.py @@ -1,6 +1,7 @@ import pytest -from poetry.core.masonry.utils.package_include import NotAPackageError, PackageInclude +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