Skip to content

Commit 39169a3

Browse files
committed
Added support for License-Expression as per PEP 639
It doesn't validate the expressions, or require you to move from using License, yet.
1 parent d8ec782 commit 39169a3

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pyroma/ratings.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class Licensing(BaseTest):
338338

339339
def test(self, data):
340340
license = data.get("license")
341+
license_expression = data.get("license_expression")
341342
classifiers = data.get("classifiers", [])
342343
licenses = set()
343344
for classifier in classifiers:
@@ -346,14 +347,27 @@ def test(self, data):
346347
# license classifier exist
347348
licenses.add(classifier)
348349

349-
if not license and not licenses:
350+
if not license and not license_expression and not licenses:
350351
self._message = "Your package does neither have a license field nor any license classifiers."
351352
return False
352353

353-
if license in CODE_LICENSES:
354-
if not CODE_LICENSES[license].intersection(licenses):
355-
self._message = f"The license '{license}' specified is not listed in your classifiers."
356-
return False
354+
if license and license_expression:
355+
self._message = "You do not need to specify both a License and a Licence-Expression."
356+
return False
357+
358+
if not license and license_expression:
359+
specified = []
360+
for short_name in CODE_LICENSES:
361+
if short_name in license_expression:
362+
specified.append(short_name)
363+
else:
364+
specified = [license]
365+
366+
for license in specified:
367+
if license in CODE_LICENSES:
368+
if not CODE_LICENSES[license].intersection(licenses):
369+
self._message = f"The license '{license}' specified is not listed in your classifiers."
370+
return False
357371

358372
return True
359373

pyroma/testdata/only_config/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ classifiers =
1515
Programming Language :: Python :: 3.2
1616
Programming Language :: Python :: 3.3
1717
License :: OSI Approved :: MIT License
18+
License :: OSI Approved :: GNU General Public License (GPL)
1819
keywords =
1920
pypi
2021
quality
2122
example
23+
license-expression = MIT OR GPL-2.0-or-later
24+
2225
[options]
2326
python_requires = >=2.6

0 commit comments

Comments
 (0)