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
0bc88c6c
Commit
0bc88c6c
authored
Apr 26, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compile imported module conditionally for faster development based on version
parent
7ecf30ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
43 deletions
+9
-43
Cython/Compiler/Importer.py
Cython/Compiler/Importer.py
+9
-43
No files found.
Cython/Compiler/Importer.py
View file @
0bc88c6c
...
...
@@ -11,48 +11,7 @@ import imp
import
pyximport
# set up the PyxArgs global variable in pyximport (why is that a global :)
importers
=
pyximport
.
install
(
pyimport
=
True
)
pyximport
.
uninstall
(
*
importers
)
def
_import_normal
(
modulename
):
# __import__ does not take keyword arguments under 2.4
return
__import__
(
modulename
,
None
,
None
,
[
''
])
def
_import_compile
(
modulename
):
if
'.'
in
modulename
:
packagename
,
modulename
=
modulename
.
rsplit
(
'.'
,
1
)
__path__
=
_import_normal
(
packagename
).
__path__
else
:
__path__
=
None
file
,
filename
,
description
=
imp
.
find_module
(
modulename
,
__path__
)
if
file
:
file
.
close
()
else
:
raise
ImportError
(
modulename
)
return
pyximport
.
load_module
(
modulename
,
filename
)
def
importer
(
modulename
,
compile
=
False
,
version
=
None
):
"""
Import a module. If compile is true, always try to compile the .py file.
Otherwise, try a regular import and if that fails (i.e. there is a
syntax error, try to compile it.
"""
if
version
is
not
None
and
sys
.
version_info
[:
2
]
>=
version
and
not
compile
:
return
_import_normal
(
modulename
)
if
compile
:
return
_import_compile
(
modulename
)
else
:
try
:
return
_import_normal
(
modulename
)
except
SyntaxError
:
return
_import_compile
(
modulename
)
def
importer
(
modulename
):
def
importer
(
modulename
,
version
=
None
):
try
:
# Check for an already compiled module
return
__import__
(
modulename
,
None
,
None
,
[
''
])
...
...
@@ -62,4 +21,11 @@ def importer(modulename):
dirname
=
os
.
path
.
dirname
root
=
dirname
(
dirname
(
dirname
(
os
.
path
.
abspath
(
__file__
))))
filename
=
os
.
path
.
join
(
root
,
*
modulename
.
split
(
'.'
))
+
".pyx"
return
pyximport
.
load_module
(
modulename
,
filename
)
\ No newline at end of file
if
version
and
version
<
sys
.
version_info
[:
2
]:
return
pyximport
.
load_module
(
modulename
,
filename
)
else
:
mod
=
imp
.
new_module
(
modulename
)
exec
open
(
filename
).
read
()
in
mod
.
__dict__
,
mod
.
__dict__
sys
.
modules
[
modulename
]
=
mod
return
mod
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