diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am
index e32fd125..908f622d 100644
--- a/lang/python/Makefile.am
+++ b/lang/python/Makefile.am
@@ -1,115 +1,120 @@
# Makefile.am for the Python bindings.
# Copyright (C) 2016 g10 Code GmbH
#
# This file is part of GPGME.
#
# GPGME is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# GPGME is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see .
EXTRA_DIST = \
README \
MANIFEST.in \
gpgme.i \
helpers.c helpers.h private.h \
gpgme-h-clean.py \
examples \
gpg
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
# For VPATH builds we need to copy some files because Python's
# distutils are not VPATH-aware.
copystamp: $(COPY_FILES) $(COPY_FILES_GPG) data.h config.h
- if test "$(srcdir)" != "$(builddir)" ; then \
- cp -R $(COPY_FILES) . ; \
- cp -R $(COPY_FILES_GPG) gpg ; \
- fi
+ for VERSION in $(PYTHON_VERSIONS); do \
+ $(MKDIR_P) python$${VERSION}-gpg/gpg && \
+ cp -R $(COPY_FILES) python$${VERSION}-gpg && \
+ cp gpg/version.py python$${VERSION}-gpg/gpg && \
+ cp -R $(COPY_FILES_GPG) python$${VERSION}-gpg/gpg ; \
+ done
touch $@
data.h:
ln -s "$(top_srcdir)/src/data.h" .
config.h:
ln -s "$(top_builddir)/config.h" .
all-local: copystamp
- for PYTHON in $(PYTHONS); do \
+ set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \
+ PYTHON="$$1" ; shift ; \
+ cd python$${VERSION}-gpg && \
CFLAGS="$(CFLAGS)" \
- $$PYTHON setup.py build --verbose ; \
+ $$PYTHON ../setup.py build --verbose ; \
+ cd .. ; \
done
dist/gpg-$(VERSION).tar.gz dist/gpg-$(VERSION).tar.gz.asc: copystamp
CFLAGS="$(CFLAGS)" \
$(PYTHON) setup.py sdist --verbose
gpg2 --detach-sign --armor dist/gpg-$(VERSION).tar.gz
.PHONY: prepare
prepare: copystamp
.PHONY: sdist
sdist: dist/gpg-$(VERSION).tar.gz dist/gpg-$(VERSION).tar.gz.asc
.PHONY: upload
upload: dist/gpg-$(VERSION).tar.gz dist/gpg-$(VERSION).tar.gz.asc
twine upload $^
CLEANFILES = gpgme.h errors.i gpgme_wrap.c gpg/gpgme.py \
data.h config.h copystamp
# Remove the rest.
#
# 'make distclean' clears the write bit, breaking rm -rf. Fix the
# permissions.
clean-local:
rm -rf -- build
- if test "$(srcdir)" != "$(builddir)" ; then \
- find . -type d ! -perm -200 -exec chmod u+w {} ';' ; \
- for F in $(COPY_FILES); do rm -rf -- `basename $$F` ; done ; \
- for F in $(COPY_FILES_GPG); do \
- rm -rf -- gpg/`basename $$F` ; \
- done ; \
- fi
+ for VERSION in $(PYTHON_VERSIONS); do \
+ find python$${VERSION}-gpg -type d ! -perm -200 -exec chmod u+w {} ';' ; \
+ rm -rf -- python$${VERSION}-gpg ; \
+ done
install-exec-local:
rm -f install_files.txt
- for PYTHON in $(PYTHONS); do \
- $$PYTHON setup.py install \
+ set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \
+ PYTHON="$$1" ; shift ; \
+ cd python$${VERSION}-gpg && \
+ $$PYTHON ../setup.py 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
uninstall-local:
xargs <$(DESTDIR)$(pythondir)/gpg/install_files.txt -- rm -rf --
rm -rf -- $(DESTDIR)$(pythondir)/gpg
diff --git a/lang/python/tests/run-tests.py b/lang/python/tests/run-tests.py
index 46c6d8c8..e76acb2a 100644
--- a/lang/python/tests/run-tests.py
+++ b/lang/python/tests/run-tests.py
@@ -1,99 +1,101 @@
#!/usr/bin/env python
# Copyright (C) 2016 g10 Code GmbH
#
# This file is part of GPGME.
#
# GPGME is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GPGME is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see .
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import glob
import os
import subprocess
import sys
class SplitAndAccumulate(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
current = getattr(namespace, self.dest, list())
current.extend(values.split())
setattr(namespace, self.dest, current)
parser = argparse.ArgumentParser(description='Run tests.')
parser.add_argument('tests', metavar='TEST', type=str, nargs='+',
help='A test to run')
parser.add_argument('-v', '--verbose', action="store_true", default=False,
help='Be verbose.')
parser.add_argument('-q', '--quiet', action="store_true", default=False,
help='Be quiet.')
parser.add_argument('--interpreters', metavar='PYTHON', type=str,
default=[], action=SplitAndAccumulate,
help='Use these interpreters to run the tests, ' +
'separated by spaces.')
parser.add_argument('--srcdir', type=str,
default=os.environ.get("srcdir", ""),
help='Location of the tests.')
parser.add_argument('--builddir', type=str,
default=os.environ.get("abs_builddir", ""),
help='Location of the tests.')
parser.add_argument('--parallel', action="store_true", default=False,
help='Ignored. For compatibility with run-tests.scm.')
args = parser.parse_args()
if not args.interpreters:
args.interpreters = [sys.executable]
out = sys.stdout if args.verbose else None
err = sys.stderr if args.verbose else None
def status_to_str(code):
return {0: "PASS", 77: "SKIP", 99: "ERROR"}.get(code, "FAIL")
results = list()
for interpreter in args.interpreters:
version = subprocess.check_output(
[interpreter, "-c", "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"]).strip().decode()
- builddirs = glob.glob(os.path.join(args.builddir, "..", "build",
+ builddirs = glob.glob(os.path.join(args.builddir, "..",
+ "python{0}-gpg".format(version),
+ "build",
"lib*"+version))
assert len(builddirs) == 1, \
"Expected one build directory, got {0}".format(builddirs)
env = dict(os.environ)
env["PYTHONPATH"] = builddirs[0]
if not args.quiet:
print("Running tests using {0} ({1})...".format(interpreter, version))
for test in args.tests:
status = subprocess.call(
[interpreter, os.path.join(args.srcdir, test)],
env=env, stdout=out, stderr=err)
if not args.quiet:
print("{0}: {1}".format(status_to_str(status), test))
results.append(status)
def count(status):
return len(list(filter(lambda x: x == status, results)))
def failed():
return len(list(filter(lambda x: x not in (0, 77, 99), results)))
if not args.quiet:
print("{0} tests run, {1} succeeded, {2} failed, {3} skipped.".format(
len(results), count(0), failed(), count(77)))
sys.exit(len(results) - count(0))
sys.exit(results[0])