Skip to content

Commit 96bf387

Browse files
gpotter2evverx
andauthored
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 669506b 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 4f71027 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 669506b * 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 <[email protected]> --------- Co-authored-by: Evgeny Vereshchagin <[email protected]>
1 parent ee7d0b4 commit 96bf387

File tree

9 files changed

+160
-95
lines changed

9 files changed

+160
-95
lines changed

.github/workflows/unittests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
run: tox -e spell
3030
- name: Run twine check
3131
run: tox -e twine
32+
- name: Run gitarchive check
33+
run: tox -e gitarchive
3234
docs:
3335
name: Build doc
3436
runs-on: ubuntu-latest

MANIFEST.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
include MANIFEST.in
22
include LICENSE
33
include run_scapy
4-
include scapy/VERSION
5-
recursive-exclude test *
4+
prune test

README

-1
This file was deleted.

doc/scapy/development.rst

+31-6
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,35 @@ publish the release::
300300
Release Candidates (RC) could also be done. For example, the first RC will be
301301
tagged v2.4.3rc1 and the message ``2.4.3 Release Candidate #1``.
302302

303-
Prior to uploading the release to PyPi, the ``author_email`` in ``setup.py``
304-
must be changed to the address of the maintainer performing the release. The
305-
following commands can then be used::
303+
Prior to uploading the release to PyPi, the mail address of the maintainer
304+
performing the release must be added next to his name in ``pyproject.toml``.
305+
See `this <https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#authors-maintainers>`_ for details.
306306

