netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft 0/3] Python Build Modernization
@ 2023-07-31 11:40 Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 1/3] py: move package source into src directory Jeremy Sowden
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jeremy Sowden @ 2023-07-31 11:40 UTC (permalink / raw)
  To: Netfilter Devel

Directly invoking setup.py to build and install a Python module is
deprecated:

  https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html

Pablo recently removed the autotooling which did this.  This patch-set
updates the Python build configuration to add support for modern
alternatives while leaving the setup.py script around for users who may
need it.

The approach I have used is described here:

  https://setuptools.pypa.io/en/latest/build_meta.html

We move the setuptools configuration out of setup.py into setup.cfg, and
then add a pyproject.toml configuration file to tell PEP-517 build tools
to use setuptools.

Setuptools also supports putting all its configuration into
pyproject.toml files:

  https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

However, this is much more recent than its setup.cfg support (2022 vs
2016), which is why I decided to stick with the approach described
above.

Jeremy Sowden (3):
  py: move package source into src directory
  py: use setup.cfg to configure setuptools
  py: add pyproject.toml to support PEP-517-compatible build-systems

 INSTALL                  |  3 ++-
 py/Makefile.am           |  2 +-
 py/pyproject.toml        |  3 +++
 py/setup.cfg             | 24 ++++++++++++++++++++++++
 py/setup.py              | 23 ++---------------------
 py/{ => src}/__init__.py |  0
 py/{ => src}/nftables.py |  0
 py/{ => src}/schema.json |  0
 8 files changed, 32 insertions(+), 23 deletions(-)
 create mode 100644 py/pyproject.toml
 create mode 100644 py/setup.cfg
 rename py/{ => src}/__init__.py (100%)
 rename py/{ => src}/nftables.py (100%)
 rename py/{ => src}/schema.json (100%)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH nft 1/3] py: move package source into src directory
  2023-07-31 11:40 [PATCH nft 0/3] Python Build Modernization Jeremy Sowden
@ 2023-07-31 11:40 ` Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 2/3] py: use setup.cfg to configure setuptools Jeremy Sowden
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jeremy Sowden @ 2023-07-31 11:40 UTC (permalink / raw)
  To: Netfilter Devel

Separate the actual package source from the build files.  In addition
to being a bit tidier, this will prevent setup.py being erroneously
installed when we introduce PEP-517 support in a later commit.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 py/Makefile.am           | 2 +-
 py/setup.py              | 2 +-
 py/{ => src}/__init__.py | 0
 py/{ => src}/nftables.py | 0
 py/{ => src}/schema.json | 0
 5 files changed, 2 insertions(+), 2 deletions(-)
 rename py/{ => src}/__init__.py (100%)
 rename py/{ => src}/nftables.py (100%)
 rename py/{ => src}/schema.json (100%)

diff --git a/py/Makefile.am b/py/Makefile.am
index f10ae360599f..4056aa61f820 100644
--- a/py/Makefile.am
+++ b/py/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = setup.py __init__.py nftables.py schema.json
+EXTRA_DIST = setup.py src
diff --git a/py/setup.py b/py/setup.py
index 8ad73e7b58e5..d08b8b129a81 100755
--- a/py/setup.py
+++ b/py/setup.py
@@ -10,7 +10,7 @@ setup(name='nftables',
       url='https://netfilter.org/projects/nftables/index.html',
       packages=['nftables'],
       provides=['nftables'],
-      package_dir={'nftables':'.'},
+      package_dir={'nftables':'src'},
       package_data={'nftables':['schema.json']},
       classifiers=[
           'Development Status :: 4 - Beta',
diff --git a/py/__init__.py b/py/src/__init__.py
similarity index 100%
rename from py/__init__.py
rename to py/src/__init__.py
diff --git a/py/nftables.py b/py/src/nftables.py
similarity index 100%
rename from py/nftables.py
rename to py/src/nftables.py
diff --git a/py/schema.json b/py/src/schema.json
similarity index 100%
rename from py/schema.json
rename to py/src/schema.json
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH nft 2/3] py: use setup.cfg to configure setuptools
  2023-07-31 11:40 [PATCH nft 0/3] Python Build Modernization Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 1/3] py: move package source into src directory Jeremy Sowden
@ 2023-07-31 11:40 ` Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 3/3] py: add pyproject.toml to support PEP-517-compatible build-systems Jeremy Sowden
  2023-08-03  7:46 ` [PATCH nft 0/3] Python Build Modernization Pablo Neira Ayuso
  3 siblings, 0 replies; 5+ messages in thread
From: Jeremy Sowden @ 2023-07-31 11:40 UTC (permalink / raw)
  To: Netfilter Devel

Setuptools has had support for declarative configuration for several
years.  To quote their documentation:

  Setuptools allows using configuration files (usually setup.cfg) to
  define a package’s metadata and other options that are normally
  supplied to the setup() function (declarative config).

  This approach not only allows automation scenarios but also reduces
  boilerplate code in some cases.

Additionally, this allows us to introduce support for PEP-517-compatible
build-systems.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 py/Makefile.am |  2 +-
 py/setup.cfg   | 24 ++++++++++++++++++++++++
 py/setup.py    | 23 ++---------------------
 3 files changed, 27 insertions(+), 22 deletions(-)
 create mode 100644 py/setup.cfg

diff --git a/py/Makefile.am b/py/Makefile.am
index 4056aa61f820..974539fd44ad 100644
--- a/py/Makefile.am
+++ b/py/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = setup.py src
+EXTRA_DIST = setup.cfg setup.py src
diff --git a/py/setup.cfg b/py/setup.cfg
new file mode 100644
index 000000000000..953b7f4164b4
--- /dev/null
+++ b/py/setup.cfg
@@ -0,0 +1,24 @@
+[metadata]
+name = nftables
+version = attr: nftables.NFTABLES_VERSION
+description = Libnftables binding
+author = Netfilter project
+author_email = coreteam@netfilter.org
+url = https://netfilter.org/projects/nftables/index.html
+provides = nftables
+classifiers =
+  Development Status :: 4 - Beta
+  Environment :: Console
+  Intended Audience :: Developers
+  License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+  Operating System :: POSIX :: Linux
+  Programming Language :: Python
+  Topic :: System :: Networking :: Firewalls
+
+[options]
+packages = nftables
+package_dir =
+  nftables = src
+
+[options.package_data]
+nftables = schema.json
diff --git a/py/setup.py b/py/setup.py
index d08b8b129a81..beda28e82166 100755
--- a/py/setup.py
+++ b/py/setup.py
@@ -1,24 +1,5 @@
 #!/usr/bin/env python
+
 from setuptools import setup
-from nftables import NFTABLES_VERSION
 
-setup(name='nftables',
-      version=NFTABLES_VERSION,
-      description='Libnftables binding',
-      author='Netfilter project',
-      author_email='coreteam@netfilter.org',
-      url='https://netfilter.org/projects/nftables/index.html',
-      packages=['nftables'],
-      provides=['nftables'],
-      package_dir={'nftables':'src'},
-      package_data={'nftables':['schema.json']},
-      classifiers=[
-          'Development Status :: 4 - Beta',
-          'Environment :: Console',
-          'Intended Audience :: Developers',
-          'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
-          'Operating System :: POSIX :: Linux',
-          'Programming Language :: Python',
-          'Topic :: System :: Networking :: Firewalls',
-          ],
-      )
+setup()
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH nft 3/3] py: add pyproject.toml to support PEP-517-compatible build-systems
  2023-07-31 11:40 [PATCH nft 0/3] Python Build Modernization Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 1/3] py: move package source into src directory Jeremy Sowden
  2023-07-31 11:40 ` [PATCH nft 2/3] py: use setup.cfg to configure setuptools Jeremy Sowden
