Commit 902eab1d authored by Stefan Behnel's avatar Stefan Behnel

slightly update "sharing declarations" section

parent b9904c3d
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
Sharing Declarations Between Cython Modules Sharing Declarations Between Cython Modules
******************************************** ********************************************
This section describes a new set of facilities for making C declarations, This section describes how to make C declarations, functions and extension
functions and extension types in one Cython module available for use in types in one Cython module available for use in another Cython module.
another Cython module. These facilities are closely modeled on the Python These facilities are closely modeled on the Python import mechanism,
import mechanism, and can be thought of as a compile-time version of it. and can be thought of as a compile-time version of it.
Definition and Implementation files Definition and Implementation files
==================================== ====================================
...@@ -27,6 +28,7 @@ convenient place to put common declarations, for example declarations of ...@@ -27,6 +28,7 @@ convenient place to put common declarations, for example declarations of
functions from an :ref:`external library <external-C-code>` that one functions from an :ref:`external library <external-C-code>` that one
wants to use in several modules. wants to use in several modules.
What a Definition File contains What a Definition File contains
================================ ================================
...@@ -49,6 +51,7 @@ wants to access :keyword:`cdef` attributes and methods, or to inherit from ...@@ -49,6 +51,7 @@ wants to access :keyword:`cdef` attributes and methods, or to inherit from
presence in a definition file does that. You only need a public presence in a definition file does that. You only need a public
declaration if you want to make something available to external C code. declaration if you want to make something available to external C code.
What an Implementation File contains What an Implementation File contains
====================================== ======================================
...@@ -58,6 +61,7 @@ corresponding definition file also defines that type (see below). ...@@ -58,6 +61,7 @@ corresponding definition file also defines that type (see below).
If one doesn't need to :keyword:`cimport` anything from this module, then this If one doesn't need to :keyword:`cimport` anything from this module, then this
is the only file one needs. is the only file one needs.
.. _cimport: .. _cimport:
The cimport statement The cimport statement
...@@ -114,6 +118,7 @@ detail below. ...@@ -114,6 +118,7 @@ detail below.
If a ``.pxd`` file changes, any modules that :keyword:`cimport` from it may need to be If a ``.pxd`` file changes, any modules that :keyword:`cimport` from it may need to be
recompiled. The ``Cython.Build.cythonize`` utility can take care of this for you. recompiled. The ``Cython.Build.cythonize`` utility can take care of this for you.
Search paths for definition files Search paths for definition files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -125,6 +130,7 @@ Also, whenever you compile a file :file:`modulename.pyx`, the corresponding ...@@ -125,6 +130,7 @@ Also, whenever you compile a file :file:`modulename.pyx`, the corresponding
definition file :file:`modulename.pxd` is first searched for along the same definition file :file:`modulename.pxd` is first searched for along the same
path, and if found, it is processed before processing the ``.pyx`` file. path, and if found, it is processed before processing the ``.pyx`` file.
Using cimport to resolve naming conflicts Using cimport to resolve naming conflicts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -153,6 +159,7 @@ in :file:`c_lunch.pxd` are extern C entities. There won't be any actual ...@@ -153,6 +159,7 @@ in :file:`c_lunch.pxd` are extern C entities. There won't be any actual
:file:`c_lunch.pxd` file has done its job of providing an additional namespace :file:`c_lunch.pxd` file has done its job of providing an additional namespace
at compile time. at compile time.
Sharing C Functions Sharing C Functions
=================== ===================
...@@ -188,6 +195,7 @@ example: ...@@ -188,6 +195,7 @@ example:
this object from Python, nor can you use it from Cython using a normal import this object from Python, nor can you use it from Cython using a normal import
statement; you have to use :keyword:`cimport`. statement; you have to use :keyword:`cimport`.
Sharing Extension Types Sharing Extension Types
======================= =======================
...@@ -249,4 +257,3 @@ Some things to note about this example: ...@@ -249,4 +257,3 @@ Some things to note about this example:
doesn't bind the name Shrubbing in Landscaping's module namespace at run doesn't bind the name Shrubbing in Landscaping's module namespace at run
time, so to access :func:`Shrubbing.standard_shrubbery` we also need to time, so to access :func:`Shrubbing.standard_shrubbery` we also need to
``import Shrubbing``. ``import Shrubbing``.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment