docs: python bindings

* Updated the Cython example code slightly, along with the
  corresponding explanation.
This commit is contained in:
Ben McGinnes 2018-09-18 08:32:30 +10:00
parent f4d83800d8
commit 362caaf02f
4 changed files with 28 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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)
)