Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/misc/cython_c.pyx
4079 views
1
import sage.misc.misc
2
import sage.server.support
3
4
def cython(code,
5
verbose=False, compile_message=False,
6
make_c_file_nice=False, use_cache=False):
7
"""
8
Given a block of Cython code (as a text string), this function
9
compiles it using a C compiler, and includes it into the global
10
scope of the module that called this function.
11
12
The following pragmas are available:
13
14
- ``clang`` - may be either c or c++ (or C or C++) indicating
15
whether a C or C++ compiler should be used.
16
17
- ``clib`` - additional libraries to be linked in, the space
18
separated list is split and passed to distutils.
19
20
- ``cinclude`` - additional directories to search for header
21
files. The space separated list is split and passed to
22
distutils.
23
24
- ``cfile`` - additional C or C++ files to be compiled. Also,
25
``$SAGE_ROOT`` is expanded, but other environment variables
26
are not.
27
28
- ``cargs`` - additional parameters passed to the compiler
29
30
For example::
31
32
#clang C++
33
#clib givaro
34
#cinclude /usr/local/include/
35
#cargs -ggdb
36
#cfile foo.c
37
38
AUTHOR: William Stein, 2006-10-31
39
40
.. warn:
41
42
Only use this from Python code, not from extension code, since
43
from extension code you would change the global scope (i.e.,
44
of the Sage interpreter). And it would be stupid, since you're
45
already writing Cython!
46
47
Also, never use this in the standard Sage library. Any code
48
that uses this can only run on a system that has a C compiler
49
installed, and we want to avoid making that assumption for
50
casual Sage usage. Also, any code that uses this in the
51
library would greatly slow down startup time, since currently
52
there is no caching.
53
54
.. todo:
55
56
Need to create a clever caching system so code only gets
57
compiled once.
58
"""
59
tmpfile = sage.misc.misc.tmp_filename() + ".spyx"
60
open(tmpfile,'w').write(code)
61
sage.server.support.cython_import_all(tmpfile, globals(),
62
verbose=verbose, compile_message=compile_message,
63
use_cache=use_cache,
64
create_local_c_file=False)
65
66
67
68