[PATCH gpgme] Fix prerelease Python sdist tarball creation and add PEP517 support

David Runge dave at sleepmap.de
Tue Nov 15 10:34:13 CET 2022


the attached patches improve the sdist tarball creation by relying on
builtin features of setuptools wherever possible and allowing the
creation (and signing) of prerelease sdist tarballs.

Additionally, a pyproject.toml file now describes the build-system
requirements, which are used by PEP517 build backends and allows common
Python project management software to build gpg as part of a virtualenv.

I noticed, that the last release of gpg [1] is from 2018 and only covers
version 1.10.0 (which can not be built against current libgpg-error).
As I am currently working on a project that will likely make use of gpg
via integration in dulwich [2], I would be very happy, if a release could be
made in the near future (including an sdist tarball on pypi.org).
Ideally, there would also be prebuilt wheels, but they would likely have
to bundle libraries, so that is not so easy to do.
Having an up-to-date and functional sdist tarball would already be a
*huge* improvement for the Python ecosystem!


[1] https://pypi.org/project/gpg/
[2] https://pypi.org/project/dulwich/

-------------- next part --------------
From 2d1fc6414e01959856313ce61d59a71774286b04 Mon Sep 17 00:00:00 2001
From: David Runge <dave at sleepmap.de>
Date: Mon, 14 Nov 2022 00:14:47 +0100
Subject: [PATCH 1/2] Simplify and standardize Python sdist creation

- Substitute `-alpha`, `-beta` and `-rc` version string components with
  `a`, `b` and `rc` (respectively), as that is used when Python version
  strings are constructed (https://peps.python.org/pep-0440/).
- Rely on the standard `dist/` directory created by `python setup.py
  sdist` instead of using a custom one which requires more overhead for
  no benefit.
- Remove the use of the invalid `--manifest` option to `python setup.py
  sdist` (MANIFEST.in is used automatically).
- Instead of trying to find `gpg` via `gpgconf`, just use `gpg`
  directly, when creating a detached signature for the sdist tarball.
- Provide a `clean` target which can be used to remove the `dist/`
  directory via `make clean -C lang/python`.

Signed-off-by: David Runge <dave at sleepmap.de>
 lang/python/Makefile.am | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am
index 845b7b17..99279e74 100644
--- a/lang/python/Makefile.am
+++ b/lang/python/Makefile.am
@@ -23,6 +23,9 @@ EXTRA_DIST = \
 	gpgme.i \
 	helpers.c helpers.h private.h
+# Python translates -alpha to a and -beta to b in version strings
+PY_PKG_VER = $(subst -alpha,a,$(subst -beta,b,$(subst -rc,rc,$(VERSION))))
 SUBDIRS = . tests examples doc src
 .PHONY: prepare
@@ -45,23 +48,20 @@ all-local: copystamp
 	    $$PYTHON setup.py build --verbose --build-base="$$(basename "$${PYTHON}")-gpg" ; \
-python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz.asc: copystamp
-	$(MKDIR_P) python$(PYTHON_VERSION)-gpg-dist
+dist/gpg-$(PY_PKG_VER).tar.gz.asc: copystamp
 	CPP="$(CPP)" \
 	srcdir="$(srcdir)" \
 	top_builddir="$(top_builddir)" \
-	  $(PYTHON) setup.py sdist --verbose --dist-dir=python$(PYTHON_VERSION)-gpg-dist \
-		--manifest=python$(PYTHON_VERSION)-gpg-dist/MANIFEST
-	gpgbin=gpgconf --list-components | grep OpenPGP | sed -e 's/gpg:OpenPGP://g'
-	$(gpgbin) --detach-sign --armor python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz
+	  $(PYTHON) setup.py sdist --verbose
+	gpg --detach-sign --armor dist/gpg-$(PY_PKG_VER).tar.gz
 .PHONY: sdist
-sdist:	python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz.asc
+sdist:	dist/gpg-$(PY_PKG_VER).tar.gz.asc
 .PHONY: upload
-upload: python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz \
-        python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz.asc
+upload: dist/gpg-$(PY_PKG_VER).tar.gz \
+        dist/gpg-$(PY_PKG_VER).tar.gz.asc
 	twine upload $^
 CLEANFILES = copystamp \
@@ -69,6 +69,9 @@ CLEANFILES = copystamp \
 	data.h \
+	rm -rf -- dist
 # Remove the rest.
 # 'make distclean' clears the write bit, breaking rm -rf.  Fix the

-------------- next part --------------
From b23db649e10575a74c78a6679251175da076cfc7 Mon Sep 17 00:00:00 2001
From: David Runge <dave at sleepmap.de>
Date: Mon, 14 Nov 2022 00:22:01 +0100
Subject: [PATCH 2/2] Add pyproject.toml to list required build-systems

Add pyproject.toml file to add the required build-systems (setuptools
and swig). Adding the file with the `[build-system]` table allows PEP517
(https://peps.python.org/pep-0517/) aware build backends to function
properly, by automatically resolving build backends
This change allows to pull in `gpg` via pypi.org using Python project
management software such as flit, poetry and pdm, which are enabled to
build gpg in a virtualenv of a given project.

Signed-off-by: David Runge <dave at sleepmap.de>
 lang/python/pyproject.toml | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 lang/python/pyproject.toml

diff --git a/lang/python/pyproject.toml b/lang/python/pyproject.toml
new file mode 100644
index 00000000..14d55000
--- /dev/null
+++ b/lang/python/pyproject.toml
@@ -0,0 +1,2 @@
+requires = ["setuptools", "swig"]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20221115/5cc99348/attachment.sig>

More information about the Gnupg-devel mailing list