307-
python3 setup.py sdist
308-
twine check dist/scapy-2.4.3.tar.gz
309-
twine upload dist/scapy-2.4.3.tar.gz
307+
The following commands can then be used::
308+
309+
pip install --upgrade build
310+
python -m build
311+
twine check dist/*
312+
twine upload dist/*
313+
314+
.. warning::
315+
Make sure that you don't have left-overs in your ``dist/`` folder ! There should only be the source and the wheel for the package.
316+
Also check that the wheel ends in ``*-py3-none-any.whl`` !
317+
318+
319+
Packaging Scapy
320+
===============
321+
322+
When packaging Scapy, you should build the source while setting the ``SCAPY_VERSION`` variable, in order to make sure that the version remains consistent.
323+
324+
.. code:: bash
325+
326+
$ SCAPY_VERSION=2.5.0 python3 -m build
327+
...
328+
Successfully built scapy-2.5.0.tar.gz and scapy-2.5.0-py3-none-any.whl
329+
330+
If you want to test Scapy while packaging it, you are encouraged to use the ``./run_tests`` script with no arguments. It will run a subset of the tests that don't use any external dependency, and will be easier to test. The only dependency is ``tox``
331+
332+
.. code:: bash
333+
334+
$ ./test/run_tests

doc/scapy/installation.rst

+57-72
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Download and Installation
77
Overview
88
========
99

10-
0. Install `Python 2.7.X or 3.4+ <https://www.python.org/downloads/>`_.
10+
0. Install `Python 3.7+ <https://www.python.org/downloads/>`_.
1111
1. `Download and install Scapy. <#installing-scapy-v2-x>`_
1212
2. `Follow the platform-specific instructions (dependencies) <#platform-specific-instructions>`_.
1313
3. (Optional): `Install additional software for special features <#optional-software-for-special-features>`_.
@@ -18,26 +18,19 @@ Each of these steps can be done in a different way depending on your platform an
1818
Scapy versions
1919
==============
2020

21-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
22-
| Scapy version | Python 2.2-2.6 | Python 2.7 | Python 3.4-3.6 | Python 3.7 | Python 3.8 | Python 3.9 | Python 3.10-3.11 |
23-
+===============+================+============+================+============+============+============+==================+
24-
| 2.3.3 ||||||||
25-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
26-
| 2.4.0 ||||||||
27-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
28-
| 2.4.2 ||||||||
29-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
30-
| 2.4.3-2.4.4 ||||||||
31-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
32-
| 2.4.5 ||||||||
33-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
34-
| 2.5.0 ||||||||
35-
+---------------+----------------+------------+----------------+------------+------------+------------+------------------+
36-
37-
.. note::
38-
39-
In Scapy v2 use ``from scapy.all import *`` instead of ``from scapy import *``.
21+
.. note:: Scapy 2.5.0 was the last version to support Python 2.7 !
4022

23+
+------------------+-------+-------+--------+
24+
| Scapy version | 2.3.3 | 2.5.0 | >2.5.0 |
25+
+==================+=======+=======+========+
26+
| Python 2.2-2.6 ||||
27+
+------------------+-------+-------+--------+
28+
| Python 2.7 ||||
29+
+------------------+-------+-------+--------+
30+
| Python 3.4-3.6 ||||
31+
+------------------+-------+-------+--------+
32+
| Python 3.7-3.11 ||||
33+
+------------------+-------+-------+--------+
4134

4235
Installing Scapy v2.x
4336
=====================
@@ -61,19 +54,21 @@ Latest release
6154

6255
Use pip::
6356

64-
$ pip install --pre scapy[basic]
57+
$ pip install scapy
6558

66-
In fact, since 2.4.3, Scapy comes in 3 bundles:
59+
..
60+
!! COMMENTED UNTIL NEXT RELEASE !!
61+
Scapy specifies ``optional-dependencies`` so that you can install its optional dependencies directly through pip:
6762
68-
+----------+------------------------------------------+---------------------------------------+
69-
| Bundle | Contains | Pip command |
70-
+==========+==========================================+=======================================+
71-
| Default | Only Scapy | ``pip install scapy`` |
72-
+----------+------------------------------------------+---------------------------------------+
73-
| Basic | Scapy & IPython. **Highly recommended** | ``pip install --pre scapy[basic]`` |
74-
+----------+------------------------------------------+---------------------------------------+
75-
| Complete | Scapy & all its main dependencies | ``pip install --pre scapy[complete]`` |
76-
+----------+------------------------------------------+---------------------------------------+
63+
+----------+------------------------------------------+-----------------------------+
64+
| Bundle | Contains | Pip command |
65+
+==========+==========================================+=============================+
66+
| Default | Only Scapy | ``pip install scapy`` |
67+
+----------+------------------------------------------+-----------------------------+
68+
| CLI | Scapy & IPython. **Highly recommended** | ``pip install scapy[cli]`` |
69+
+----------+------------------------------------------+-----------------------------+
70+
| All | Scapy & all its optional dependencies | ``pip install scapy[all]`` |
71+
+----------+------------------------------------------+-----------------------------+
7772

7873

7974
Current development version
@@ -82,34 +77,29 @@ Current development version
8277
.. index::
8378
single: Git, repository
8479

85-
If you always want the latest version with all new features and bugfixes, use Scapy's Git repository:
80+
If you always want the latest version of Scapy with all new the features and bugfixes (but slightly less stable), you can install Scapy from its Git repository.
8681

87-
1. `Install the Git version control system <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>`_.
82+
.. note:: If you don't want to clone Scapy, you can install the development version in one line using::
8883

89-
2. Check out a clone of Scapy's repository::
90-
91-
$ git clone https://github.com/secdev/scapy.git
84+
$ pip install https://github.com/secdev/scapy/archive/refs/heads/master.zip
9285

93-
.. note::
94-
You can also download Scapy's `latest version <https://github.com/secdev/scapy/archive/master.zip>`_ in a zip file::
86+
1. Check out a clone of Scapy's repository with `git <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>`_::
9587

96-
$ wget --trust-server-names https://github.com/secdev/scapy/archive/master.zip # or wget -O master.zip https://github.com/secdev/scapy/archive/master.zip
97-
$ unzip master.zip
98-
$ cd master
88+
$ git clone https://github.com/secdev/scapy.git
89+
$ cd scapy
9990

100-
3. Install Scapy in the standard `distutils <https://docs.python.org/3/distutils/setupscript.html>`_ way::
91+
2. Install Scapy using `pip <https://docs.python.org/dev/installing/index.html>`_::
10192

102-
$ cd scapy
103-
$ sudo python setup.py install
93+
$ pip install .
10494

105-
If you used Git, you can always update to the latest version afterwards::
95+
3. If you used Git, you can always update to the latest version afterwards::
10696

10797
$ git pull
108-
$ sudo python setup.py install
98+
$ pip install .
10999

110100
.. note::
111101

112-
You can run scapy without installing it using the ``run_scapy`` (unix) or ``run_scapy.bat`` (Windows) script or running it directly from the executable zip file (see the previous section).
102+
You can run scapy without installing it using the ``run_scapy`` (unix) or ``run_scapy.bat`` (Windows) script.
113103

114104
Optional Dependencies
115105
=====================
@@ -132,7 +122,7 @@ Here are the topics involved and some examples that you can use to try if your i
132122
133123
* 2D graphics. ``psdump()`` and ``pdfdump()`` need `PyX <http://pyx.sourceforge.net/>`_ which in turn needs a LaTeX distribution: `texlive (Unix) <http://www.tug.org/texlive/>`_ or `MikTex (Windows) <https://miktex.org/>`_.
134124

135-
Note: PyX requires version <=0.12.1 on Python 2.7. This means that on Python 2.7, it needs to be installed via ``pip install pyx==0.12.1``. Otherwise ``pip install pyx``
125+
You can install pyx using ``pip install pyx``
136126

137127
.. code-block:: python
138128
@@ -203,29 +193,29 @@ Linux native
203193

204194
Scapy can run natively on Linux, without libpcap.
205195

206-
* Install `Python 2.7 or 3.4+ <http://www.python.org>`_.
207-
* Install `tcpdump <http://www.tcpdump.org>`_ and make sure it is in the $PATH. (It's only used to compile BPF filters (``-ddd option``))
196+
* Install `Python 3.7+ <http://www.python.org>`__.
197+
* Install `libpcap <http://www.tcpdump.org>`_. (By default it will only be used to compile BPF filters)
208198
* Make sure your kernel has Packet sockets selected (``CONFIG_PACKET``)
209199
* If your kernel is < 2.6, make sure that Socket filtering is selected ``CONFIG_FILTER``)
210200

211201
Debian/Ubuntu/Fedora
212202
--------------------
213203

214-
Make sure tcpdump is installed:
204+
Make sure libpcap is installed:
215205

216206
- Debian/Ubuntu:
217207

218208
.. code-block:: text
219209
220-
$ sudo apt-get install tcpdump
210+
$ sudo apt-get install libpcap-dev
221211
222212
- Fedora:
223213

224214
.. code-block:: text
225215
226-
$ yum install tcpdump
216+
$ yum install libpcap-devel
227217
228-
Then install Scapy via ``pip`` or ``apt`` (bundled under ``python-scapy``)
218+
Then install Scapy via ``pip`` or ``apt`` (bundled under ``python3-scapy``)
229219
All dependencies may be installed either via the platform-specific installer, or via PyPI. See `Optional Dependencies <#optional-dependencies>`_ for more information.
230220

231221

@@ -278,7 +268,7 @@ In a similar manner, to install Scapy on OpenBSD 5.9+, you **may** want to insta
278268

279269
.. code-block:: text
280270
281-
$ doas pkg_add libpcap tcpdump
271+
$ doas pkg_add libpcap
282272
283273
Then install Scapy via ``pip`` or ``pkg_add`` (bundled under ``python-scapy``)
284274
All dependencies may be installed either via the platform-specific installer, or via PyPI. See `Optional Dependencies <#optional-dependencies>`_ for more information.
@@ -297,28 +287,23 @@ Solaris / SunOS requires ``libpcap`` (installed by default) to work.
297287
Windows
298288
-------
299289

300-
.. sectionauthor:: Dirk Loss <mail at dirk-loss.de>
290+
You need to install Npcap in order to install Scapy on Windows (should also work with Winpcap, but unsupported nowadays):
301291

302-
Scapy is primarily being developed for Unix-like systems and works best on those platforms. But the latest version of Scapy supports Windows out-of-the-box. So you can use nearly all of Scapy's features on your Windows machine as well.
292+
* Download link: `Npcap <https://nmap.org/npcap/>`_: `the latest version <https://nmap.org/npcap/#download>`_
293+
* During installation:
294+
* we advise to turn **off** the ``Winpcap compatibility mode``
295+
* if you want to use your wifi card in monitor mode (if supported), make sure you enable the ``802.11`` option
303296

304-
.. image:: graphics/scapy-win-screenshot1.png
305-
:scale: 80
306-
:align: center
307-
308-
You need the following software in order to install Scapy on Windows:
309-
310-
* `Python <http://www.python.org>`_: `Python 2.7.X or 3.4+ <https://www.python.org/downloads/>`_. After installation, add the Python installation directory and its \Scripts subdirectory to your PATH. Depending on your Python version, the defaults would be ``C:\Python27`` and ``C:\Python27\Scripts`` respectively.
311-
* `Npcap <https://nmap.org/npcap/>`_: `the latest version <https://nmap.org/npcap/#download>`_. Default values are recommended. Scapy will also work with Winpcap.
312-
* `Scapy <http://www.secdev.org/projects/scapy/>`_: `latest development version <https://github.com/secdev/scapy/archive/master.zip>`_ from the `Git repository <https://github.com/secdev/scapy>`_. Unzip the archive, open a command prompt in that directory and run ``python setup.py install``.
313-
314-
Just download the files and run the setup program. Choosing the default installation options should be safe. (In the case of ``Npcap``, Scapy **will work** with ``802.11`` option enabled. You might want to make sure that this is ticked when installing).
297+
Once that is done, you can `continue with Scapy's installation <#latest-release>`_.
315298

316-
After all packages are installed, open a command prompt (cmd.exe) and run Scapy by typing ``scapy``. If you have set the PATH correctly, this will find a little batch file in your ``C:\Python27\Scripts`` directory and instruct the Python interpreter to load Scapy.
299+
You should then be able to open a ``cmd.exe`` and just call ``scapy``. If not, you probably haven't enabled the "Add Python to PATH" option when installing Python. You can follow the instructions `over here <https://docs.python.org/3/using/windows.html#finding-the-python-executable>`_ to change that (or add it manually).
317300

318-
If really nothing seems to work, consider skipping the Windows version and using Scapy from a Linux Live CD -- either in a virtual machine on your Windows host or by booting from CDROM: An older version of Scapy is already included in grml and BackTrack for example. While using the Live CD you can easily upgrade to the latest Scapy version by using the `above installation methods <#installing-scapy-v2-x>`_.
301+
Screenshots
302+
^^^^^^^^^^^
319303

320-
Screenshot
321-
^^^^^^^^^^
304+
.. image:: graphics/scapy-win-screenshot1.png
305+
:scale: 80
306+
:align: center
322307

323308
.. image:: graphics/scapy-win-screenshot2.png
324309
:scale: 80

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ changelog = "https://github.com/secdev/scapy/releases"
4747
scapy = "scapy.main:interact"
4848

4949
[project.optional-dependencies]
50-
basic = [ "ipython" ]
51-
complete = [
50+
cli = [ "ipython" ]
51+
all = [
5252
"ipython",
5353
"pyx",
5454
"cryptography>=2.0",

scapy/__init__.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ def _version_from_git_archive():
4040
"""
4141
Rely on git archive "export-subst" git attribute.
4242
See 'man gitattributes' for more details.
43-
Note: describe is only supported with git >= 2.32.0
44-
but we use it to workaround GH#3121
43+
Note: describe is only supported with git >= 2.32.0,
44+
and the `tags=true` option with git >= 2.35.0 but we
45+
use it to workaround GH#3121.
4546
"""
46-
git_archive_id = '$Format:%ct %(describe)$'.strip().split()
47+
git_archive_id = '$Format:%ct %(describe:tags=true)$'.split()
4748
tstamp = git_archive_id[0]
48-
tag = git_archive_id[1]
49+
if len(git_archive_id) > 1:
50+
tag = git_archive_id[1]
51+
else:
52+
# project is run in CI and has another %(describe)
53+
tag = ""
4954

5055
if "Format" in tstamp:
5156
raise ValueError('not a git archive')
@@ -106,7 +111,7 @@ def _git(cmd):
106111
else:
107112
raise subprocess.CalledProcessError(process.returncode, err)
108113

109-
tag = _git("git describe --always")
114+
tag = _git("git describe --tags --always --long")
110115
if not tag.startswith("v"):
111116
# Upstream was not fetched
112117
commit = _git("git rev-list --tags --max-count=1")
@@ -120,12 +125,14 @@ def _version():
120125
121126
:return: the Scapy version
122127
"""
128+
# Method 0: from external packaging
123129
try:
124130
# possibly forced by external packaging
125131
return os.environ['SCAPY_VERSION']
126132
except KeyError:
127133
pass
128134

135+
# Method 1: from the VERSION file, included in sdist and wheels
129136
version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION')
130137
try:
131138
# file generated when running sdist
@@ -135,16 +142,19 @@ def _version():
135142
except FileNotFoundError:
136143
pass
137144

145+
# Method 2: from the archive tag, exported when using git archives
138146
try:
139147
return _version_from_git_archive()
140148
except ValueError:
141149
pass
142150

151+
# Method 3: from git itself, used when Scapy was cloned
143152
try:
144153
return _version_from_git_describe()
145154
except Exception:
146155
pass
147156

157+
# Fallback
148158
try:
149159
# last resort, use the modification date of __init__.py
150160
d = datetime.datetime.utcfromtimestamp(os.path.getmtime(__file__))

0 commit comments

Comments
 (0)