diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-02-28 11:12:30 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-28 11:12:30 -0500 |
| commit | 0c63d161ecb96514c4b271abbee74ad952f2c537 (patch) | |
| tree | d624c65b32d1276e75fc001ae2d4d8be2a7001f0 | |
| parent | 1a549254c1828161417ff1053b8cdea34b9ad1dd (diff) | |
| parent | adf32a23250c56b8c3856c768b5776bb78f695a3 (diff) | |
| download | python-setuptools-git-0c63d161ecb96514c4b271abbee74ad952f2c537.tar.gz | |
Merge pull request #2583 from melissa-kun-li/check-specifier-handle-error
Handle AttributeError by raising DistutilsSetupError in check_specifier. Fixes #1932
| -rw-r--r-- | changelog.d/1932.change.rst | 1 | ||||
| -rw-r--r-- | setuptools/dist.py | 2 | ||||
| -rw-r--r-- | setuptools/tests/test_dist.py | 13 |
3 files changed, 15 insertions, 1 deletions
diff --git a/changelog.d/1932.change.rst b/changelog.d/1932.change.rst new file mode 100644 index 00000000..a7af5b72 --- /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 diff --git a/setuptools/dist.py b/setuptools/dist.py index c31020f0..6ae3886b 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}" diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index cb47fb58..e4bba47b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -9,6 +9,7 @@ from setuptools.dist import ( _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) |
