2008-07-29 13:18:17 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2010-06-16 20:47:55 +00:00
|
|
|
"""
|
2023-02-17 13:53:48 +00:00
|
|
|
Setuptools setup file for Scapy.
|
2010-06-16 20:47:55 +00:00
|
|
|
"""
|
|
|
|
|
2023-02-17 13:53:48 +00:00
|
|
|
import io
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info[0] <= 2:
|
|
|
|
raise OSError("Scapy no longer supports Python 2 ! Please use Scapy 2.5.0")
|
|
|
|
|
2019-01-10 11:56:28 +00:00
|
|
|
try:
|
2023-02-17 13:53:48 +00:00
|
|
|
from setuptools import setup
|
2023-02-13 17:08:41 +00:00
|
|
|
from setuptools.command.sdist import sdist
|
2023-04-11 16:21:11 +00:00
|
|
|
from setuptools.command.build_py import build_py
|
2019-02-24 17:08:03 +00:00
|
|
|
except:
|
|
|
|
raise ImportError("setuptools is required to install scapy !")
|
2008-07-29 13:18:17 +00:00
|
|
|
|
|
|
|
|
2018-05-15 16:23:02 +00:00
|
|
|
def get_long_description():
|
2023-02-17 13:53:48 +00:00
|
|
|
"""
|
|
|
|
Extract description from README.md, for PyPI's usage
|
|
|
|
"""
|
2019-10-22 11:43:25 +00:00
|
|
|
def process_ignore_tags(buffer):
|
|
|
|
return "\n".join(
|
|
|
|
x for x in buffer.split("\n") if "<!-- ignore_ppi -->" not in x
|
|
|
|
)
|
2018-05-15 16:23:02 +00:00
|
|
|
try:
|
2019-02-24 17:08:03 +00:00
|
|
|
fpath = os.path.join(os.path.dirname(__file__), "README.md")
|
|
|
|
with io.open(fpath, encoding="utf-8") as f:
|
2019-01-10 17:08:06 +00:00
|
|
|
readme = f.read()
|
|
|
|
desc = readme.partition("<!-- start_ppi_description -->")[2]
|
|
|
|
desc = desc.partition("<!-- stop_ppi_description -->")[0]
|
2019-10-22 11:43:25 +00:00
|
|
|
return process_ignore_tags(desc.strip())
|
2018-05-15 16:23:02 +00:00
|
|
|
except IOError:
|
|
|
|
return None
|
|
|
|
|
2019-01-10 17:08:06 +00:00
|
|
|
|
2023-04-11 16:21:11 +00:00
|
|
|
# Note: why do we bother including a 'scapy/VERSION' file and doing our
|
|
|
|
# own versioning stuff, instead of using more standard methods?
|
|
|
|
# Because it's all garbage.
|
|
|
|
|
|
|
|
# If you remain fully standard, there's no way
|
|
|
|
# of adding the version dynamically, even less when using archives
|
|
|
|
# (currently, we're able to add the version anytime someone exports Scapy
|
|
|
|
# on github).
|
|
|
|
|
|
|
|
# If you use setuptools_scm, you'll be able to have the git tag set into
|
|
|
|
# the wheel (therefore the metadata), that you can then retrieve using
|
|
|
|
# importlib.metadata, BUT it breaks sdist (source packages), as those
|
|
|
|
# don't include metadata.
|
|
|
|
|
|
|
|
|
|
|
|
def _build_version(path):
|
|
|
|
"""
|
|
|
|
This adds the scapy/VERSION file when creating a sdist and a wheel
|
|
|
|
"""
|
|
|
|
fn = os.path.join(path, 'scapy', 'VERSION')
|
|
|
|
with open(fn, 'w') as f:
|
|
|
|
f.write(__import__('scapy').VERSION)
|
|
|
|
|
|
|
|
|
2023-02-13 17:08:41 +00:00
|
|
|
class SDist(sdist):
|
2023-02-17 13:53:48 +00:00
|
|
|
"""
|
|
|
|
Modified sdist to create scapy/VERSION file
|
|
|
|
"""
|
|
|
|
def make_release_tree(self, base_dir, *args, **kwargs):
|
|
|
|
super(SDist, self).make_release_tree(base_dir, *args, **kwargs)
|
2023-02-13 17:08:41 +00:00
|
|
|
# ensure there's a scapy/VERSION file
|
2023-04-11 16:21:11 +00:00
|
|
|
_build_version(base_dir)
|
|
|
|
|
|
|
|
|
|
|
|
class BuildPy(build_py):
|
|
|
|
"""
|
|
|
|
Modified build_py to create scapy/VERSION file
|
|
|
|
"""
|
|
|
|
def build_package_data(self):
|
|
|
|
super(BuildPy, self).build_package_data()
|
|
|
|
# ensure there's a scapy/VERSION file
|
|
|
|
_build_version(self.build_lib)
|
2023-02-13 17:08:41 +00:00
|
|
|
|
2008-07-29 13:18:17 +00:00
|
|
|
setup(
|
2023-04-11 16:21:11 +00:00
|
|
|
cmdclass={'sdist': SDist, 'build_py': BuildPy},
|
2018-05-15 16:23:02 +00:00
|
|
|
long_description=get_long_description(),
|
|
|
|
long_description_content_type='text/markdown',
|
2008-07-29 13:18:17 +00:00
|
|
|
)
|