scapy/setup.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.6 KiB
Python
Raw Normal View History

2008-07-29 13:18:17 +00:00
#! /usr/bin/env python
"""
Setuptools setup file for Scapy.
"""
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:
from setuptools import setup
setup: sanitize package version (#3862) * setup: sanitize package version Currently, when installing from a non-tagged git archive version we get an error from pkg_resources: pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'git-archive.dev95ba5b8504' This version does not comply with the PEP 440 standard. Update the parsing of git-archive %(describe) placeholder by adding multiple safeguards for computing scapy.VERSION (the first successful method is used in priority): 1) If the SCAPY_VERSION env var is defined, use it. This will allow downstream packaging to force a specific version even if they store scapy in a different repository using a different git tag scheme. 2) If the scapy/VERSION file exists, use its contents. 3) Try to parse a tag from a git archive %(describe) placeholder. If the git archive was not made on a tag, use the commit timestamp to convert it to a date YYYY.MM.DD which is PEP 440 compatible. 4) Try to use git describe to generate a tag. 5) Use the last modification date of scapy/__init__.py and generate a date YYYY.MM.DD which is PEP 440 compatible. 6) Return 0.0.0 Do not try to generate the scapy/VERSION file when importing scapy anymore but generate it by overriding the sdist command in setup.py and write it to the temp folder used for the source archive generation. Update unit tests to ensure that order of priority is enforced. Link: https://peps.python.org/pep-0440/ Link: https://bugzilla.redhat.com/show_bug.cgi?id=2162667 Signed-off-by: Robin Jarry <rjarry@redhat.com> * Reject invalid git tags --------- Signed-off-by: Robin Jarry <rjarry@redhat.com> Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
2023-02-13 17:08:41 +00:00
from setuptools.command.sdist import sdist
Support new build methods (#3958) * Build and check the wheel in the twine check as well It should help to make sure that scapy can be installed from PyPI (or any other package index) using pip and its sdist. The check switched to the "build" build frontend because it builds wheels from sdists by default: https://pypa-build.readthedocs.io/en/stable/#python--m-build * Remove README In 669506bd42e4141718374ba297974881fe125fb8 scapy switched to pyproject.toml where 'readme' is dynamic and should be supplied by setup.py. setup.py reads README.md and it works from inside the source tree but since README.md isn't included in the sdist it fails when pip or the build frontend builds the wheel from the sdist with: ``` distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ``` This patch addresses that by removing README and letting setuptools include README.md to the sdist automatcially. README was added in 4f71027fcd in 2016 and back then it probably made sense because setuptools didn't include README.md in the sdist automatically. These days setuptools can handle README.md just fine so it's no longer necessary to keep README any more. It makes it possible to build the wheel from the sdist again. Fixes: ``` python3 -m build ... * Building wheel from sdist * Creating venv isolated environment... * Installing packages in isolated environment... (setuptools>=62.0.0) * Getting build dependencies for wheel... ... File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 351, in _obtain_readme self._ensure_previously_set(dist, "readme") File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 307, in _ensure_previously_set raise OptionError(msg) distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel ``` and ``` python3 -m pip install dist/scapy-2.5.0.dev56.tar.gz Processing ./dist/scapy-2.5.0.dev56.tar.gz Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ... ``` It's a follow-up to 669506bd42e4141718374ba297974881fe125fb8 * Update doc: installation & build instructions * Make sure VERSION is also exported in wheels * Cleanup MANIFEST.in * Add packaging instructions * Add git archive unit test * Use %(describe:tags=True) * Update doc/scapy/installation.rst Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru> --------- Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
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():
"""
Extract description from README.md, for PyPI's usage
"""
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]
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
Support new build methods (#3958) * Build and check the wheel in the twine check as well It should help to make sure that scapy can be installed from PyPI (or any other package index) using pip and its sdist. The check switched to the "build" build frontend because it builds wheels from sdists by default: https://pypa-build.readthedocs.io/en/stable/#python--m-build * Remove README In 669506bd42e4141718374ba297974881fe125fb8 scapy switched to pyproject.toml where 'readme' is dynamic and should be supplied by setup.py. setup.py reads README.md and it works from inside the source tree but since README.md isn't included in the sdist it fails when pip or the build frontend builds the wheel from the sdist with: ``` distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ``` This patch addresses that by removing README and letting setuptools include README.md to the sdist automatcially. README was added in 4f71027fcd in 2016 and back then it probably made sense because setuptools didn't include README.md in the sdist automatically. These days setuptools can handle README.md just fine so it's no longer necessary to keep README any more. It makes it possible to build the wheel from the sdist again. Fixes: ``` python3 -m build ... * Building wheel from sdist * Creating venv isolated environment... * Installing packages in isolated environment... (setuptools>=62.0.0) * Getting build dependencies for wheel... ... File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 351, in _obtain_readme self._ensure_previously_set(dist, "readme") File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 307, in _ensure_previously_set raise OptionError(msg) distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel ``` and ``` python3 -m pip install dist/scapy-2.5.0.dev56.tar.gz Processing ./dist/scapy-2.5.0.dev56.tar.gz Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ... ``` It's a follow-up to 669506bd42e4141718374ba297974881fe125fb8 * Update doc: installation & build instructions * Make sure VERSION is also exported in wheels * Cleanup MANIFEST.in * Add packaging instructions * Add git archive unit test * Use %(describe:tags=True) * Update doc/scapy/installation.rst Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru> --------- Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
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)
setup: sanitize package version (#3862) * setup: sanitize package version Currently, when installing from a non-tagged git archive version we get an error from pkg_resources: pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'git-archive.dev95ba5b8504' This version does not comply with the PEP 440 standard. Update the parsing of git-archive %(describe) placeholder by adding multiple safeguards for computing scapy.VERSION (the first successful method is used in priority): 1) If the SCAPY_VERSION env var is defined, use it. This will allow downstream packaging to force a specific version even if they store scapy in a different repository using a different git tag scheme. 2) If the scapy/VERSION file exists, use its contents. 3) Try to parse a tag from a git archive %(describe) placeholder. If the git archive was not made on a tag, use the commit timestamp to convert it to a date YYYY.MM.DD which is PEP 440 compatible. 4) Try to use git describe to generate a tag. 5) Use the last modification date of scapy/__init__.py and generate a date YYYY.MM.DD which is PEP 440 compatible. 6) Return 0.0.0 Do not try to generate the scapy/VERSION file when importing scapy anymore but generate it by overriding the sdist command in setup.py and write it to the temp folder used for the source archive generation. Update unit tests to ensure that order of priority is enforced. Link: https://peps.python.org/pep-0440/ Link: https://bugzilla.redhat.com/show_bug.cgi?id=2162667 Signed-off-by: Robin Jarry <rjarry@redhat.com> * Reject invalid git tags --------- Signed-off-by: Robin Jarry <rjarry@redhat.com> Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
2023-02-13 17:08:41 +00:00
class SDist(sdist):
"""
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)
setup: sanitize package version (#3862) * setup: sanitize package version Currently, when installing from a non-tagged git archive version we get an error from pkg_resources: pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'git-archive.dev95ba5b8504' This version does not comply with the PEP 440 standard. Update the parsing of git-archive %(describe) placeholder by adding multiple safeguards for computing scapy.VERSION (the first successful method is used in priority): 1) If the SCAPY_VERSION env var is defined, use it. This will allow downstream packaging to force a specific version even if they store scapy in a different repository using a different git tag scheme. 2) If the scapy/VERSION file exists, use its contents. 3) Try to parse a tag from a git archive %(describe) placeholder. If the git archive was not made on a tag, use the commit timestamp to convert it to a date YYYY.MM.DD which is PEP 440 compatible. 4) Try to use git describe to generate a tag. 5) Use the last modification date of scapy/__init__.py and generate a date YYYY.MM.DD which is PEP 440 compatible. 6) Return 0.0.0 Do not try to generate the scapy/VERSION file when importing scapy anymore but generate it by overriding the sdist command in setup.py and write it to the temp folder used for the source archive generation. Update unit tests to ensure that order of priority is enforced. Link: https://peps.python.org/pep-0440/ Link: https://bugzilla.redhat.com/show_bug.cgi?id=2162667 Signed-off-by: Robin Jarry <rjarry@redhat.com> * Reject invalid git tags --------- Signed-off-by: Robin Jarry <rjarry@redhat.com> Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
2023-02-13 17:08:41 +00:00
# ensure there's a scapy/VERSION file
Support new build methods (#3958) * Build and check the wheel in the twine check as well It should help to make sure that scapy can be installed from PyPI (or any other package index) using pip and its sdist. The check switched to the "build" build frontend because it builds wheels from sdists by default: https://pypa-build.readthedocs.io/en/stable/#python--m-build * Remove README In 669506bd42e4141718374ba297974881fe125fb8 scapy switched to pyproject.toml where 'readme' is dynamic and should be supplied by setup.py. setup.py reads README.md and it works from inside the source tree but since README.md isn't included in the sdist it fails when pip or the build frontend builds the wheel from the sdist with: ``` distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ``` This patch addresses that by removing README and letting setuptools include README.md to the sdist automatcially. README was added in 4f71027fcd in 2016 and back then it probably made sense because setuptools didn't include README.md in the sdist automatically. These days setuptools can handle README.md just fine so it's no longer necessary to keep README any more. It makes it possible to build the wheel from the sdist again. Fixes: ``` python3 -m build ... * Building wheel from sdist * Creating venv isolated environment... * Installing packages in isolated environment... (setuptools>=62.0.0) * Getting build dependencies for wheel... ... File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 351, in _obtain_readme self._ensure_previously_set(dist, "readme") File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 307, in _ensure_previously_set raise OptionError(msg) distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel ``` and ``` python3 -m pip install dist/scapy-2.5.0.dev56.tar.gz Processing ./dist/scapy-2.5.0.dev56.tar.gz Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ... ``` It's a follow-up to 669506bd42e4141718374ba297974881fe125fb8 * Update doc: installation & build instructions * Make sure VERSION is also exported in wheels * Cleanup MANIFEST.in * Add packaging instructions * Add git archive unit test * Use %(describe:tags=True) * Update doc/scapy/installation.rst Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru> --------- Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
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)
setup: sanitize package version (#3862) * setup: sanitize package version Currently, when installing from a non-tagged git archive version we get an error from pkg_resources: pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'git-archive.dev95ba5b8504' This version does not comply with the PEP 440 standard. Update the parsing of git-archive %(describe) placeholder by adding multiple safeguards for computing scapy.VERSION (the first successful method is used in priority): 1) If the SCAPY_VERSION env var is defined, use it. This will allow downstream packaging to force a specific version even if they store scapy in a different repository using a different git tag scheme. 2) If the scapy/VERSION file exists, use its contents. 3) Try to parse a tag from a git archive %(describe) placeholder. If the git archive was not made on a tag, use the commit timestamp to convert it to a date YYYY.MM.DD which is PEP 440 compatible. 4) Try to use git describe to generate a tag. 5) Use the last modification date of scapy/__init__.py and generate a date YYYY.MM.DD which is PEP 440 compatible. 6) Return 0.0.0 Do not try to generate the scapy/VERSION file when importing scapy anymore but generate it by overriding the sdist command in setup.py and write it to the temp folder used for the source archive generation. Update unit tests to ensure that order of priority is enforced. Link: https://peps.python.org/pep-0440/ Link: https://bugzilla.redhat.com/show_bug.cgi?id=2162667 Signed-off-by: Robin Jarry <rjarry@redhat.com> * Reject invalid git tags --------- Signed-off-by: Robin Jarry <rjarry@redhat.com> Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
2023-02-13 17:08:41 +00:00
2008-07-29 13:18:17 +00:00
setup(
Support new build methods (#3958) * Build and check the wheel in the twine check as well It should help to make sure that scapy can be installed from PyPI (or any other package index) using pip and its sdist. The check switched to the "build" build frontend because it builds wheels from sdists by default: https://pypa-build.readthedocs.io/en/stable/#python--m-build * Remove README In 669506bd42e4141718374ba297974881fe125fb8 scapy switched to pyproject.toml where 'readme' is dynamic and should be supplied by setup.py. setup.py reads README.md and it works from inside the source tree but since README.md isn't included in the sdist it fails when pip or the build frontend builds the wheel from the sdist with: ``` distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ``` This patch addresses that by removing README and letting setuptools include README.md to the sdist automatcially. README was added in 4f71027fcd in 2016 and back then it probably made sense because setuptools didn't include README.md in the sdist automatically. These days setuptools can handle README.md just fine so it's no longer necessary to keep README any more. It makes it possible to build the wheel from the sdist again. Fixes: ``` python3 -m build ... * Building wheel from sdist * Creating venv isolated environment... * Installing packages in isolated environment... (setuptools>=62.0.0) * Getting build dependencies for wheel... ... File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 351, in _obtain_readme self._ensure_previously_set(dist, "readme") File "/tmp/build-env-vtaxy4xl/lib64/python3.11/site-packages/setuptools/config/pyprojecttoml.py", line 307, in _ensure_previously_set raise OptionError(msg) distutils.errors.DistutilsOptionError: No configuration found for dynamic 'readme'. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`. ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel ``` and ``` python3 -m pip install dist/scapy-2.5.0.dev56.tar.gz Processing ./dist/scapy-2.5.0.dev56.tar.gz Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ... ``` It's a follow-up to 669506bd42e4141718374ba297974881fe125fb8 * Update doc: installation & build instructions * Make sure VERSION is also exported in wheels * Cleanup MANIFEST.in * Add packaging instructions * Add git archive unit test * Use %(describe:tags=True) * Update doc/scapy/installation.rst Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru> --------- Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
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
)