Skip to content

Commit

Permalink
Merge pull request #2583 from melissa-kun-li/check-specifier-handle-e…
Browse files Browse the repository at this point in the history
…rror

Handle AttributeError by raising DistutilsSetupError in check_specifier. Fixes #1932
  • Loading branch information
jaraco authored Feb 28, 2021
2 parents 1a54925 + adf32a2 commit 0c63d16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/1932.change.rst
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
13 changes: 13 additions & 0 deletions setuptools/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
_get_unpatched,
check_package_data,
DistDeprecationWarning,
check_specifier,
)
from setuptools import sic
from setuptools import Distribution
Expand Down Expand Up @@ -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)

0 comments on commit 0c63d16

Please sign in to comment.