Skip to content

Commit 2b6ae9f

Browse files
committed
Replace error with warning and remove license classifier
1 parent a54b9ba commit 2b6ae9f

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

setuptools/dist.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from ._reqs import _StrOrIter
2929
from .config import pyprojecttoml, setupcfg
3030
from .discovery import ConfigDiscovery
31-
from .errors import InvalidConfigError
3231
from .monkey import get_unpatched
3332
from .warnings import InformationOnly, SetuptoolsDeprecationWarning
3433

@@ -414,13 +413,21 @@ def _finalize_license_expression(self) -> None:
414413
InformationOnly.emit(f"Normalizing '{license_expr}' to '{normalized}'")
415414
self.metadata.license_expression = normalized
416415

416+
classifiers = []
417+
license_classifiers_found = False
417418
for cl in self.metadata.get_classifiers():
418419
if not cl.startswith("License :: "):
420+
classifiers.append(cl)
419421
continue
420-
raise InvalidConfigError(
421-
"License classifier are deprecated in favor of the license expression. "
422-
f"Remove the '{cl}' classifier."
422+
license_classifiers_found = True
423+
SetuptoolsDeprecationWarning.emit(
424+
"License classifier are deprecated in favor of the license expression.",
425+
f"Please remove the '{cl}' classifier.",
426+
see_url="https://peps.python.org/pep-0639/",
427+
due_date=(2027, 2, 17), # Introduced 2025-02-17
423428
)
429+
if license_classifiers_found:
430+
self.metadata.set_classifiers(classifiers)
424431

425432
def _finalize_license_files(self) -> None:
426433
"""Compute names of all license files which should be included."""

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io
1010
import re
1111
import tarfile
12+
import warnings
1213
from inspect import cleandoc
1314
from pathlib import Path
1415
from unittest.mock import Mock
@@ -23,7 +24,8 @@
2324
from setuptools.config import expand, pyprojecttoml, setupcfg
2425
from setuptools.config._apply_pyprojecttoml import _MissingDynamic, _some_attrgetter
2526
from setuptools.dist import Distribution
26-
from setuptools.errors import InvalidConfigError, RemovedConfigError
27+
from setuptools.errors import RemovedConfigError
28+
from setuptools.warnings import SetuptoolsDeprecationWarning
2729

2830
from .downloads import retrieve_file, urls_from_file
2931

@@ -178,6 +180,7 @@ def main_tomatoes(): pass
178180
license = "mit or apache-2.0" # should be normalized in metadata
179181
classifiers = [
180182
"Development Status :: 5 - Production/Stable",
183+
"Programming Language :: Python",
181184
]
182185
"""
183186

@@ -324,10 +327,19 @@ def test_license_expression_with_bad_classifier(tmp_path):
324327
"README",
325328
f"{text}\n \"License :: OSI Approved :: MIT License\"\n]",
326329
)
327-
msg = "License classifier are deprecated.*'License :: OSI Approved :: MIT License'"
328-
with pytest.raises(InvalidConfigError, match=msg):
330+
msg = "License classifier are deprecated(?:.|\n)*'License :: OSI Approved :: MIT License'"
331+
with pytest.raises(SetuptoolsDeprecationWarning, match=msg):
329332
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
330333

334+
with warnings.catch_warnings():
335+
warnings.simplefilter("ignore", SetuptoolsDeprecationWarning)
336+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
337+
# Check 'License :: OSI Approved :: MIT License' is removed
338+
assert dist.metadata.get_classifiers() == [
339+
"Development Status :: 5 - Production/Stable",
340+
"Programming Language :: Python",
341+
]
342+
331343

332344
class TestLicenseFiles:
333345
def base_pyproject(self, tmp_path, additional_text):

0 commit comments

Comments
 (0)