@ 2023-07-31 11:40 ` Jeremy Sowden
  2023-08-03  7:46 ` [PATCH nft 0/3] Python Build Modernization Pablo Neira Ayuso
  3 siblings, 0 replies; 5+ messages in thread
From: Jeremy Sowden @ 2023-07-31 11:40 UTC (permalink / raw)
  To: Netfilter Devel

This makes it possible to build and install the module without directly
invoking setup.py which has been deprecated.

Retain the setup.py script for backwards-compatibility.

Update INSTALL to mention the new config-file.

Link: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 INSTALL           | 3 ++-
 py/Makefile.am    | 2 +-
 py/pyproject.toml | 3 +++
 3 files changed, 6 insertions(+), 2 deletions(-)
 create mode 100644 py/pyproject.toml

diff --git a/INSTALL b/INSTALL
index 9b626745d7a4..53021e5aafc3 100644
--- a/INSTALL
+++ b/INSTALL
@@ -86,7 +86,8 @@ Installation instructions for nftables
 
  CPython bindings are available for nftables under the py/ folder.
 
- setup.py is provided to install it.
+ A pyproject.toml config file and legacy setup.py script are provided to install
+ it.
 
  Source code
  ===========
diff --git a/py/Makefile.am b/py/Makefile.am
index 974539fd44ad..76aa082f8709 100644
--- a/py/Makefile.am
+++ b/py/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = setup.cfg setup.py src
+EXTRA_DIST = pyproject.toml setup.cfg setup.py src
diff --git a/py/pyproject.toml b/py/pyproject.toml
new file mode 100644
index 000000000000..fed528d4a7a1
--- /dev/null
+++ b/py/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH nft 0/3] Python Build Modernization
  2023-07-31 11:40 [PATCH nft 0/3] Python Build Modernization Jeremy Sowden
                   ` (2 preceding siblings ...)
  2023-07-31 11:40 ` [PATCH nft 3/3] py: add pyproject.toml to support PEP-517-compatible build-systems Jeremy Sowden
@ 2023-08-03  7:46 ` Pablo Neira Ayuso
  3 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2023-08-03  7:46 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Netfilter Devel

Series applied, thanks

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-03  7:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-31 11:40 [PATCH nft 0/3] Python Build Modernization Jeremy Sowden
2023-07-31 11:40 ` [PATCH nft 1/3] py: move package source into src directory Jeremy Sowden
2023-07-31 11:40 ` [PATCH nft 2/3] py: use setup.cfg to configure setuptools Jeremy Sowden
2023-07-31 11:40 ` [PATCH nft 3/3] py: add pyproject.toml to support PEP-517-compatible build-systems Jeremy Sowden
2023-08-03  7:46 ` [PATCH nft 0/3] Python Build Modernization Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).