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
e86f7378
Commit
e86f7378
authored
May 04, 2019
by
Dr Alex Meakins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PEP420 namespace support.
parent
709aafb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
13 deletions
+49
-13
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+35
-9
Cython/Utils.py
Cython/Utils.py
+14
-4
No files found.
Cython/Compiler/Main.py
View file @
e86f7378
...
@@ -621,32 +621,58 @@ def search_include_directories(dirs, qualified_name, suffix, pos, include=False)
...
@@ -621,32 +621,58 @@ def search_include_directories(dirs, qualified_name, suffix, pos, include=False)
else
:
else
:
dirs
=
(
Utils
.
find_root_package_dir
(
file_desc
.
filename
),)
+
dirs
dirs
=
(
Utils
.
find_root_package_dir
(
file_desc
.
filename
),)
+
dirs
# search for dotted filename e.g. <dir>/foo.bar.pxd
dotted_filename
=
qualified_name
dotted_filename
=
qualified_name
if
suffix
:
if
suffix
:
dotted_filename
+=
suffix
dotted_filename
+=
suffix
for
dirname
in
dirs
:
path
=
os
.
path
.
join
(
dirname
,
dotted_filename
)
if
os
.
path
.
exists
(
path
):
return
path
# search for filename in package structure e.g. <dir>/foo/bar.pxd or <dir>/foo/bar/__init__.pxd
if
not
include
:
if
not
include
:
names
=
qualified_name
.
split
(
'.'
)
names
=
qualified_name
.
split
(
'.'
)
package_names
=
tuple
(
names
[:
-
1
])
package_names
=
tuple
(
names
[:
-
1
])
module_name
=
names
[
-
1
]
module_name
=
names
[
-
1
]
module_filename
=
module_name
+
suffix
module_filename
=
module_name
+
suffix
package_filename
=
"__init__"
+
suffix
package_filename
=
"__init__"
+
suffix
for
dirname
in
dirs
:
# search for standard packages first - PEP420
path
=
os
.
path
.
join
(
dirname
,
dotted_filename
)
namespace_dirs
=
[]
if
os
.
path
.
exists
(
path
):
for
dirname
in
dirs
:
return
path
package_dir
,
is_namespace
=
Utils
.
check_package_dir
(
dirname
,
package_names
)
if
not
include
:
package_dir
=
Utils
.
check_package_dir
(
dirname
,
package_names
)
if
package_dir
is
not
None
:
if
package_dir
is
not
None
:
if
is_namespace
:
namespace_dirs
.
append
(
package_dir
)
continue
# matches modules of the form: <dir>/foo/bar.pxd
path
=
os
.
path
.
join
(
package_dir
,
module_filename
)
path
=
os
.
path
.
join
(
package_dir
,
module_filename
)
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
return
path
return
path
path
=
os
.
path
.
join
(
package_dir
,
module_name
,
package_filename
)
# matches modules of the form: <dir>/foo/bar/__init__.pxd
path
=
os
.
path
.
join
(
package_dir
,
module_name
,
package_filename
)
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
return
path
return
path
# search for namespaces second - PEP420
for
package_dir
in
namespace_dirs
:
# matches modules of the form: <dir>/foo/bar.pxd
path
=
os
.
path
.
join
(
package_dir
,
module_filename
)
if
os
.
path
.
exists
(
path
):
return
path
# matches modules of the form: <dir>/foo/bar/__init__.pxd
path
=
os
.
path
.
join
(
package_dir
,
module_name
,
package_filename
)
if
os
.
path
.
exists
(
path
):
return
path
return
None
return
None
...
...
Cython/Utils.py
View file @
e86f7378
...
@@ -148,21 +148,31 @@ def find_root_package_dir(file_path):
...
@@ -148,21 +148,31 @@ def find_root_package_dir(file_path):
@
cached_function
@
cached_function
def
check_package_dir
(
dir
,
package_names
):
def
check_package_dir
(
dir
,
package_names
):
namespace
=
True
for
dirname
in
package_names
:
for
dirname
in
package_names
:
dir
=
os
.
path
.
join
(
dir
,
dirname
)
dir
=
os
.
path
.
join
(
dir
,
dirname
)
if
not
is_package_dir
(
dir
):
has_init
=
contains_init
(
dir
)
return
None
if
not
namespace
and
not
has_init
:
return
dir
return
None
,
False
elif
has_init
:
namespace
=
False
return
dir
,
namespace
@
cached_function
@
cached_function
def
is_package_dir
(
dir_path
):
def
contains_init
(
dir_path
):
for
filename
in
PACKAGE_FILES
:
for
filename
in
PACKAGE_FILES
:
path
=
os
.
path
.
join
(
dir_path
,
filename
)
path
=
os
.
path
.
join
(
dir_path
,
filename
)
if
path_exists
(
path
):
if
path_exists
(
path
):
return
1
return
1
@
cached_function
def
is_package_dir
(
dir_path
):
if
contains_init
(
dir_path
):
return
1
@
cached_function
@
cached_function
def
path_exists
(
path
):
def
path_exists
(
path
):
# try on the filesystem first
# try on the filesystem first
...
...
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