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
Kirill Smelkov
cython
Commits
eaf2ce5d
Commit
eaf2ce5d
authored
Nov 14, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up some code
parent
4c21a8f1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
Cython/Build/Inline.py
Cython/Build/Inline.py
+7
-1
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+4
-0
pyximport/pyximport.py
pyximport/pyximport.py
+19
-2
No files found.
Cython/Build/Inline.py
View file @
eaf2ce5d
...
@@ -48,6 +48,7 @@ class UnboundSymbols(EnvTransform, SkipDeclarations):
...
@@ -48,6 +48,7 @@ class UnboundSymbols(EnvTransform, SkipDeclarations):
super
(
UnboundSymbols
,
self
).
__call__
(
node
)
super
(
UnboundSymbols
,
self
).
__call__
(
node
)
return
self
.
unbound
return
self
.
unbound
@
cached_function
@
cached_function
def
unbound_symbols
(
code
,
context
=
None
):
def
unbound_symbols
(
code
,
context
=
None
):
code
=
to_unicode
(
code
)
code
=
to_unicode
(
code
)
...
@@ -67,6 +68,7 @@ def unbound_symbols(code, context=None):
...
@@ -67,6 +68,7 @@ def unbound_symbols(code, context=None):
import
__builtin__
as
builtins
import
__builtin__
as
builtins
return
UnboundSymbols
()(
tree
)
-
set
(
dir
(
builtins
))
return
UnboundSymbols
()(
tree
)
-
set
(
dir
(
builtins
))
def
unsafe_type
(
arg
,
context
=
None
):
def
unsafe_type
(
arg
,
context
=
None
):
py_type
=
type
(
arg
)
py_type
=
type
(
arg
)
if
py_type
is
int
:
if
py_type
is
int
:
...
@@ -74,6 +76,7 @@ def unsafe_type(arg, context=None):
...
@@ -74,6 +76,7 @@ def unsafe_type(arg, context=None):
else
:
else
:
return
safe_type
(
arg
,
context
)
return
safe_type
(
arg
,
context
)
def
safe_type
(
arg
,
context
=
None
):
def
safe_type
(
arg
,
context
=
None
):
py_type
=
type
(
arg
)
py_type
=
type
(
arg
)
if
py_type
in
[
list
,
tuple
,
dict
,
str
]:
if
py_type
in
[
list
,
tuple
,
dict
,
str
]:
...
@@ -97,6 +100,7 @@ def safe_type(arg, context=None):
...
@@ -97,6 +100,7 @@ def safe_type(arg, context=None):
return
'%s.%s'
%
(
base_type
.
__module__
,
base_type
.
__name__
)
return
'%s.%s'
%
(
base_type
.
__module__
,
base_type
.
__name__
)
return
'object'
return
'object'
def
_get_build_extension
():
def
_get_build_extension
():
dist
=
Distribution
()
dist
=
Distribution
()
# Ensure the build respects distutils configuration by parsing
# Ensure the build respects distutils configuration by parsing
...
@@ -107,6 +111,7 @@ def _get_build_extension():
...
@@ -107,6 +111,7 @@ def _get_build_extension():
build_extension
.
finalize_options
()
build_extension
.
finalize_options
()
return
build_extension
return
build_extension
@
cached_function
@
cached_function
def
_create_context
(
cython_include_dirs
):
def
_create_context
(
cython_include_dirs
):
return
Context
(
list
(
cython_include_dirs
),
default_options
)
return
Context
(
list
(
cython_include_dirs
),
default_options
)
...
@@ -263,7 +268,6 @@ def extract_func_code(code):
...
@@ -263,7 +268,6 @@ def extract_func_code(code):
return
'
\
n
'
.
join
(
module
),
' '
+
'
\
n
'
.
join
(
function
)
return
'
\
n
'
.
join
(
module
),
' '
+
'
\
n
'
.
join
(
function
)
try
:
try
:
from
inspect
import
getcallargs
from
inspect
import
getcallargs
except
ImportError
:
except
ImportError
:
...
@@ -294,6 +298,7 @@ except ImportError:
...
@@ -294,6 +298,7 @@ except ImportError:
raise
TypeError
(
"Missing argument: %s"
%
name
)
raise
TypeError
(
"Missing argument: %s"
%
name
)
return
all
return
all
def
get_body
(
source
):
def
get_body
(
source
):
ix
=
source
.
index
(
':'
)
ix
=
source
.
index
(
':'
)
if
source
[:
5
]
==
'lambda'
:
if
source
[:
5
]
==
'lambda'
:
...
@@ -301,6 +306,7 @@ def get_body(source):
...
@@ -301,6 +306,7 @@ def get_body(source):
else
:
else
:
return
source
[
ix
+
1
:]
return
source
[
ix
+
1
:]
# Lots to be done here... It would be especially cool if compiled functions
# Lots to be done here... It would be especially cool if compiled functions
# could invoke each other quickly.
# could invoke each other quickly.
class
RuntimeCompiledFunction
(
object
):
class
RuntimeCompiledFunction
(
object
):
...
...
Cython/Compiler/TreeFragment.py
View file @
eaf2ce5d
...
@@ -86,6 +86,7 @@ def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None,
...
@@ -86,6 +86,7 @@ def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None,
tree
.
scope
=
scope
tree
.
scope
=
scope
return
tree
return
tree
class
TreeCopier
(
VisitorTransform
):
class
TreeCopier
(
VisitorTransform
):
def
visit_Node
(
self
,
node
):
def
visit_Node
(
self
,
node
):
if
node
is
None
:
if
node
is
None
:
...
@@ -95,6 +96,7 @@ class TreeCopier(VisitorTransform):
...
@@ -95,6 +96,7 @@ class TreeCopier(VisitorTransform):
self
.
visitchildren
(
c
)
self
.
visitchildren
(
c
)
return
c
return
c
class
ApplyPositionAndCopy
(
TreeCopier
):
class
ApplyPositionAndCopy
(
TreeCopier
):
def
__init__
(
self
,
pos
):
def
__init__
(
self
,
pos
):
super
(
ApplyPositionAndCopy
,
self
).
__init__
()
super
(
ApplyPositionAndCopy
,
self
).
__init__
()
...
@@ -105,6 +107,7 @@ class ApplyPositionAndCopy(TreeCopier):
...
@@ -105,6 +107,7 @@ class ApplyPositionAndCopy(TreeCopier):
copy
.
pos
=
self
.
pos
copy
.
pos
=
self
.
pos
return
copy
return
copy
class
TemplateTransform
(
VisitorTransform
):
class
TemplateTransform
(
VisitorTransform
):
"""
"""
Makes a copy of a template tree while doing substitutions.
Makes a copy of a template tree while doing substitutions.
...
@@ -247,6 +250,7 @@ class TreeFragment(object):
...
@@ -247,6 +250,7 @@ class TreeFragment(object):
substitutions
=
nodes
,
substitutions
=
nodes
,
temps
=
self
.
temps
+
temps
,
pos
=
pos
)
temps
=
self
.
temps
+
temps
,
pos
=
pos
)
class
SetPosTransform
(
VisitorTransform
):
class
SetPosTransform
(
VisitorTransform
):
def
__init__
(
self
,
pos
):
def
__init__
(
self
,
pos
):
super
(
SetPosTransform
,
self
).
__init__
()
super
(
SetPosTransform
,
self
).
__init__
()
...
...
pyximport/pyximport.py
View file @
eaf2ce5d
...
@@ -62,19 +62,23 @@ PYXBLD_EXT = ".pyxbld"
...
@@ -62,19 +62,23 @@ PYXBLD_EXT = ".pyxbld"
DEBUG_IMPORT
=
False
DEBUG_IMPORT
=
False
def
_print
(
message
,
args
):
def
_print
(
message
,
args
):
if
args
:
if
args
:
message
=
message
%
args
message
=
message
%
args
print
(
message
)
print
(
message
)
def
_debug
(
message
,
*
args
):
def
_debug
(
message
,
*
args
):
if
DEBUG_IMPORT
:
if
DEBUG_IMPORT
:
_print
(
message
,
args
)
_print
(
message
,
args
)
def
_info
(
message
,
*
args
):
def
_info
(
message
,
*
args
):
_print
(
message
,
args
)
_print
(
message
,
args
)
# Performance problem: for every PYX file that is imported, we will
# Performance problem: for every PYX file that is imported, we will
# invoke the whole distutils infrastructure even if the module is
# invoke the whole distutils infrastructure even if the module is
# already built. It might be more efficient to only do it when the
# already built. It might be more efficient to only do it when the
# mod time of the .pyx is newer than the mod time of the .so but
# mod time of the .pyx is newer than the mod time of the .so but
...
@@ -84,6 +88,7 @@ def _info(message, *args):
...
@@ -84,6 +88,7 @@ def _info(message, *args):
def
_load_pyrex
(
name
,
filename
):
def
_load_pyrex
(
name
,
filename
):
"Load a pyrex file given a name and filename."
"Load a pyrex file given a name and filename."
def
get_distutils_extension
(
modname
,
pyxfilename
,
language_level
=
None
):
def
get_distutils_extension
(
modname
,
pyxfilename
,
language_level
=
None
):
# try:
# try:
# import hashlib
# import hashlib
...
@@ -103,6 +108,7 @@ def get_distutils_extension(modname, pyxfilename, language_level=None):
...
@@ -103,6 +108,7 @@ def get_distutils_extension(modname, pyxfilename, language_level=None):
extension_mod
.
cython_directives
=
{
'language_level'
:
language_level
}
extension_mod
.
cython_directives
=
{
'language_level'
:
language_level
}
return
extension_mod
,
setup_args
return
extension_mod
,
setup_args
def
handle_special_build
(
modname
,
pyxfilename
):
def
handle_special_build
(
modname
,
pyxfilename
):
special_build
=
os
.
path
.
splitext
(
pyxfilename
)[
0
]
+
PYXBLD_EXT
special_build
=
os
.
path
.
splitext
(
pyxfilename
)[
0
]
+
PYXBLD_EXT
ext
=
None
ext
=
None
...
@@ -129,6 +135,7 @@ def handle_special_build(modname, pyxfilename):
...
@@ -129,6 +135,7 @@ def handle_special_build(modname, pyxfilename):
for
source
in
ext
.
sources
]
for
source
in
ext
.
sources
]
return
ext
,
setup_args
return
ext
,
setup_args
def
handle_dependencies
(
pyxfilename
):
def
handle_dependencies
(
pyxfilename
):
testing
=
'_test_files'
in
globals
()
testing
=
'_test_files'
in
globals
()
dependfile
=
os
.
path
.
splitext
(
pyxfilename
)[
0
]
+
PYXDEP_EXT
dependfile
=
os
.
path
.
splitext
(
pyxfilename
)[
0
]
+
PYXDEP_EXT
...
@@ -166,6 +173,7 @@ def handle_dependencies(pyxfilename):
...
@@ -166,6 +173,7 @@ def handle_dependencies(pyxfilename):
if
testing
:
if
testing
:
_test_files
.
append
(
file
)
_test_files
.
append
(
file
)
def
build_module
(
name
,
pyxfilename
,
pyxbuild_dir
=
None
,
inplace
=
False
,
language_level
=
None
):
def
build_module
(
name
,
pyxfilename
,
pyxbuild_dir
=
None
,
inplace
=
False
,
language_level
=
None
):
assert
os
.
path
.
exists
(
pyxfilename
),
(
assert
os
.
path
.
exists
(
pyxfilename
),
(
"Path does not exist: %s"
%
pyxfilename
)
"Path does not exist: %s"
%
pyxfilename
)
...
@@ -197,6 +205,7 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l
...
@@ -197,6 +205,7 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l
return
so_path
return
so_path
def
load_module
(
name
,
pyxfilename
,
pyxbuild_dir
=
None
,
is_package
=
False
,
def
load_module
(
name
,
pyxfilename
,
pyxbuild_dir
=
None
,
is_package
=
False
,
build_inplace
=
False
,
language_level
=
None
,
so_path
=
None
):
build_inplace
=
False
,
language_level
=
None
,
so_path
=
None
):
try
:
try
:
...
@@ -314,6 +323,7 @@ class PyxImporter(object):
...
@@ -314,6 +323,7 @@ class PyxImporter(object):
_debug
(
"%s not found"
%
fullname
)
_debug
(
"%s not found"
%
fullname
)
return
None
return
None
class
PyImporter
(
PyxImporter
):
class
PyImporter
(
PyxImporter
):
"""A meta-path importer for normal .py files.
"""A meta-path importer for normal .py files.
"""
"""
...
@@ -384,6 +394,7 @@ class PyImporter(PyxImporter):
...
@@ -384,6 +394,7 @@ class PyImporter(PyxImporter):
self
.
blocked_modules
.
pop
()
self
.
blocked_modules
.
pop
()
return
importer
return
importer
class
LibLoader
(
object
):
class
LibLoader
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
_libs
=
{}
self
.
_libs
=
{}
...
@@ -404,6 +415,7 @@ class LibLoader(object):
...
@@ -404,6 +415,7 @@ class LibLoader(object):
_lib_loader
=
LibLoader
()
_lib_loader
=
LibLoader
()
class
PyxLoader
(
object
):
class
PyxLoader
(
object
):
def
__init__
(
self
,
fullname
,
path
,
init_path
=
None
,
pyxbuild_dir
=
None
,
def
__init__
(
self
,
fullname
,
path
,
init_path
=
None
,
pyxbuild_dir
=
None
,
inplace
=
False
,
language_level
=
None
):
inplace
=
False
,
language_level
=
None
):
...
@@ -442,7 +454,8 @@ class PyxArgs(object):
...
@@ -442,7 +454,8 @@ class PyxArgs(object):
build_in_temp
=
True
build_in_temp
=
True
setup_args
=
{}
#None
setup_args
=
{}
#None
##pyxargs=None
##pyxargs=None
def
_have_importers
():
def
_have_importers
():
has_py_importer
=
False
has_py_importer
=
False
...
@@ -456,6 +469,7 @@ def _have_importers():
...
@@ -456,6 +469,7 @@ def _have_importers():
return
has_py_importer
,
has_pyx_importer
return
has_py_importer
,
has_pyx_importer
def
install
(
pyximport
=
True
,
pyimport
=
False
,
build_dir
=
None
,
build_in_temp
=
True
,
def
install
(
pyximport
=
True
,
pyimport
=
False
,
build_dir
=
None
,
build_in_temp
=
True
,
setup_args
=
{},
reload_support
=
False
,
setup_args
=
{},
reload_support
=
False
,
load_py_module_on_import_failure
=
False
,
inplace
=
False
,
load_py_module_on_import_failure
=
False
,
inplace
=
False
,
...
@@ -532,6 +546,7 @@ def install(pyximport=True, pyimport=False, build_dir=None, build_in_temp=True,
...
@@ -532,6 +546,7 @@ def install(pyximport=True, pyimport=False, build_dir=None, build_in_temp=True,
return
py_importer
,
pyx_importer
return
py_importer
,
pyx_importer
def
uninstall
(
py_importer
,
pyx_importer
):
def
uninstall
(
py_importer
,
pyx_importer
):
"""
"""
Uninstall an import hook.
Uninstall an import hook.
...
@@ -546,6 +561,7 @@ def uninstall(py_importer, pyx_importer):
...
@@ -546,6 +561,7 @@ def uninstall(py_importer, pyx_importer):
except
ValueError
:
except
ValueError
:
pass
pass
# MAIN
# MAIN
def
show_docs
():
def
show_docs
():
...
@@ -559,5 +575,6 @@ def show_docs():
...
@@ -559,5 +575,6 @@ def show_docs():
pass
pass
help
(
__main__
)
help
(
__main__
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
show_docs
()
show_docs
()
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