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
ed6478f8
Commit
ed6478f8
authored
Dec 14, 2021
by
Matus Valo
Committed by
GitHub
Dec 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use cythonize() in pyximport (GH-4339)
Closes
https://github.com/cython/cython/issues/2304
parent
98fc9f1a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
14 deletions
+89
-14
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+2
-1
Cython/Distutils/build_ext.py
Cython/Distutils/build_ext.py
+26
-8
pyximport/pyxbuild.py
pyximport/pyxbuild.py
+5
-4
pyximport/pyximport.py
pyximport/pyximport.py
+2
-1
tests/pyximport/pyximport_pyimport_only.srctree
tests/pyximport/pyximport_pyimport_only.srctree
+19
-0
tests/pyximport/pyximport_pyxbld.srctree
tests/pyximport/pyximport_pyxbld.srctree
+35
-0
No files found.
Cython/Build/Dependencies.py
View file @
ed6478f8
...
...
@@ -1034,7 +1034,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
# setup for out of place build directory if enabled
if
build_dir
:
if
os
.
path
.
isabs
(
c_file
):
warnings
.
warn
(
"build_dir has no effect for absolute source paths"
)
c_file
=
os
.
path
.
splitdrive
(
c_file
)[
1
]
c_file
=
c_file
.
split
(
os
.
sep
,
1
)[
1
]
c_file
=
os
.
path
.
join
(
build_dir
,
c_file
)
dir
=
os
.
path
.
dirname
(
c_file
)
safe_makedirs_once
(
dir
)
...
...
Cython/Distutils/build_ext.py
View file @
ed6478f8
...
...
@@ -12,14 +12,32 @@ else:
class
new_build_ext
(
_build_ext
,
object
):
def
finalize_options
(
self
):
if
self
.
distribution
.
ext_modules
:
nthreads
=
getattr
(
self
,
'parallel'
,
None
)
# -j option in Py3.5+
nthreads
=
int
(
nthreads
)
if
nthreads
else
None
from
Cython.Build.Dependencies
import
cythonize
self
.
distribution
.
ext_modules
[:]
=
cythonize
(
self
.
distribution
.
ext_modules
,
nthreads
=
nthreads
,
force
=
self
.
force
)
super
(
new_build_ext
,
self
).
finalize_options
()
user_options
=
_build_ext
.
user_options
[:]
boolean_options
=
_build_ext
.
boolean_options
[:]
user_options
.
extend
([
(
'cython-c-in-temp'
,
None
,
"put generated C files in temp directory"
),
])
boolean_options
.
extend
([
'cython-c-in-temp'
])
def
initialize_options
(
self
):
_build_ext
.
initialize_options
(
self
)
self
.
cython_c_in_temp
=
0
def
build_extension
(
self
,
ext
):
from
Cython.Build.Dependencies
import
cythonize
if
self
.
cython_c_in_temp
:
build_dir
=
self
.
build_temp
else
:
build_dir
=
None
new_ext
=
cythonize
(
ext
,
force
=
self
.
force
,
quiet
=
self
.
verbose
==
0
,
build_dir
=
build_dir
)[
0
]
ext
.
sources
=
new_ext
.
sources
super
(
new_build_ext
,
self
).
build_extension
(
ext
)
# This will become new_build_ext in the future.
from
.old_build_ext
import
old_build_ext
as
build_ext
pyximport/pyxbuild.py
View file @
ed6478f8
...
...
@@ -10,7 +10,7 @@ from distutils.errors import DistutilsArgError, DistutilsError, CCompilerError
from
distutils.extension
import
Extension
from
distutils.util
import
grok_environment_error
try
:
from
Cython.Distutils.
old_build_ext
import
old
_build_ext
as
build_ext
from
Cython.Distutils.
build_ext
import
new
_build_ext
as
build_ext
HAS_CYTHON
=
True
except
ImportError
:
HAS_CYTHON
=
False
...
...
@@ -53,7 +53,10 @@ def pyx_to_dll(filename, ext=None, force_rebuild=0, build_in_temp=False, pyxbuil
quiet
=
"--verbose"
else
:
quiet
=
"--quiet"
args
=
[
quiet
,
"build_ext"
]
if
build_in_temp
:
args
=
[
quiet
,
"build_ext"
,
'--cython-c-in-temp'
]
else
:
args
=
[
quiet
,
"build_ext"
]
if
force_rebuild
:
args
.
append
(
"--force"
)
if
inplace
and
package_base_dir
:
...
...
@@ -65,8 +68,6 @@ def pyx_to_dll(filename, ext=None, force_rebuild=0, build_in_temp=False, pyxbuil
elif
'set_initial_path'
not
in
ext
.
cython_directives
:
ext
.
cython_directives
[
'set_initial_path'
]
=
'SOURCEFILE'
if
HAS_CYTHON
and
build_in_temp
:
args
.
append
(
"--pyrex-c-in-temp"
)
sargs
=
setup_args
.
copy
()
sargs
.
update
({
"script_name"
:
None
,
...
...
pyximport/pyximport.py
View file @
ed6478f8
...
...
@@ -351,11 +351,12 @@ class PyImporter(PyxImporter):
self
.
uncompilable_modules
=
{}
self
.
blocked_modules
=
[
'Cython'
,
'pyxbuild'
,
'pyximport.pyxbuild'
,
'distutils'
]
self
.
blocked_packages
=
[
'Cython.'
,
'distutils.'
]
def
find_module
(
self
,
fullname
,
package_path
=
None
):
if
fullname
in
sys
.
modules
:
return
None
if
fullname
.
startswith
(
'Cython.'
):
if
any
([
fullname
.
startswith
(
pkg
)
for
pkg
in
self
.
blocked_packages
]
):
return
None
if
fullname
in
self
.
blocked_modules
:
# prevent infinite recursion
...
...
tests/pyximport/pyximport_pyimport_only.srctree
0 → 100644
View file @
ed6478f8
PYTHON -c "import pyimport_test; pyimport_test.test()"
######## pyimport_test.py ########
import os.path
import pyximport
pyximport.install(pyximport=False, pyimport=True,
build_dir=os.path.join(os.path.dirname(__file__), "TEST_TMP"))
def test():
import mymodule
assert mymodule.test_string == "TEST"
assert not mymodule.__file__.rstrip('oc').endswith('.py'), mymodule.__file__
######## mymodule.py ########
test_string = "TEST"
tests/pyximport/pyximport_pyxbld.srctree
0 → 100644
View file @
ed6478f8
PYTHON -c "import basic_test; basic_test.test()"
######## basic_test.py ########
import os.path
import pyximport
pyximport.install(build_dir=os.path.join(os.path.dirname(__file__), "TEST_TMP"))
def test():
import mymodule
assert mymodule.test_string == "TEST"
assert mymodule.header_value == 5
assert not mymodule.__file__.rstrip('oc').endswith('.py'), mymodule.__file__
######## mymodule.pyxbld ########
def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name = modname,
sources=[pyxfilename],
include_dirs=['./headers'] )
######## mymodule.pyx ########
cdef extern from "myheader.h":
int test_value
header_value = test_value
test_string = "TEST"
######## headers/myheader.h ########
static int test_value = 5;
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