From 85f824f49d69177f68245b9788acaf5ace97afb7 Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Sat, 27 Feb 2021 21:31:09 -0500 Subject: [PATCH 1/3] handle AttributeError by raising DisutilsSetupError in check_specifier --- setuptools/dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools/dist.py b/setuptools/dist.py index c31020f0c4..6ae3886b1f 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -292,7 +292,7 @@ def check_specifier(dist, attr, value): """Verify that value is a valid version specifier""" try: packaging.specifiers.SpecifierSet(value) - except packaging.specifiers.InvalidSpecifier as error: + except (packaging.specifiers.InvalidSpecifier, AttributeError) as error: tmpl = ( "{attr!r} must be a string " "containing valid version specifiers; {error}" From 20ced7533c2b737e9d99deacd97633f84b26567d Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Sun, 28 Feb 2021 00:59:58 -0500 Subject: [PATCH 2/3] test check_specifier --- setuptools/tests/test_dist.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index cb47fb5848..e4bba47bce 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -9,6 +9,7 @@ _get_unpatched, check_package_data, DistDeprecationWarning, + check_specifier, ) from setuptools import sic from setuptools import Distribution @@ -323,3 +324,15 @@ def test_check_package_data(package_data, expected_message): with pytest.raises( DistutilsSetupError, match=re.escape(expected_message)): check_package_data(None, str('package_data'), package_data) + + +def test_check_specifier(): + # valid specifier value + attrs = {'name': 'foo', 'python_requires': '>=3.0, !=3.1'} + dist = Distribution(attrs) + check_specifier(dist, attrs, attrs['python_requires']) + + # invalid specifier value + attrs = {'name': 'foo', 'python_requires': ['>=3.0', '!=3.1']} + with pytest.raises(DistutilsSetupError): + dist = Distribution(attrs) From adf32a23250c56b8c3856c768b5776bb78f695a3 Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Sun, 28 Feb 2021 02:11:42 -0500 Subject: [PATCH 3/3] Add changelog --- changelog.d/1932.change.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1932.change.rst diff --git a/changelog.d/1932.change.rst b/changelog.d/1932.change.rst new file mode 100644 index 0000000000..a7af5b72ac --- /dev/null +++ b/changelog.d/1932.change.rst @@ -0,0 +1 @@ +Handled :code:`AttributeError` by raising :code:`DistutilsSetupError` in :code:`dist.check_specifier()` when specifier is not a string -- by :user:`melissa-kun-li` \ No newline at end of file