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
2ac6a622
Commit
2ac6a622
authored
Oct 31, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indent stripping.
parent
780e4050
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
15 deletions
+13
-15
Cython/Build/Inline.py
Cython/Build/Inline.py
+13
-15
No files found.
Cython/Build/Inline.py
View file @
2ac6a622
...
@@ -81,6 +81,7 @@ def cython_inline(code,
...
@@ -81,6 +81,7 @@ def cython_inline(code,
locals
=
None
,
locals
=
None
,
globals
=
None
,
globals
=
None
,
**
kwds
):
**
kwds
):
code
=
strip_common_indent
(
code
)
ctx
=
Context
(
include_dirs
,
default_options
)
ctx
=
Context
(
include_dirs
,
default_options
)
if
locals
is
None
:
if
locals
is
None
:
locals
=
inspect
.
currentframe
().
f_back
.
f_back
.
f_locals
locals
=
inspect
.
currentframe
().
f_back
.
f_back
.
f_locals
...
@@ -140,28 +141,25 @@ def __invoke(%(params)s):
...
@@ -140,28 +141,25 @@ def __invoke(%(params)s):
return __import__(module).__invoke(*arg_list)
return __import__(module).__invoke(*arg_list)
non_space = re.compile('
[
^
]
')
non_space = re.compile('
[
^
]
')
def strip_common_indent(
lines
):
def strip_common_indent(
code
):
min_indent = None
min_indent = None
lines = code.split('
\
n
')
for line in lines:
for line in lines:
if not line:
match = non_space.search(line)
continue # empty
if not match:
indent = non_space.search(line).start()
if indent == len(line):
continue # blank
continue # blank
elif line[indent] == '
#':
indent = match.start()
if line[indent] == '
#':
continue
# comment
continue
# comment
elif
min_indent
is
None
or
min_indent
>
indent
:
elif
min_indent
is
None
or
min_indent
>
indent
:
min_indent
=
indent
min_indent
=
indent
for
line
in
lines
:
for
ix
,
line
in
enumerate
(
lines
):
if
not
line
:
match
=
non_space
.
search
(
line
)
continue
if
not
match
or
line
[
indent
]
==
'#'
:
indent
=
non_space
.
search
(
line
).
start
()
if
indent
==
len
(
line
):
continue
continue
elif
line
[
indent
]
==
'#'
:
yield
line
else
:
else
:
yield
line
[
min_indent
:]
lines
[
ix
]
=
line
[
min_indent
:]
return
'
\
n
'
.
join
(
lines
)
module_statement
=
re
.
compile
(
r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))'
)
module_statement
=
re
.
compile
(
r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))'
)
def
extract_func_code
(
code
):
def
extract_func_code
(
code
):
...
@@ -170,7 +168,7 @@ def extract_func_code(code):
...
@@ -170,7 +168,7 @@ def extract_func_code(code):
# TODO: string literals, backslash
# TODO: string literals, backslash
current
=
function
current
=
function
code
=
code
.
replace
(
'
\
t
'
,
' '
)
code
=
code
.
replace
(
'
\
t
'
,
' '
)
lines
=
strip_common_indent
(
code
.
split
(
'
\
n
'
)
)
lines
=
code
.
split
(
'
\
n
'
)
for
line
in
lines
:
for
line
in
lines
:
if
not
line
.
startswith
(
' '
):
if
not
line
.
startswith
(
' '
):
if
module_statement
.
match
(
line
):
if
module_statement
.
match
(
line
):
...
...
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