Builds with modern setuptools generate the following warning:

 setuptools/dist.py:765: SetuptoolsDeprecationWarning: License classifiers are 
deprecated.
 !!

   
********************************************************************************
   Please consider removing the following classifiers in favor of a SPDX 
license expression:
   License :: OSI Approved :: Apache Software License
   See 
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license 
for details.
   
********************************************************************************
 !!

The previous attempt to fix this warning was incorrect, as the
license_expression is not a classifier, and was reverted in commit
eb0a643f88cf ("Revert "python: Replace deprecated License with
License-Expression (PEP 639).".").

Do it properly this time.  We need to remove the classifier and
replace the 'license' with the 'license_expression'.

Specifying both fields is not really an option as systems like PyPi
will reject such packages.  So, just checking the setuptools version
at build time and choosing appropriate license description.
This should allow us to build the package on both old and new systems
without warnings and have complete metadata.

Signed-off-by: Ilya Maximets <[email protected]>
---
 python/setup.py.template | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/python/setup.py.template b/python/setup.py.template
index 89e80eed4..56a426dad 100644
--- a/python/setup.py.template
+++ b/python/setup.py.template
@@ -74,6 +74,21 @@ else:
 extra_cflags = os.environ.get('extra_cflags', '').split()
 extra_libs = os.environ.get('extra_libs', '').split()
 
+
+# Use PEP 639 license expression on setuptools >= 77, fall back to the legacy
+# license field and classifier otherwise.
+setuptools_version = tuple(
+    int(x) for x in setuptools.__version__.split('.')[:2]
+)
+if setuptools_version >= (77, 0):
+    license_kwargs = dict(license_expression='Apache-2.0')
+    license_classifiers = []
+else:
+    license_kwargs = dict(license='Apache 2.0')
+    license_classifiers = [
+        'License :: OSI Approved :: Apache Software License',
+    ]
+
 flow_extras_require = ['netaddr', 'pyparsing']
 
 setup_args = dict(
@@ -89,13 +104,13 @@ setup_args = dict(
               'ovs.db', 'ovs.flow', 'ovs.flowviz', 'ovs.flowviz.odp',
               'ovs.flowviz.ofp', 'ovs.unixctl'],
     keywords=['openvswitch', 'ovs', 'OVSDB'],
-    license='Apache 2.0',
+    **license_kwargs,
     classifiers=[
         'Development Status :: 5 - Production/Stable',
         'Topic :: Database :: Front-Ends',
         'Topic :: Software Development :: Libraries :: Python Modules',
         'Topic :: System :: Networking',
-        'License :: OSI Approved :: Apache Software License',
+        *license_classifiers,
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.7',
     ],
-- 
2.54.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to