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
0db6c709
Commit
0db6c709
authored
Jul 26, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't reload inline module if it's already loaded.
parent
ab740487
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
46 deletions
+51
-46
Cython/Build/Inline.py
Cython/Build/Inline.py
+51
-46
No files found.
Cython/Build/Inline.py
View file @
0db6c709
...
@@ -146,59 +146,64 @@ def cython_inline(code,
...
@@ -146,59 +146,64 @@ def cython_inline(code,
arg_sigs
=
tuple
([(
get_type
(
kwds
[
arg
],
ctx
),
arg
)
for
arg
in
arg_names
])
arg_sigs
=
tuple
([(
get_type
(
kwds
[
arg
],
ctx
),
arg
)
for
arg
in
arg_names
])
key
=
orig_code
,
arg_sigs
,
sys
.
version_info
,
sys
.
executable
,
Cython
.
__version__
key
=
orig_code
,
arg_sigs
,
sys
.
version_info
,
sys
.
executable
,
Cython
.
__version__
module_name
=
"_cython_inline_"
+
hashlib
.
md5
(
str
(
key
).
encode
(
'utf-8'
)).
hexdigest
()
module_name
=
"_cython_inline_"
+
hashlib
.
md5
(
str
(
key
).
encode
(
'utf-8'
)).
hexdigest
()
if
module_name
in
sys
.
modules
:
module
=
sys
.
modules
[
module_name
]
else
:
build_extension
=
None
if
cython_inline
.
so_ext
is
None
:
# Figure out and cache current extension suffix
build_extension
=
_get_build_extension
()
cython_inline
.
so_ext
=
build_extension
.
get_ext_filename
(
''
)
build_extension
=
None
module_path
=
os
.
path
.
join
(
lib_dir
,
module_name
+
cython_inline
.
so_ext
)
if
cython_inline
.
so_ext
is
None
:
# Figure out and cache current extension suffix
build_extension
=
_get_build_extension
()
cython_inline
.
so_ext
=
build_extension
.
get_ext_filename
(
''
)
module_path
=
os
.
path
.
join
(
lib_dir
,
module_name
+
cython_inline
.
so_ext
)
if
not
os
.
path
.
exists
(
lib_dir
):
if
not
os
.
path
.
exists
(
lib_dir
):
os
.
makedirs
(
lib_dir
)
os
.
makedirs
(
lib_dir
)
if
force
or
not
os
.
path
.
isfile
(
module_path
):
if
force
or
not
os
.
path
.
isfile
(
module_path
):
cflags
=
[]
cflags
=
[]
c_include_dirs
=
[]
c_include_dirs
=
[]
qualified
=
re
.
compile
(
r'([.\
w]+)[.]
')
qualified
=
re
.
compile
(
r'([.\
w]+)[.]
')
for type, _ in arg_sigs:
for type, _ in arg_sigs:
m = qualified.match(type)
m = qualified.match(type)
if m:
if m:
cimports.append('
\
ncimport
%
s
' % m.groups()[0])
cimports.append('
\
ncimport
%
s
' % m.groups()[0])
# one special case
# one special case
if m.groups()[0] == '
numpy
':
if m.groups()[0] == '
numpy
':
import numpy
import numpy
c_include_dirs.append(numpy.get_include())
c_include_dirs.append(numpy.get_include())
# cflags.append('
-
Wno
-
unused
')
# cflags.append('
-
Wno
-
unused
')
module_body, func_body = extract_func_code(code)
module_body, func_body = extract_func_code(code)
params = '
,
'.join(['
%
s
%
s
' % a for a in arg_sigs])
params = '
,
'.join(['
%
s
%
s
' % a for a in arg_sigs])
module_code = """
module_code = """
%(module_body)s
%(module_body)s
%(cimports)s
%(cimports)s
def __invoke(%(params)s):
def __invoke(%(params)s):
%(func_body)s
%(func_body)s
""" % {'
cimports
': '
\
n
'.join(cimports), '
module_body
': module_body, '
params
': params, '
func_body
': func_body }
""" % {'
cimports
': '
\
n
'.join(cimports), '
module_body
': module_body, '
params
': params, '
func_body
': func_body }
for key, value in literals.items():
for key, value in literals.items():
module_code = module_code.replace(key, value)
module_code = module_code.replace(key, value)
pyx_file = os.path.join(lib_dir, module_name + '
.
pyx
')
pyx_file = os.path.join(lib_dir, module_name + '
.
pyx
')
fh = open(pyx_file, '
w
')
fh = open(pyx_file, '
w
')
try:
try:
fh.write(module_code)
fh.write(module_code)
finally:
finally:
fh.close()
fh.close()
extension = Extension(
extension = Extension(
name = module_name,
name = module_name,
sources = [pyx_file],
sources = [pyx_file],
include_dirs = c_include_dirs,
include_dirs = c_include_dirs,
extra_compile_args = cflags)
extra_compile_args = cflags)
if build_extension is None:
if build_extension is None:
build_extension = _get_build_extension()
build_extension = _get_build_extension()
build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet)
build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet)
build_extension.build_temp = os.path.dirname(pyx_file)
build_extension.build_temp = os.path.dirname(pyx_file)
build_extension.build_lib = lib_dir
build_extension.build_lib = lib_dir
build_extension.run()
build_extension.run()
module = imp.load_dynamic(module_name, module_path)
module = imp.load_dynamic(module_name, module_path)
arg_list = [kwds[arg] for arg in arg_names]
arg_list = [kwds[arg] for arg in arg_names]
return module.__invoke(*arg_list)
return module.__invoke(*arg_list)
...
...
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