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
f187dd7f
Commit
f187dd7f
authored
Nov 04, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extended stdlib compilation script that special cases some tricky modules
parent
11204636
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
28 deletions
+100
-28
Tools/cystdlib.py
Tools/cystdlib.py
+100
-28
No files found.
Tools/cystdlib.py
View file @
f187dd7f
"""
Highly experimental script that compiles the CPython standard library using Cython.
Execute the script either in the CPython 'Lib' directory or pass the
option '--current-python' to compile the standard library of the running
Python interpreter.
Pass '--parallel' to get a parallel build.
Usage example::
$ python cystdlib.py --current-python build_ext -i
"""
import
sys
from
distutils.core
import
setup
from
distutils.core
import
setup
from
Cython.Build
import
cythonize
from
Cython.Build
import
cythonize
from
Cython.Compiler
import
Options
from
Cython.Compiler
import
Options
import
sys
# improve Python compatibility by allowing some broken code
pyver
=
sys
.
version_info
[
0
]
Options
.
error_on_unknown_names
=
False
try
:
excludes
=
[
'**/test/**/*.py'
,
'**/tests/**/*.py'
,
'**/__init__.py'
]
broken
=
[
'idlelib/MultiCall.py'
,
'email/utils.py'
,
'multiprocessing/reduction.py'
,
'multiprocessing/util.py'
,
]
default_directives
=
dict
(
auto_cpdef
=
True
)
special_directives
=
[
([
'pkgutil.py'
],
dict
(
auto_cpdef
=
False
)),
]
def
build_extensions
(
includes
=
'**/*.py'
,
excludes
=
excludes
+
broken
,
special_directives
=
special_directives
,
parallel
=
None
):
if
isinstance
(
includes
,
str
):
includes
=
[
includes
]
all_groups
=
(
special_directives
or
[])
+
[(
includes
,
{})]
extensions
=
[]
for
modules
,
directives
in
all_groups
:
exclude_now
=
excludes
[:]
for
other_modules
,
_
in
special_directives
:
if
other_modules
!=
modules
:
exclude_now
.
extend
(
other_modules
)
d
=
dict
(
default_directives
)
d
.
update
(
directives
)
extensions
.
extend
(
cythonize
(
modules
,
exclude
=
exclude_now
,
exclude_failures
=
True
,
language_level
=
pyver
,
compiler_directives
=
d
,
nthreads
=
parallel
,
))
return
extensions
def
build
(
extensions
):
try
:
setup
(
name
=
'stuff'
,
ext_modules
=
extensions
)
return
extensions
,
True
except
:
import
traceback
print
(
'error building extensions %s'
%
(
extensions
,))
traceback
.
print_exc
()
return
extensions
,
False
def
_build
(
args
):
sys_args
,
ext
=
args
sys
.
argv
[
1
:]
=
sys_args
return
build
([
ext
])
if
__name__
==
'__main__'
:
import
sys
pyver
=
sys
.
version_info
[
0
]
try
:
sys
.
argv
.
remove
(
'--current-python'
)
sys
.
argv
.
remove
(
'--current-python'
)
except
ValueError
:
except
ValueError
:
pass
pass
else
:
else
:
# assume that the stdlib is where the "os" module lives
# assume that the stdlib is where the "os" module lives
import
os
import
os
os
.
chdir
(
os
.
path
.
dirname
(
os
.
__file__
))
os
.
chdir
(
os
.
path
.
dirname
(
os
.
__file__
))
try
:
try
:
sys
.
argv
.
remove
(
'--parallel'
)
sys
.
argv
.
remove
(
'--parallel'
)
import
multiprocessing
import
multiprocessing
parallel_compiles
=
multiprocessing
.
cpu_count
()
*
2
parallel_compiles
=
multiprocessing
.
cpu_count
()
*
2
except
(
ValueError
,
ImportError
):
print
(
"Building in %d parallel processes"
%
parallel_compiles
)
except
(
ValueError
,
ImportError
):
parallel_compiles
=
None
parallel_compiles
=
None
# improve Python compatibility by allowing some broken code
extensions
=
build_extensions
(
parallel
=
parallel_compiles
)
Options
.
error_on_unknown_names
=
False
if
parallel_compiles
:
pool
=
multiprocessing
.
Pool
(
parallel_compiles
)
excludes
=
[
'**/test/**/*.py'
,
'**/tests/**/*.py'
,
'**/__init__.py'
]
sys_args
=
sys
.
argv
[
1
:]
results
=
pool
.
map
(
_build
,
[
(
sys_args
,
ext
)
for
ext
in
extensions
])
default_directives
=
dict
(
auto_cpdef
=
True
)
pool
.
close
()
pool
.
join
()
setup
(
for
ext
,
result
in
results
:
name
=
'stuff'
,
if
not
result
:
ext_modules
=
cythonize
([
"**/*.py"
],
print
(
"building extension %s failed"
%
(
ext
[
0
],))
exclude
=
excludes
,
else
:
exclude_failures
=
True
,
build
(
extensions
)
language_level
=
pyver
,
# compiler_directives=dict(auto_cpdef=True),
nthreads
=
parallel_compiles
,
),
)
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