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
2cc9535e
Commit
2cc9535e
authored
Feb 10, 2019
by
Brock Mendel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REF: make Utils dependency-free by moving search_include_directories to Main
parent
e80bbb3e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
49 deletions
+55
-49
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+55
-1
Cython/Utils.py
Cython/Utils.py
+0
-48
No files found.
Cython/Compiler/Main.py
View file @
2cc9535e
...
@@ -265,7 +265,7 @@ class Context(object):
...
@@ -265,7 +265,7 @@ class Context(object):
def
search_include_directories
(
self
,
qualified_name
,
suffix
,
pos
,
def
search_include_directories
(
self
,
qualified_name
,
suffix
,
pos
,
include
=
False
,
sys_path
=
False
):
include
=
False
,
sys_path
=
False
):
return
Utils
.
search_include_directories
(
return
search_include_directories
(
tuple
(
self
.
include_directories
),
qualified_name
,
suffix
,
pos
,
include
,
sys_path
)
tuple
(
self
.
include_directories
),
qualified_name
,
suffix
,
pos
,
include
,
sys_path
)
def
find_root_package_dir
(
self
,
file_path
):
def
find_root_package_dir
(
self
,
file_path
):
...
@@ -753,6 +753,60 @@ def compile(source, options = None, full_module_name = None, **kwds):
...
@@ -753,6 +753,60 @@ def compile(source, options = None, full_module_name = None, **kwds):
return
compile_multiple
(
source
,
options
)
return
compile_multiple
(
source
,
options
)
@
Utils
.
cached_function
def
search_include_directories
(
dirs
,
qualified_name
,
suffix
,
pos
,
include
=
False
,
sys_path
=
False
):
"""
Search the list of include directories for the given file name.
If a source file position is given, first searches the directory
containing that file. Returns None if not found, but does not
report an error.
The 'include' option will disable package dereferencing.
If 'sys_path' is True, also search sys.path.
"""
if
sys_path
:
dirs
=
dirs
+
tuple
(
sys
.
path
)
if
pos
:
file_desc
=
pos
[
0
]
if
not
isinstance
(
file_desc
,
FileSourceDescriptor
):
raise
RuntimeError
(
"Only file sources for code supported"
)
if
include
:
dirs
=
(
os
.
path
.
dirname
(
file_desc
.
filename
),)
+
dirs
else
:
dirs
=
(
Utils
.
find_root_package_dir
(
file_desc
.
filename
),)
+
dirs
dotted_filename
=
qualified_name
if
suffix
:
dotted_filename
+=
suffix
if
not
include
:
names
=
qualified_name
.
split
(
'.'
)
package_names
=
tuple
(
names
[:
-
1
])
module_name
=
names
[
-
1
]
module_filename
=
module_name
+
suffix
package_filename
=
"__init__"
+
suffix
for
dirname
in
dirs
:
path
=
os
.
path
.
join
(
dirname
,
dotted_filename
)
if
os
.
path
.
exists
(
path
):
return
path
if
not
include
:
package_dir
=
Utils
.
check_package_dir
(
dirname
,
package_names
)
if
package_dir
is
not
None
:
path
=
os
.
path
.
join
(
package_dir
,
module_filename
)
if
os
.
path
.
exists
(
path
):
return
path
path
=
os
.
path
.
join
(
dirname
,
package_dir
,
module_name
,
package_filename
)
if
os
.
path
.
exists
(
path
):
return
path
return
None
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
#
#
# Main command-line entry point
# Main command-line entry point
...
...
Cython/Utils.py
View file @
2cc9535e
...
@@ -135,54 +135,6 @@ def copy_file_to_dir_if_newer(sourcefile, destdir):
...
@@ -135,54 +135,6 @@ def copy_file_to_dir_if_newer(sourcefile, destdir):
shutil
.
copy2
(
sourcefile
,
destfile
)
shutil
.
copy2
(
sourcefile
,
destfile
)
@
cached_function
def
search_include_directories
(
dirs
,
qualified_name
,
suffix
,
pos
,
include
=
False
,
sys_path
=
False
):
# Search the list of include directories for the given
# file name. If a source file position is given, first
# searches the directory containing that file. Returns
# None if not found, but does not report an error.
# The 'include' option will disable package dereferencing.
# If 'sys_path' is True, also search sys.path.
if
sys_path
:
dirs
=
dirs
+
tuple
(
sys
.
path
)
if
pos
:
file_desc
=
pos
[
0
]
from
Cython.Compiler.Scanning
import
FileSourceDescriptor
if
not
isinstance
(
file_desc
,
FileSourceDescriptor
):
raise
RuntimeError
(
"Only file sources for code supported"
)
if
include
:
dirs
=
(
os
.
path
.
dirname
(
file_desc
.
filename
),)
+
dirs
else
:
dirs
=
(
find_root_package_dir
(
file_desc
.
filename
),)
+
dirs
dotted_filename
=
qualified_name
if
suffix
:
dotted_filename
+=
suffix
if
not
include
:
names
=
qualified_name
.
split
(
'.'
)
package_names
=
tuple
(
names
[:
-
1
])
module_name
=
names
[
-
1
]
module_filename
=
module_name
+
suffix
package_filename
=
"__init__"
+
suffix
for
dirname
in
dirs
:
path
=
os
.
path
.
join
(
dirname
,
dotted_filename
)
if
path_exists
(
path
):
return
path
if
not
include
:
package_dir
=
check_package_dir
(
dirname
,
package_names
)
if
package_dir
is
not
None
:
path
=
os
.
path
.
join
(
package_dir
,
module_filename
)
if
path_exists
(
path
):
return
path
path
=
os
.
path
.
join
(
dirname
,
package_dir
,
module_name
,
package_filename
)
if
path_exists
(
path
):
return
path
return
None
@
cached_function
@
cached_function
def
find_root_package_dir
(
file_path
):
def
find_root_package_dir
(
file_path
):
dir
=
os
.
path
.
dirname
(
file_path
)
dir
=
os
.
path
.
dirname
(
file_path
)
...
...
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