Misc CI and packaging updates
- Add a pyproject.toml - Run black on Python code - Do a basic smoke test on Python 2.7, even though our test suite doesn't work there - Don't check in `netfilterqueue.c`, but do include it in the sdist
This commit is contained in:
parent
afcee0d9bf
commit
a5578d3122
|
@ -8,7 +8,7 @@ on:
|
|||
|
||||
jobs:
|
||||
Ubuntu:
|
||||
name: 'Ubuntu (${{ matrix.python }})'
|
||||
name: 'Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})'
|
||||
timeout-minutes: 10
|
||||
runs-on: 'ubuntu-latest'
|
||||
strategy:
|
||||
|
@ -20,6 +20,16 @@ jobs:
|
|||
- '3.8'
|
||||
- '3.9'
|
||||
- '3.10'
|
||||
- 'pypy-3.7'
|
||||
- 'pypy-3.8'
|
||||
check_lint: ['0']
|
||||
extra_name: ['']
|
||||
include:
|
||||
- python: '2.7'
|
||||
extra_name: ', build only'
|
||||
- python: '3.9'
|
||||
check_lint: '1'
|
||||
extra_name: ', check lint'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
@ -30,5 +40,6 @@ jobs:
|
|||
- name: Run tests
|
||||
run: ./ci.sh
|
||||
env:
|
||||
CHECK_LINT: '${{ matrix.check_lint }}'
|
||||
# Should match 'name:' up above
|
||||
JOB_NAME: 'Ubuntu (${{ matrix.python }})'
|
||||
JOB_NAME: 'Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})'
|
||||
|
|
|
@ -82,12 +82,11 @@ From source
|
|||
|
||||
To install from source::
|
||||
|
||||
pip install cython
|
||||
git clone https://github.com/oremanj/python-netfilterqueue
|
||||
cd python-netfilterqueue
|
||||
pip install .
|
||||
|
||||
If Cython is installed, Distutils will use it to regenerate the .c source from the .pyx. It will then compile the .c into a .so.
|
||||
|
||||
API
|
||||
===
|
||||
|
||||
|
|
36
ci.sh
36
ci.sh
|
@ -4,9 +4,43 @@ set -ex -o pipefail
|
|||
|
||||
pip install -U pip setuptools wheel
|
||||
sudo apt-get install libnetfilter-queue-dev
|
||||
|
||||
python setup.py sdist --formats=zip
|
||||
pip install dist/*.zip
|
||||
pip install -r test-requirements.txt
|
||||
|
||||
if python --version 2>&1 | fgrep -q "Python 2.7"; then
|
||||
# The testsuite doesn't run on 2.7, so do just a basic smoke test.
|
||||
unshare -Urn python -c "from netfilterqueue import NetfilterQueue as NFQ; NFQ()"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
pip install -Ur test-requirements.txt
|
||||
|
||||
if [ "$CHECK_LINT" = "1" ]; then
|
||||
error=0
|
||||
if ! black --check setup.py tests; then
|
||||
cat <<EOF
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
Formatting problems were found (listed above). To fix them, run
|
||||
|
||||
pip install -r test-requirements.txt
|
||||
black setup.py tests
|
||||
|
||||
in your local checkout.
|
||||
|
||||
EOF
|
||||
error=1
|
||||
fi
|
||||
if [ "$error" = "1" ]; then
|
||||
cat <<EOF
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
EOF
|
||||
fi
|
||||
exit $error
|
||||
fi
|
||||
|
||||
cd tests
|
||||
pytest -W error -ra -v .
|
||||
|
|
11553
netfilterqueue.c
11553
netfilterqueue.c
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
|||
[build-system]
|
||||
requires = ["setuptools >= 42", "wheel", "cython"]
|
||||
build-backend = "setuptools.build_meta"
|
6
setup.py
6
setup.py
|
@ -1,10 +1,11 @@
|
|||
from setuptools import setup, Extension
|
||||
|
||||
VERSION = "0.8.1" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes.
|
||||
VERSION = "0.8.1" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes.
|
||||
|
||||
try:
|
||||
# Use Cython
|
||||
from Cython.Build import cythonize
|
||||
|
||||
ext_modules = cythonize(
|
||||
Extension(
|
||||
"netfilterqueue", ["netfilterqueue.pyx"], libraries=["netfilter_queue"]
|
||||
|
@ -27,7 +28,6 @@ setup(
|
|||
url="https://github.com/oremanj/python-netfilterqueue",
|
||||
description="Python bindings for libnetfilter_queue",
|
||||
long_description=open("README.rst").read(),
|
||||
download_url="http://pypi.python.org/packages/source/N/NetfilterQueue/NetfilterQueue-%s.tar.gz" % VERSION,
|
||||
classifiers=[
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
|
@ -39,5 +39,5 @@ setup(
|
|||
"Programming Language :: Cython",
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
|
|
@ -3,3 +3,6 @@ pytest
|
|||
trio
|
||||
pytest-trio
|
||||
async_generator
|
||||
cython
|
||||
black
|
||||
platformdirs <= 2.4.0 # needed by black; 2.4.1+ don't support py3.6
|
||||
|
|
|
@ -14,16 +14,30 @@ attrs==21.4.0
|
|||
# outcome
|
||||
# pytest
|
||||
# trio
|
||||
black==21.12b0
|
||||
# via -r test-requirements.in
|
||||
click==8.0.3
|
||||
# via black
|
||||
cython==0.29.26
|
||||
# via -r test-requirements.in
|
||||
idna==3.3
|
||||
# via trio
|
||||
iniconfig==1.1.1
|
||||
# via pytest
|
||||
mypy-extensions==0.4.3
|
||||
# via black
|
||||
outcome==1.1.0
|
||||
# via
|
||||
# pytest-trio
|
||||
# trio
|
||||
packaging==21.3
|
||||
# via pytest
|
||||
pathspec==0.9.0
|
||||
# via black
|
||||
platformdirs==2.4.0
|
||||
# via
|
||||
# -r test-requirements.in
|
||||
# black
|
||||
pluggy==1.0.0
|
||||
# via pytest
|
||||
py==1.11.0
|
||||
|
@ -44,7 +58,11 @@ sortedcontainers==2.4.0
|
|||
# via trio
|
||||
toml==0.10.2
|
||||
# via pytest
|
||||
tomli==1.2.3
|
||||
# via black
|
||||
trio==0.19.0
|
||||
# via
|
||||
# -r test-requirements.in
|
||||
# pytest-trio
|
||||
typing-extensions==4.0.1
|
||||
# via black
|
||||
|
|
|
@ -65,9 +65,7 @@ def pytest_runtestloop():
|
|||
|
||||
|
||||
async def peer_main(idx: int, parent_fd: int) -> None:
|
||||
parent = trio.socket.fromfd(
|
||||
parent_fd, socket.AF_UNIX, socket.SOCK_SEQPACKET
|
||||
)
|
||||
parent = trio.socket.fromfd(parent_fd, socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
|
||||
# Tell parent we've set up our netns, wait for it to confirm it's
|
||||
# created our veth interface
|
||||
|
@ -83,9 +81,7 @@ async def peer_main(idx: int, parent_fd: int) -> None:
|
|||
f"ip addr add {my_ip}/24 dev veth0",
|
||||
f"ip route add default via {router_ip} dev veth0",
|
||||
):
|
||||
await trio.run_process(
|
||||
cmd.split(), capture_stdout=True, capture_stderr=True
|
||||
)
|
||||
await trio.run_process(cmd.split(), capture_stdout=True, capture_stderr=True)
|
||||
|
||||
peer = trio.socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
await peer.bind((my_ip, 0))
|
||||
|
@ -226,11 +222,13 @@ class Harness:
|
|||
await trio.run_process(f"/sbin/iptables -A FORWARD {rule}".split())
|
||||
try:
|
||||
async with packets_w, trio.open_nursery() as nursery:
|
||||
|
||||
@nursery.start_soon
|
||||
async def listen_for_packets():
|
||||
while True:
|
||||
await trio.lowlevel.wait_readable(nfq.get_fd())
|
||||
nfq.run(block=False)
|
||||
|
||||
yield packets_r
|
||||
nursery.cancel_scope.cancel()
|
||||
finally:
|
||||
|
|
|
@ -19,8 +19,9 @@ async def test_queue_dropping(harness):
|
|||
packet.accept()
|
||||
|
||||
async with trio.open_nursery() as nursery:
|
||||
async with harness.capture_packets_to(2) as p2, \
|
||||
harness.capture_packets_to(1) as p1:
|
||||
async with harness.capture_packets_to(2) as p2, harness.capture_packets_to(
|
||||
1
|
||||
) as p1:
|
||||
nursery.start_soon(drop, p2, b"two")
|
||||
nursery.start_soon(drop, p1, b"one")
|
||||
|
||||
|
@ -79,7 +80,7 @@ async def test_rewrite_reorder(harness):
|
|||
|
||||
async def test_errors(harness):
|
||||
with pytest.warns(RuntimeWarning, match="rcvbuf limit is"):
|
||||
async with harness.capture_packets_to(2, sock_len=2**30):
|
||||
async with harness.capture_packets_to(2, sock_len=2 ** 30):
|
||||
pass
|
||||
|
||||
async with harness.capture_packets_to(2, queue_num=0):
|
||||
|
|
Loading…
Reference in New Issue