Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
4dc1f87e
Commit
4dc1f87e
authored
Jul 06, 2013
by
Stefan Behnel
Committed by
Stefan Behnel
Jul 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update userguide to use cythonize() for building
parent
5eaf861a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
18 deletions
+52
-18
docs/src/userguide/source_files_and_compilation.rst
docs/src/userguide/source_files_and_compilation.rst
+47
-10
docs/src/userguide/tutorial.rst
docs/src/userguide/tutorial.rst
+5
-8
No files found.
docs/src/userguide/source_files_and_compilation.rst
View file @
4dc1f87e
...
@@ -29,6 +29,7 @@ The other, and probably better, way is to use the :mod:`distutils` extension
...
@@ -29,6 +29,7 @@ The other, and probably better, way is to use the :mod:`distutils` extension
provided with Cython. The benifit of this method is that it will give the
provided with Cython. The benifit of this method is that it will give the
platform specific compilation options, acting like a stripped down autotools.
platform specific compilation options, acting like a stripped down autotools.
Basic setup.py
Basic setup.py
===============
===============
The distutils extension provided with Cython allows you to pass ``.pyx`` files
The distutils extension provided with Cython allows you to pass ``.pyx`` files
...
@@ -39,12 +40,10 @@ extension, say with filename :file:`example.pyx` the associated :file:`setup.py`
...
@@ -39,12 +40,10 @@ extension, say with filename :file:`example.pyx` the associated :file:`setup.py`
would be::
would be::
from distutils.core import setup
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
setup(
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = cythonize("example.pyx")
ext_modules = [Extension("example", ["example.pyx"])]
)
)
To understand the :file:`setup.py` more fully look at the official
To understand the :file:`setup.py` more fully look at the official
...
@@ -55,6 +54,7 @@ current directory use:
...
@@ -55,6 +54,7 @@ current directory use:
$ python setup.py build_ext --inplace
$ python setup.py build_ext --inplace
Cython Files Depending on C Files
Cython Files Depending on C Files
===================================
===================================
...
@@ -63,14 +63,15 @@ compile them into your extension the basic :file:`setup.py` file to do this
...
@@ -63,14 +63,15 @@ compile them into your extension the basic :file:`setup.py` file to do this
would be::
would be::
from distutils.core import setup
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
from distutils.extension import Extension
from Cython.Distutils import build_ext
sourcefiles = ['example.pyx', 'helper.c', 'another_helper.c']
sourcefiles = ['example.pyx', 'helper.c', 'another_helper.c']
extensions = [Extension("example", sourcefiles)]
setup(
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = cythonize(extensions)
ext_modules = [Extension("example", sourcefiles)]
)
)
Notice that the files have been given a name, this is not necessary, but it
Notice that the files have been given a name, this is not necessary, but it
...
@@ -88,17 +89,33 @@ to find the ``.h`` and library files when linking to external libraries.
...
@@ -88,17 +89,33 @@ to find the ``.h`` and library files when linking to external libraries.
Multiple Cython Files in a Package
Multiple Cython Files in a Package
===================================
===================================
TODO
To automatically compile multiple Cython files without listing all of them
explicitly, you can use glob patterns::
setup(
ext_modules = cythonize("package/*.pyx")
)
You can also use glob patterns in :class:`Extension` objects if you pass
them through :func:`cythonize`::
extensions = [Extension("*", "*.pyx")]
setup(
ext_modules = cythonize(extensions)
)
Distributing Cython modules
Distributing Cython modules
============================
============================
It is strongly recommended that you distribute the generated ``.c`` files as well
It is strongly recommended that you distribute the generated ``.c`` files as well
as your Cython sources, so that users can install your module without needing
as your Cython sources, so that users can install your module without needing
to have Cython available.
to have Cython available.
It is also recommended that Cython compilation not be enabled by default in the
It is also recommended that Cython compilation not be enabled by default in the
version you distribute. Even if the user has Cython installed, he probably
version you distribute. Even if the user has Cython installed, he
/she
probably
doesn't want to use it just to install your module. Also, the
version he has
doesn't want to use it just to install your module. Also, the
installed version
may not be the same one you used, and may not compile your sources correctly.
may not be the same one you used, and may not compile your sources correctly.
This simply means that the :file:`setup.py` file that you ship with will just
This simply means that the :file:`setup.py` file that you ship with will just
...
@@ -112,6 +129,26 @@ we would have instead::
...
@@ -112,6 +129,26 @@ we would have instead::
ext_modules = [Extension("example", ["example.c"])]
ext_modules = [Extension("example", ["example.c"])]
)
)
This is easy to combine with :func:`cythonize` by changing the file extension
of the extension module sources::
from distutils.core import setup
from distutils.extension import Extension
USE_CYTHON = ... # command line option, try-import, ...
ext = '.pyx' if USE_CYTHON else '.c'
extensions = [Extension("example", ["example"+ext])]
if USE_CYTHON:
from Cython.Build import cythonize
extensions = cythonize(extensions)
setup(
ext_modules = extensions
)
.. _pyximport:
.. _pyximport:
...
...
docs/src/userguide/tutorial.rst
View file @
4dc1f87e
...
@@ -26,7 +26,6 @@ handling facilities, including the try-except and try-finally statements, is
...
@@ -26,7 +26,6 @@ handling facilities, including the try-except and try-finally statements, is
available to you -- even in the midst of manipulating C data.
available to you -- even in the midst of manipulating C data.
Cython Hello World
Cython Hello World
===================
===================
...
@@ -37,17 +36,15 @@ So lets start with the canonical python hello world::
...
@@ -37,17 +36,15 @@ So lets start with the canonical python hello world::
print "Hello World"
print "Hello World"
S
o the first thing to do is rename the file to :file:`helloworld.pyx`. Now w
e
S
ave this code in a file named :file:`helloworld.pyx`. Now we need to creat
e
need to make the :file:`setup.py`, which is like a python Makefile (for more
the :file:`setup.py`, which is like a python Makefile (for more information
information
see :ref:`compilation`). Your :file:`setup.py` should look like::
see :ref:`compilation`). Your :file:`setup.py` should look like::
from distutils.core import setup
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
setup(
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = cythonize("helloworld.pyx")
ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)
)
To use this to build your Cython file use the commandline options:
To use this to build your Cython file use the commandline options:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment