|
12 | 12 | raise OSError("Scapy no longer supports Python 2 ! Please use Scapy 2.5.0") |
13 | 13 |
|
14 | 14 | try: |
| 15 | + import setuptools |
15 | 16 | from setuptools import setup |
16 | 17 | from setuptools.command.sdist import sdist |
17 | 18 | from setuptools.command.build_py import build_py |
@@ -81,6 +82,31 @@ def build_package_data(self): |
81 | 82 | # ensure there's a scapy/VERSION file |
82 | 83 | _build_version(self.build_lib) |
83 | 84 |
|
| 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 | + |
84 | 110 | setup( |
85 | 111 | cmdclass={'sdist': SDist, 'build_py': BuildPy}, |
86 | 112 | data_files=[('share/man/man1', ["doc/scapy.1"])], |
|
0 commit comments