From 362caaf02f3a25b7e626572aa30b87771c2c8f4d Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Tue, 18 Sep 2018 08:32:30 +1000 Subject: [PATCH] docs: python bindings * Updated the Cython example code slightly, along with the corresponding explanation. --- doc/gpgme-python-howto.texi | 10 +++++++--- lang/python/docs/gpgme-python-howto.org | 10 +++++++--- .../examples/howto/advanced/cython/keycount.pyx | 16 +++++++++++++--- .../examples/howto/advanced/cython/setup.py | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/doc/gpgme-python-howto.texi b/doc/gpgme-python-howto.texi index 8073a90b..7cdce1eb 100644 --- a/doc/gpgme-python-howto.texi +++ b/doc/gpgme-python-howto.texi @@ -2120,8 +2120,9 @@ publist = list(pubkeys) pubnum = len(publist) print(""" - Number of secret keys: @{0@} - Number of public keys: @{1@} + Number of secret keys: @{0@} + Number of public keys: @{1@} + """.format(secnum, pubnum)) @end example @@ -2172,7 +2173,10 @@ On the other hand it ran in nearly half the time; taking 6 minutes and which the CPython script alone took. The @samp{keycount.pyx} and @samp{setup.py} files used to generate this example -have been added to the @samp{examples/howto/advanced/cython/} directory. +have been added to the @samp{examples/howto/advanced/cython/} directory +The example versions include some additional options to annotate the +existing code and to detect Cython's use. The latter comes from the +@uref{http://docs.cython.org/en/latest/src/tutorial/pure.html#magic-attributes-within-the-pxd, Magic Attributes} section of the Cython documentation. @node Miscellaneous work-arounds @chapter Miscellaneous work-arounds diff --git a/lang/python/docs/gpgme-python-howto.org b/lang/python/docs/gpgme-python-howto.org index 0d7f9b4e..0836d21d 100644 --- a/lang/python/docs/gpgme-python-howto.org +++ b/lang/python/docs/gpgme-python-howto.org @@ -2025,8 +2025,9 @@ publist = list(pubkeys) pubnum = len(publist) print(""" - Number of secret keys: {0} - Number of public keys: {1} + Number of secret keys: {0} + Number of public keys: {1} + """.format(secnum, pubnum)) #+END_SRC @@ -2077,7 +2078,10 @@ On the other hand it ran in nearly half the time; taking 6 minutes and which the CPython script alone took. The =keycount.pyx= and =setup.py= files used to generate this example -have been added to the =examples/howto/advanced/cython/= directory. +have been added to the =examples/howto/advanced/cython/= directory +The example versions include some additional options to annotate the +existing code and to detect Cython's use. The latter comes from the +[[http://docs.cython.org/en/latest/src/tutorial/pure.html#magic-attributes-within-the-pxd][Magic Attributes]] section of the Cython documentation. * Miscellaneous work-arounds diff --git a/lang/python/examples/howto/advanced/cython/keycount.pyx b/lang/python/examples/howto/advanced/cython/keycount.pyx index f0097db2..2aa636d5 100755 --- a/lang/python/examples/howto/advanced/cython/keycount.pyx +++ b/lang/python/examples/howto/advanced/cython/keycount.pyx @@ -1,3 +1,6 @@ +from __future__ import absolute_import + +import cython import gpg c = gpg.Context() @@ -10,7 +13,14 @@ secnum = len(seclist) publist = list(pubkeys) pubnum = len(publist) +if cython.compiled is True: + cc = "Powered by Cython compiled C code." +else: + cc = "Powered by Python." + print(""" -Number of secret keys: {0} -Number of public keys: {1} -""".format(secnum, pubnum)) + Number of secret keys: {0} + Number of public keys: {1} + + {2} +""".format(secnum, pubnum, cc)) diff --git a/lang/python/examples/howto/advanced/cython/setup.py b/lang/python/examples/howto/advanced/cython/setup.py index 0d0be01e..f8dce034 100644 --- a/lang/python/examples/howto/advanced/cython/setup.py +++ b/lang/python/examples/howto/advanced/cython/setup.py @@ -2,5 +2,5 @@ from distutils.core import setup from Cython.Build import cythonize setup( - ext_modules = cythonize("keycount.pyx") + ext_modules = cythonize("keycount.pyx", annotate=True) )