From 8d3193f3848ba4d54f98265749a35c7dfc1a2122 Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Wed, 12 Jan 2022 20:15:53 -0700 Subject: [PATCH] Release v0.9.0 --- CHANGES.txt | 6 +++--- MANIFEST.in | 1 + ci.sh | 5 +++++ netfilterqueue.pyx | 18 ++++++------------ pyproject.toml | 2 +- setup.py | 11 ++++++++++- test-requirements.in | 1 - test-requirements.txt | 2 -- tests/test_basic.py | 4 +++- 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6411b05..96c7638 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,11 +1,11 @@ -v0.9.0, unreleased +v0.9.0, 12 Jan 2021 Improve usability when Packet objects are retained past the callback Add Packet.retain() to save the packet contents in such cases Eliminate warnings during build on py3 Add CI and basic test suite Raise a warning, not an error, if we don't get the bufsize we want - Don't allow bind() more than once on the same NetfilterQueue, since - that would leak the old queue handle + Don't allow bind() more than once on the same NetfilterQueue, since that would leak the old queue handle + ** This will be the last version with support for Python 2.7. ** v0.8.1, 30 Jan 2017 Fix bug #25- crashing when used in OUTPUT or POSTROUTING chains diff --git a/MANIFEST.in b/MANIFEST.in index d1d14ae..f461248 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,4 @@ include *.rst include *.c include *.pyx include *.pxd +recursive-include tests/ *.py diff --git a/ci.sh b/ci.sh index 54f0181..0284cdc 100755 --- a/ci.sh +++ b/ci.sh @@ -5,7 +5,12 @@ set -ex -o pipefail pip install -U pip setuptools wheel sudo apt-get install libnetfilter-queue-dev +# Cython is required to build the sdist... +pip install cython python setup.py sdist --formats=zip + +# ... but not to install it +pip uninstall -y cython pip install dist/*.zip if python --version 2>&1 | fgrep -q "Python 2.7"; then diff --git a/netfilterqueue.pyx b/netfilterqueue.pyx index 9730af5..42a4a98 100644 --- a/netfilterqueue.pyx +++ b/netfilterqueue.pyx @@ -5,7 +5,7 @@ function. Copyright: (c) 2011, Kerkhoff Technologies Inc. License: MIT; see LICENSE.txt """ -VERSION = (0, 8, 1) +VERSION = (0, 9, 0) # Constants for module users COPY_NONE = 0 @@ -24,10 +24,6 @@ DEF SockCopySize = MaxCopySize + SockOverhead # Socket queue should hold max number of packets of copysize bytes DEF SockRcvSize = DEFAULT_MAX_QUEUELEN * SockCopySize // 2 -cdef extern from "Python.h": - const char* __FILE__ - int __LINE__ - cdef extern from *: """ #if PY_MAJOR_VERSION < 3 @@ -35,10 +31,6 @@ cdef extern from *: #endif """ -import socket -import warnings -cimport cpython.version - cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg, nfq_data *nfa, void *data) with gil: """Create a Packet and pass it to appropriate callback.""" @@ -227,11 +219,11 @@ cdef class NetfilterQueue: newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h), sock_len) if newsiz != sock_len * 2: try: - warnings.warn_explicit( + import warnings + + warnings.warn( "Socket rcvbuf limit is now %d, requested %d." % (newsiz, sock_len), category=RuntimeWarning, - filename=bytes(__FILE__).decode("ascii"), - lineno=__LINE__, ) except: # if warnings are being treated as errors self.unbind() @@ -267,6 +259,8 @@ cdef class NetfilterQueue: def run_socket(self, s): """Accept packets using socket.recv so that, for example, gevent can monkeypatch it.""" + import socket + while True: try: buf = s.recv(BufferSize) diff --git a/pyproject.toml b/pyproject.toml index f1a8602..9787c3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools >= 42", "wheel", "cython"] +requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index c6f403a..ead5b9d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ +import os, sys from setuptools import setup, Extension -VERSION = "0.8.1" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes. +VERSION = "0.9.0" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes. try: # Use Cython @@ -14,6 +15,14 @@ try: ) except ImportError: # No Cython + if not os.path.exists(os.path.join(os.path.dirname(__file__), "netfilterqueue.c")): + sys.stderr.write( + "You must have Cython installed (`pip install cython`) to build this " + "package from source.\nIf you're receiving this error when installing from " + "PyPI, please file a bug report at " + "https://github.com/oremanj/python-netfilterqueue/issues/new\n" + ) + sys.exit(1) ext_modules = [ Extension("netfilterqueue", ["netfilterqueue.c"], libraries=["netfilter_queue"]) ] diff --git a/test-requirements.in b/test-requirements.in index 86be074..21b675e 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -3,6 +3,5 @@ pytest trio pytest-trio async_generator -cython black platformdirs <= 2.4.0 # needed by black; 2.4.1+ don't support py3.6 diff --git a/test-requirements.txt b/test-requirements.txt index 2eff85c..b5acfd3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -18,8 +18,6 @@ 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 diff --git a/tests/test_basic.py b/tests/test_basic.py index 2f55781..264aa8d 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -79,10 +79,12 @@ async def test_rewrite_reorder(harness): async def test_errors(harness): - with pytest.warns(RuntimeWarning, match="rcvbuf limit is"): + with pytest.warns(RuntimeWarning, match="rcvbuf limit is") as record: async with harness.capture_packets_to(2, sock_len=2 ** 30): pass + assert record[0].filename.endswith("conftest.py") + async with harness.capture_packets_to(2, queue_num=0): with pytest.raises(OSError, match="Failed to create queue"): async with harness.capture_packets_to(2, queue_num=0):