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
Boxiang Sun
cython
Commits
d0a66db8
Commit
d0a66db8
authored
Oct 30, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip common indentation in inline code.
parent
799bf36b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
Cython/Build/Inline.py
Cython/Build/Inline.py
+28
-2
No files found.
Cython/Build/Inline.py
View file @
d0a66db8
...
...
@@ -34,7 +34,7 @@ def cython_inline(code, types='aggressive', lib_dir=os.path.expanduser('~/.cytho
key
=
code
,
arg_sigs
module
=
code_cache
.
get
(
key
)
if
not
module
:
module_body
,
extract_func_code
=
extract_bodies
(
code
)
module_body
,
func_body
=
extract_func_code
(
code
)
params
=
', '
.
join
(
'%s %s'
%
a
for
a
in
arg_sigs
)
module_code
=
"""
%(module_body)s
...
...
@@ -58,13 +58,39 @@ def __invoke(%(params)s):
arg_list
=
[
kwds
[
arg
]
for
arg
in
arg_names
]
return
__import__
(
module
).
__invoke
(
*
arg_list
)
non_space
=
re
.
compile
(
'[^ ]'
)
def
strip_common_indent
(
lines
):
min_indent
=
None
for
line
in
lines
:
if
not
line
:
continue
# empty
indent
=
non_space
.
search
(
line
).
start
()
if
indent
==
len
(
line
):
continue
# blank
elif
line
[
indent
]
==
'#'
:
continue
# comment
elif
min_indent
is
None
or
min_indent
>
indent
:
min_indent
=
indent
for
line
in
lines
:
if
not
line
:
continue
indent
=
non_space
.
search
(
line
).
start
()
if
indent
==
len
(
line
):
continue
elif
line
[
indent
]
==
'#'
:
yield
line
else
:
yield
line
[
min_indent
:]
module_statement
=
re
.
compile
(
r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))'
)
def
extract_func_code
(
code
):
module
=
[]
function
=
[]
# TODO: string literals, backslash
current
=
function
for
line
in
code
.
split
(
'
\
n
'
):
code
=
code
.
replace
(
'
\
t
'
,
' '
)
lines
=
strip_common_indent
(
code
.
split
(
'
\
n
'
))
for
line
in
lines
:
if
not
line
.
startswith
(
' '
):
if
module_statement
.
match
(
line
):
current
=
module
...
...
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