diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am index a18a014a..b9145f5b 100644 --- a/lang/python/Makefile.am +++ b/lang/python/Makefile.am @@ -27,70 +27,45 @@ EXTRA_DIST = \ SUBDIRS = . tests -COPY_FILES = \ - $(srcdir)/gpgme.i \ - $(srcdir)/README \ - $(srcdir)/MANIFEST.in \ - $(srcdir)/gpgme-h-clean.py \ - $(srcdir)/examples \ - $(srcdir)/helpers.c $(srcdir)/helpers.h $(srcdir)/private.h - -COPY_FILES_GPG = \ - $(srcdir)/gpg/callbacks.py \ - $(srcdir)/gpg/constants \ - $(srcdir)/gpg/core.py \ - $(srcdir)/gpg/errors.py \ - $(srcdir)/gpg/__init__.py \ - $(srcdir)/gpg/results.py \ - $(srcdir)/gpg/util.py - .PHONY: prepare -prepare: - test -n "$(PREPAREDIR)" - $(MKDIR_P) "$(PREPAREDIR)/gpg" - cp -R $(COPY_FILES) "$(PREPAREDIR)" - cp setup.py "$(PREPAREDIR)" - cp gpg/version.py "$(PREPAREDIR)/gpg" - ln -sf "$(abs_top_srcdir)/src/data.h" "$(PREPAREDIR)" - ln -sf "$(abs_top_builddir)/config.h" "$(PREPAREDIR)" - cp -R $(COPY_FILES_GPG) "$(PREPAREDIR)/gpg" +prepare: copystamp # For VPATH builds we need to copy some files because Python's # distutils are not VPATH-aware. -copystamp: $(COPY_FILES) $(COPY_FILES_GPG) - set -e ; for VERSION in $(PYTHON_VERSIONS); do \ - $(MAKE) PREPAREDIR=python$${VERSION}-gpg prepare; \ - done +copystamp: + ln -sf "$(abs_top_srcdir)/src/data.h" . + ln -sf "$(abs_top_builddir)/config.h" . touch $@ all-local: copystamp set -e ; set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \ PYTHON="$$1" ; shift ; \ - cd python$${VERSION}-gpg && \ CFLAGS="$(CFLAGS)" \ abs_top_builddir="$(abs_top_builddir)" \ - $$PYTHON setup.py build --verbose ; \ - cd .. ; \ + $$PYTHON setup.py build --verbose --build-base=python$${VERSION}-gpg ; \ done -python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz \ python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz.asc: copystamp - cd python$(PYTHON_VERSION)-gpg && \ + $(MKDIR_P) python$(PYTHON_VERSION)-gpg-dist CFLAGS="$(CFLAGS)" \ abs_top_builddir="$(abs_top_builddir)" \ - $(PYTHON) setup.py sdist --verbose - gpg2 --detach-sign --armor python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz + $(PYTHON) setup.py sdist --verbose --dist-dir=python$(PYTHON_VERSION)-gpg-dist \ + --manifest=python$(PYTHON_VERSION)-gpg-dist/MANIFEST + gpg2 --detach-sign --armor python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz .PHONY: sdist -sdist: python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz \ - python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).tar.gz.asc +sdist: python$(PYTHON_VERSION)-gpg/dist/gpg-$(VERSION).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: python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz \ + python$(PYTHON_VERSION)-gpg-dist/gpg-$(VERSION).tar.gz.asc twine upload $^ -CLEANFILES = copystamp +CLEANFILES = copystamp \ + config.h \ + data.h \ + files.txt \ + install_files.txt # Remove the rest. # @@ -104,22 +79,22 @@ clean-local: done install-exec-local: - rm -f install_files.txt set -e ; set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \ PYTHON="$$1" ; shift ; \ - cd python$${VERSION}-gpg ; \ abs_top_builddir="$(abs_top_builddir)" \ - $$PYTHON setup.py install \ - --prefix $(DESTDIR)$(prefix) \ + $$PYTHON setup.py \ + build \ + --build-base=python$${VERSION}-gpg \ + install \ + --prefix "$(DESTDIR)$(prefix)" \ --record files.txt \ --verbose ; \ - cat files.txt >> ../install_files.txt ; \ + cat files.txt >> install_files.txt ; \ rm files.txt ; \ - cd .. ; \ done - $(MKDIR_P) $(DESTDIR)$(pythondir)/gpg - mv install_files.txt $(DESTDIR)$(pythondir)/gpg + $(MKDIR_P) "$(DESTDIR)$(pythondir)/gpg" + mv install_files.txt "$(DESTDIR)$(pythondir)/gpg" uninstall-local: - xargs <$(DESTDIR)$(pythondir)/gpg/install_files.txt -- rm -rf -- - rm -rf -- $(DESTDIR)$(pythondir)/gpg + xargs < "$(DESTDIR)$(pythondir)/gpg/install_files.txt" -- rm -rf -- + rm -rf -- "$(DESTDIR)$(pythondir)/gpg" diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in index 8ddbf276..6692de6f 100755 --- a/lang/python/setup.py.in +++ b/lang/python/setup.py.in @@ -21,6 +21,7 @@ from distutils.core import setup, Extension import os, os.path, sys import glob +import shutil import subprocess # Out-of-tree build of the gpg bindings. @@ -89,14 +90,6 @@ if not os.path.exists(gpg_error_h): glob.glob(os.path.join(gpg_error_prefix, "include", "*", "gpg-error.h"))[0] -print("Building python gpg module using {} and {}.".format(gpgme_h, gpg_error_h)) - -# Cleanup gpgme.h from deprecated functions and typedefs. -subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpgme_h], - stdout=open("gpgme.h", "w")) -subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpg_error_h], - stdout=open("errors.i", "w")) - define_macros = [] libs = getconfig('libs') @@ -149,14 +142,47 @@ if uname_s.startswith("MINGW32"): # http://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module from distutils.command.build import build class BuildExtFirstHack(build): + + def _generate(self): + print("Building python gpg module using {} and {}.".format(gpgme_h, gpg_error_h)) + + # Cleanup gpgme.h from deprecated functions and typedefs. + # Keep timestamp to avoid rebuild + if not os.path.exists(self.build_base): + os.makedirs(self.build_base) + + for src, dst in ( + (gpgme_h, os.path.join(self.build_base, "gpgme.h")), + (gpg_error_h, os.path.join(self.build_base, "errors.i")) + ): + subprocess.check_call([sys.executable, "gpgme-h-clean.py", src], + stdout=open(dst, "w")) + shutil.copystat(src, dst) + + # Copy due to http://bugs.python.org/issue2624 + # Avoid creating in srcdir + shutil.copy2("gpgme.i", self.build_base) + def run(self): + self._generate() + + # Append generated files via build_base + if not os.path.exists(os.path.join(self.build_lib, "gpg")): + os.makedirs(os.path.join(self.build_lib, "gpg")) + + swig_sources.append(os.path.join(self.build_base, 'gpgme.i')) + swig_opts.extend(['-I' + self.build_base, '-outdir', os.path.join(self.build_lib, 'gpg')]) + include_dirs.append(self.build_base) + self.run_command('build_ext') build.run(self) py3 = [] if sys.version_info.major < 3 else ['-py3'] -swige = Extension("gpg._gpgme", ["gpgme.i", "helpers.c"], - swig_opts = ['-threads', - '-outdir', 'gpg'] + py3 + extra_swig_opts, +swig_sources = ['helpers.c'] +swig_opts = ['-threads'] + py3 + extra_swig_opts +swige = Extension("gpg._gpgme", + sources = swig_sources, + swig_opts = swig_opts, include_dirs = include_dirs, define_macros = define_macros, library_dirs = library_dirs, diff --git a/lang/python/tests/run-tests.py b/lang/python/tests/run-tests.py index 9e061d83..9e2fb78c 100644 --- a/lang/python/tests/run-tests.py +++ b/lang/python/tests/run-tests.py @@ -71,7 +71,6 @@ for interpreter in args.interpreters: pattern = os.path.join(args.builddir, "..", "python{0}-gpg".format(version), - "build", "lib*"+version) builddirs = glob.glob(pattern) if len(builddirs) == 0: