Skip to content

Commit c09a292

Browse files
authored
Hack: support setuptools < 77 with modern licenses (#4931)
1 parent 5c3fe1c commit c09a292

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ maintainers = [
1515
{ name="Guillaume VALADON" },
1616
{ name="Nils WEISS" },
1717
]
18-
license = { text="GPL-2.0-only" }
18+
license = "GPL-2.0-only"
1919
requires-python = ">=3.7, <4"
2020
description = "Scapy: interactive packet manipulation tool"
2121
keywords = [ "network" ]
@@ -27,7 +27,6 @@ classifiers = [
2727
"Intended Audience :: Science/Research",
2828
"Intended Audience :: System Administrators",
2929
"Intended Audience :: Telecommunications Industry",
30-
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
3130
"Programming Language :: Python :: 3",
3231
"Programming Language :: Python :: 3 :: Only",
3332
"Programming Language :: Python :: 3.7",

setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
raise OSError("Scapy no longer supports Python 2 ! Please use Scapy 2.5.0")
1313

1414
try:
15+
import setuptools
1516
from setuptools import setup
1617
from setuptools.command.sdist import sdist
1718
from setuptools.command.build_py import build_py
@@ -81,6 +82,31 @@ def build_package_data(self):
8182
# ensure there's a scapy/VERSION file
8283
_build_version(self.build_lib)
8384

85+
86+
# Patch so that for setuptools < 77 understands the 'license' version required
87+
# by modern setuptools. See https://github.com/secdev/scapy/issues/4849.
88+
# This allow us to keep support for Python 3.7
89+
try:
90+
major = int(setuptools.__version__.split(".")[0])
91+
if major < 77:
92+
# We replace setuptools.dist.pyprojecttoml.apply_configuration with goo
93+
from setuptools.config.pyprojecttoml import read_configuration, _apply
94+
95+
def _patched_apply_configuration(dist, filepath, *_):
96+
# 1. We force ignore option errors regarding 'license'
97+
config = read_configuration(filepath, True, ignore_option_errors=True, dist=dist)
98+
99+
# 2. We replace the license with the one it expected
100+
if isinstance(config["project"]["license"], str):
101+
config["project"]["license"] = {'text': config["project"]["license"]}
102+
103+
return _apply(dist, config, filepath)
104+
105+
setuptools.dist.pyprojecttoml.apply_configuration = _patched_apply_configuration
106+
except Exception:
107+
pass
108+
109+
84110
setup(
85111
cmdclass={'sdist': SDist, 'build_py': BuildPy},
86112
data_files=[('share/man/man1', ["doc/scapy.1"])],

0 commit comments

Comments
 (0)