Skip to content

Commit fdf53b9

Browse files
author
gabrieldemarmiesse
committed
Changed some filenames.
1 parent 54a5fb5 commit fdf53b9

File tree

7 files changed

+91
-93
lines changed

7 files changed

+91
-93
lines changed

Demos/Readme_demos.rst Demos/README.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
* To run demos do::
1+
To run demos do::
22

33
cd Demos
44
make test
55

6-
which runs run_primes.py, run_numeric_demo.py, run_spam.py,
7-
integrate_timing.py, callback/runcheese.py and embed/embedded
6+
which runs ``run_primes.py``, ``run_numeric_demo.py``, ``run_spam.py``,
7+
``integrate_timing.py``, ``callback/runcheese.py`` and ``embed/embedded``
88

9-
* For other demos::
9+
For other demos::
1010

1111
cd libraries
1212
python setup.py build_ext --inplace
1313
python -c 'import call_mymath;print(call_mymath.call_sinc(1))'
1414

15-
To run one of the benchmarks for 10 iterations to compare cython and python timings::
15+
To run one of the benchmarks for 10 iterations to compare cython and python timings::
1616

1717
cd benchmarks
1818
python setup.py build_ext --inplace
1919
python nqueens.py -n 10
2020
python -c 'import nqueens;print(nqueens.test_n_queens(10))'
2121

22-
To demo cython/bin/cython_freeze::
22+
To demo ``cython/bin/cython_freeze``::
2323

2424
make
2525
./nCr 10 5

Demos/callback/README.txt Demos/callback/README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ This example demonstrates how you can wrap a C API
22
that has a callback interface, so that you can
33
pass Python functions to it as callbacks.
44

5-
The files cheesefinder.h and cheesefinder.c
5+
The files ``cheesefinder.h`` and ``cheesefinder.c``
66
represent the C library to be wrapped.
77

8-
The file cheese.pyx is the Pyrex module
8+
The file ``cheese.pyx`` is the Cython module
99
which wraps it.
1010

11-
The file run_cheese.py demonstrates how to
11+
The file ``run_cheese.py`` demonstrates how to
1212
call the wrapper.

Demos/embed/README Demos/embed/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ This example demonstrates how Cython-generated code
22
can be called directly from a main program written in C.
33

44
The Windows makefiles were contributed by
5-
Duncan Booth <[email protected]>.
5+
Duncan Booth: [email protected].

Demos/freeze/README.txt Demos/freeze/README.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
NAME
22
====
33

4-
cython_freeze - create a C file for embedding Cython modules
4+
**cython_freeze** - create a C file for embedding Cython modules
55

66

77
SYNOPSIS
88
========
9+
::
910

10-
cython_freeze [-o outfile] [-p] module [...]
11+
cython_freeze [-o outfile] [-p] module [...]
1112

1213

1314
DESCRIPTION
@@ -32,21 +33,20 @@ modules, but it requires another C source file to be created.
3233

3334
OPTIONS
3435
=======
36+
::
3537

36-
-o FILE, --outfile=FILE write output to FILE instead of standard output
37-
-p, --pymain do not automatically run the first module as __main__
38+
-o FILE, --outfile=FILE write output to FILE instead of standard output
39+
-p, --pymain do not automatically run the first module as __main__
3840

3941

4042
EXAMPLE
4143
=======
4244

43-
In the Demos/freeze directory, there exist two Cython modules:
45+
In the ``Demos/freeze`` directory, there exist two Cython modules:
4446

45-
lcmath.pyx
46-
A module that interfaces with the -lm library.
47+
* ``lcmath.pyx``: A module that interfaces with the -lm library.
4748

48-
combinatorics.pyx
49-
A module that implements n-choose-r using lcmath.
49+
* ``combinatorics.pyx``: A module that implements n-choose-r using lcmath.
5050

5151
Both modules have the Python idiom ``if __name__ == "__main__"``, which only
5252
execute if that module is the "main" module. If run as main, lcmath prints the

bin/cython_freeze

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Create a C file for embedding one or more Cython source files.
44
Requires Cython 0.11.2 (or perhaps newer).
55
6-
See Demos/freeze/README.txt for more details.
6+
See Demos/freeze/README.rst for more details.
77
"""
88
from __future__ import print_function
99

pyximport/README

-73
This file was deleted.

pyximport/README.rst

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Pyximport
2+
=========
3+
4+
Cython is a compiler. Therefore it is natural that people tend to go
5+
through an edit/compile/test cycle with Cython modules. But my personal
6+
opinion is that one of the deep insights in Python's implementation is
7+
that a language can be compiled (Python modules are compiled to .pyc)
8+
files and hide that compilation process from the end-user so that they
9+
do not have to worry about it. Pyximport does this for Cython modules.
10+
For instance if you write a Cython module called ``foo.pyx``, with
11+
Pyximport you can import it in a regular Python module like this::
12+
13+
import pyximport; pyximport.install()
14+
import foo
15+
16+
Doing so will result in the compilation of ``foo.pyx`` (with appropriate
17+
exceptions if it has an error in it).
18+
19+
If you would always like to import Cython files without building them
20+
specially, you can also add the first line above to your sitecustomize.py.
21+
That will install the hook every time you run Python. Then you can use
22+
Cython modules just with simple import statements. I like to test my
23+
Cython modules like this::
24+
25+
python -c "import foo"
26+
27+
See help(pyximport.install) to learn its options for controlling the
28+
default behavior of ``import`` and ``reload``.
29+
30+
Dependency Handling
31+
-------------------
32+
33+
In Pyximport 1.1 it is possible to declare that your module depends on
34+
multiple files, (likely ``.h`` and ``.pxd`` files). If your Cython module is
35+
named ``foo`` and thus has the filename ``foo.pyx`` then you should make
36+
another file in the same directory called ``foo.pyxdep``. The
37+
``modname.pyxdep`` file can be a list of filenames or ``globs`` (like
38+
``*.pxd`` or ``include/*.h``). Each filename or glob must be on a separate
39+
line. Pyximport will check the file date for each of those files before
40+
deciding whether to rebuild the module. In order to keep track of the
41+
fact that the dependency has been handled, Pyximport updates the
42+
modification time of your ``.pyx`` source file. Future versions may do
43+
something more sophisticated like informing distutils of the
44+
dependencies directly.
45+
46+
Limitations
47+
-----------
48+
Pyximport does not give you any control over how your Cython file is
49+
compiled. Usually the defaults are fine. You might run into problems if
50+
you wanted to write your program in half-C, half-Cython and build them
51+
into a single library. Pyximport 1.2 will probably do this.
52+
53+
Pyximport does not hide the Distutils/GCC warnings and errors generated
54+
by the import process. Arguably this will give you better feedback if
55+
something went wrong and why. And if nothing went wrong it will give you
56+
the warm fuzzy that pyximport really did rebuild your module as it was
57+
supposed to.
58+
59+
For further thought and discussion
60+
----------------------------------
61+
62+
``setup.py install`` does not modify ``sitecustomize.py`` for you. Should it?
63+
Modifying Python's "standard interpreter" behaviour may be more than
64+
most people expect of a package they install..
65+
66+
Pyximport puts your ``.c`` file beside your ``.pyx`` file (analogous to
67+
``.pyc`` beside ``.py``). But it puts the platform-specific binary in a
68+
build directory as per normal for Distutils. If I could wave a magic
69+
wand and get Cython or distutils or whoever to put the build directory I
70+
might do it but not necessarily: having it at the top level is VERY
71+
HELPFUL for debugging Cython problems.

0 commit comments

Comments
 (0)