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
f685aade
Commit
f685aade
authored
Nov 01, 2018
by
Stefan Behnel
Committed by
GitHub
Nov 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2697 from cython/gh2638_absolute_import_handling
gh2638 absolute import handling
parents
60fd64bb
886723f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+11
-2
tests/run/cimport.srctree
tests/run/cimport.srctree
+12
-1
No files found.
Cython/Build/Dependencies.py
View file @
f685aade
...
@@ -399,6 +399,8 @@ dependency_regex = re.compile(r"(?:^\s*from +([0-9a-zA-Z_.]+) +cimport)|"
...
@@ -399,6 +399,8 @@ dependency_regex = re.compile(r"(?:^\s*from +([0-9a-zA-Z_.]+) +cimport)|"
r"(?:^\
s*cimpo
rt +([0-9a-zA-Z_.]+(?: *, *[0-9a-zA-Z_.]+)*))|"
r"(?:^\
s*cimpo
rt +([0-9a-zA-Z_.]+(?: *, *[0-9a-zA-Z_.]+)*))|"
r"(?:^\
s*cde
f +extern +from +['\"]([^'\"]+)['\"])|"
r"(?:^\
s*cde
f +extern +from +['\"]([^'\"]+)['\"])|"
r"(?:^\
s*i
nclude +['\"]([^'\"]+)['\"])"
,
re
.
M
)
r"(?:^\
s*i
nclude +['\"]([^'\"]+)['\"])"
,
re
.
M
)
dependency_after_from_regex
=
re
.
compile
(
r"(?:^\
s+
\(((?:[0-9a-zA-Z_., ]*)*)\
)[#
\n])|"
r"(?:^\
s+((?:[
0-9a-zA-Z_., ]*))[#\n])"
,
re
.
M
)
def
normalize_existing
(
base_path
,
rel_paths
):
def
normalize_existing
(
base_path
,
rel_paths
):
...
@@ -488,6 +490,13 @@ def parse_dependencies(source_filename):
...
@@ -488,6 +490,13 @@ def parse_dependencies(source_filename):
cimport_from
,
cimport_list
,
extern
,
include
=
m
.
groups
()
cimport_from
,
cimport_list
,
extern
,
include
=
m
.
groups
()
if
cimport_from
:
if
cimport_from
:
cimports
.
append
(
cimport_from
)
cimports
.
append
(
cimport_from
)
m_after_from
=
dependency_after_from_regex
.
search
(
source
,
pos
=
m
.
end
())
if
m_after_from
:
multiline
,
one_line
=
m_after_from
.
groups
()
subimports
=
multiline
or
one_line
cimports
.
extend
(
"{}.{}"
.
format
(
cimport_from
,
s
.
strip
())
for
s
in
subimports
.
split
(
','
))
elif
cimport_list
:
elif
cimport_list
:
cimports
.
extend
(
x
.
strip
()
for
x
in
cimport_list
.
split
(
","
))
cimports
.
extend
(
x
.
strip
()
for
x
in
cimport_list
.
split
(
","
))
elif
extern
:
elif
extern
:
...
@@ -584,14 +593,14 @@ class DependencyTree(object):
...
@@ -584,14 +593,14 @@ class DependencyTree(object):
pxd_list
=
[
filename
[:
-
4
]
+
'.pxd'
]
pxd_list
=
[
filename
[:
-
4
]
+
'.pxd'
]
else
:
else
:
pxd_list
=
[]
pxd_list
=
[]
# Cimports generates all possible combinations package.module
# when imported as from package cimport module.
for
module
in
self
.
cimports
(
filename
):
for
module
in
self
.
cimports
(
filename
):
if
module
[:
7
]
==
'cython.'
or
module
==
'cython'
:
if
module
[:
7
]
==
'cython.'
or
module
==
'cython'
:
continue
continue
pxd_file
=
self
.
find_pxd
(
module
,
filename
)
pxd_file
=
self
.
find_pxd
(
module
,
filename
)
if
pxd_file
is
not
None
:
if
pxd_file
is
not
None
:
pxd_list
.
append
(
pxd_file
)
pxd_list
.
append
(
pxd_file
)
elif
not
self
.
quiet
:
print
(
"%s: cannot find cimported module '%s'"
%
(
filename
,
module
))
return
tuple
(
pxd_list
)
return
tuple
(
pxd_list
)
@
cached_method
@
cached_method
...
...
tests/run/cimport.srctree
View file @
f685aade
...
@@ -33,9 +33,18 @@ cdef int foo(int a):
...
@@ -33,9 +33,18 @@ cdef int foo(int a):
ctypedef int my_int
ctypedef int my_int
######## pkg/subpkg/__init__.py ########
######## pkg/subpkg/submod.pxd ########
ctypedef int my_int
######## a.pyx ########
######## a.pyx ########
from other cimport A, foo
from other cimport (
A,
foo,
)
print A, foo(10)
print A, foo(10)
cimport other
cimport other
...
@@ -43,3 +52,5 @@ print other.A, other.foo(10)
...
@@ -43,3 +52,5 @@ print other.A, other.foo(10)
from pkg cimport sub
from pkg cimport sub
cdef sub.my_int a = 100
cdef sub.my_int a = 100
from pkg.subpkg cimport submod
\ No newline at end of file
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