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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
3c612380
Commit
3c612380
authored
Apr 10, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new script to compile+run Python files directly in Cython
parent
962d37ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
bin/cythonrun
bin/cythonrun
+66
-0
No files found.
bin/cythonrun
0 → 100755
View file @
3c612380
#!/usr/bin/env python
"""
Compile a Python script into an executable that embeds CPython and run it.
Requires CPython to be built as a shared library ('libpythonX.Y').
Basic usage:
python cythonrun somefile.py [ARGS]
"""
DEBUG
=
True
import
sys
import
os
import
subprocess
from
distutils
import
sysconfig
INCDIR
=
sysconfig
.
get_python_inc
()
LIBDIR1
=
sysconfig
.
get_config_var
(
'LIBDIR'
)
LIBDIR2
=
sysconfig
.
get_config_var
(
'LIBPL'
)
PYLIB
=
sysconfig
.
get_config_var
(
'LIBRARY'
)[
3
:
-
2
]
CC
=
sysconfig
.
get_config_var
(
'CC'
)
CFLAGS
=
sysconfig
.
get_config_var
(
'CFLAGS'
)
+
' '
+
os
.
environ
.
get
(
'CFLAGS'
,
''
)
LINKCC
=
sysconfig
.
get_config_var
(
'LINKCC'
)
LINKFORSHARED
=
sysconfig
.
get_config_var
(
'LINKFORSHARED'
)
LIBS
=
sysconfig
.
get_config_var
(
'LIBS'
)
SYSLIBS
=
sysconfig
.
get_config_var
(
'SYSLIBS'
)
def
runcmd
(
cmd
,
shell
=
True
):
cmd
=
' '
.
join
(
cmd
)
if
DEBUG
:
print
(
cmd
)
returncode
=
subprocess
.
call
(
cmd
,
shell
=
True
)
if
returncode
:
sys
.
exit
(
returncode
)
def
clink
(
basename
):
runcmd
([
LINKCC
,
'-o'
,
basename
,
basename
+
'.o'
,
'-L'
+
LIBDIR1
,
'-L'
+
LIBDIR2
,
'-l'
+
PYLIB
]
+
LIBS
.
split
()
+
SYSLIBS
.
split
()
+
LINKFORSHARED
.
split
())
def
ccompile
(
basename
):
runcmd
([
CC
,
'-c'
,
'-o'
,
basename
+
'.o'
,
basename
+
'.c'
,
'-I'
+
INCDIR
]
+
CFLAGS
.
split
())
def
cycompile
(
input_file
):
from
Cython.Compiler
import
Version
,
CmdLine
,
Main
options
,
sources
=
CmdLine
.
parse_command_line
([
'--embed'
,
input_file
])
if
DEBUG
:
print
(
'Using Cython %s to compile %s'
%
(
Version
.
version
,
input_file
))
result
=
Main
.
compile
(
sources
,
options
)
if
result
.
num_errors
>
0
:
sys
.
exit
(
1
)
def
exec_file
(
basename
,
*
args
):
runcmd
([
os
.
path
.
abspath
(
basename
)]
+
list
(
args
),
shell
=
False
)
def
main
(
input_file
,
*
args
):
basename
=
os
.
path
.
splitext
(
input_file
)[
0
]
cycompile
(
input_file
)
ccompile
(
basename
)
clink
(
basename
)
exec_file
(
basename
)
if
__name__
==
'__main__'
:
main
(
*
sys
.
argv
[
1
:])
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