Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
a66b2d20
Unverified
Commit
a66b2d20
authored
Jan 13, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚨
removed linter warnings for Python code
parent
f4a55f26
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
13 deletions
+27
-13
CHANGES.md
develop/amalgamate/CHANGES.md
+10
-0
amalgamate.py
develop/amalgamate/amalgamate.py
+17
-13
No files found.
develop/amalgamate/CHANGES.md
0 → 100644
View file @
a66b2d20
The following changes have been made to the code with respect to
<https://github.com/edlund/amalgamate/commit/c91f07eea1133aa184f652b8f1398eaf03586208>
:
-
Resolved inspection results from PyCharm:
-
replaced tabs with spaces
-
added encoding annotation
-
reindented file to remove trailing whitespaces
-
unused import
`sys`
-
membership check
-
made function from
`_is_within`
-
removed unused variable
`actual_path`
develop/amalgamate/amalgamate.py
View file @
a66b2d20
#!/usr/bin/env python
#!/usr/bin/env python
# coding=utf-8
# amalgamate.py - Amalgamate C source and header files.
# amalgamate.py - Amalgamate C source and header files.
# Copyright (c) 2012, Erik Edlund <erik.edlund@32767.se>
# Copyright (c) 2012, Erik Edlund <erik.edlund@32767.se>
...
@@ -37,7 +38,7 @@ import datetime
...
@@ -37,7 +38,7 @@ import datetime
import
json
import
json
import
os
import
os
import
re
import
re
import
sys
class
Amalgamation
(
object
):
class
Amalgamation
(
object
):
...
@@ -88,7 +89,7 @@ class Amalgamation(object):
...
@@ -88,7 +89,7 @@ class Amalgamation(object):
for
file_path
in
self
.
sources
:
for
file_path
in
self
.
sources
:
# Do not check the include paths while processing the source
# Do not check the include paths while processing the source
# list, all given source paths must be correct.
# list, all given source paths must be correct.
actual_path
=
self
.
actual_path
(
file_path
)
#
actual_path = self.actual_path(file_path)
print
(
" - processing
\"
{0}
\"
"
.
format
(
file_path
))
print
(
" - processing
\"
{0}
\"
"
.
format
(
file_path
))
t
=
TranslationUnit
(
file_path
,
self
,
True
)
t
=
TranslationUnit
(
file_path
,
self
,
True
)
amalgamation
+=
t
.
content
amalgamation
+=
t
.
content
...
@@ -102,8 +103,16 @@ class Amalgamation(object):
...
@@ -102,8 +103,16 @@ class Amalgamation(object):
print
(
"Files included: {0}"
.
format
(
self
.
included_files
))
print
(
"Files included: {0}"
.
format
(
self
.
included_files
))
print
(
""
)
print
(
""
)
class
TranslationUnit
(
object
):
def
_is_within
(
match
,
matches
):
for
m
in
matches
:
if
match
.
start
()
>
m
.
start
()
and
\
match
.
end
()
<
m
.
end
():
return
True
return
False
class
TranslationUnit
(
object
):
# // C++ comment.
# // C++ comment.
cpp_comment_pattern
=
re
.
compile
(
r"//.*?\n"
)
cpp_comment_pattern
=
re
.
compile
(
r"//.*?\n"
)
...
@@ -165,12 +174,6 @@ class TranslationUnit(object):
...
@@ -165,12 +174,6 @@ class TranslationUnit(object):
return
skippable_contexts
return
skippable_contexts
# Returns True if the match is within list of other matches
# Returns True if the match is within list of other matches
def
_is_within
(
self
,
match
,
matches
):
for
m
in
matches
:
if
match
.
start
()
>
m
.
start
()
and
\
match
.
end
()
<
m
.
end
():
return
True
return
False
# Removes pragma once from content
# Removes pragma once from content
def
_process_pragma_once
(
self
):
def
_process_pragma_once
(
self
):
...
@@ -185,7 +188,7 @@ class TranslationUnit(object):
...
@@ -185,7 +188,7 @@ class TranslationUnit(object):
pragmas
=
[]
pragmas
=
[]
pragma_once_match
=
self
.
pragma_once_pattern
.
search
(
self
.
content
)
pragma_once_match
=
self
.
pragma_once_pattern
.
search
(
self
.
content
)
while
pragma_once_match
:
while
pragma_once_match
:
if
not
self
.
_is_within
(
pragma_once_match
,
skippable_contexts
):
if
not
_is_within
(
pragma_once_match
,
skippable_contexts
):
pragmas
.
append
(
pragma_once_match
)
pragmas
.
append
(
pragma_once_match
)
pragma_once_match
=
self
.
pragma_once_pattern
.
search
(
self
.
content
,
pragma_once_match
=
self
.
pragma_once_pattern
.
search
(
self
.
content
,
...
@@ -215,7 +218,7 @@ class TranslationUnit(object):
...
@@ -215,7 +218,7 @@ class TranslationUnit(object):
includes
=
[]
includes
=
[]
include_match
=
self
.
include_pattern
.
search
(
self
.
content
)
include_match
=
self
.
include_pattern
.
search
(
self
.
content
)
while
include_match
:
while
include_match
:
if
not
self
.
_is_within
(
include_match
,
skippable_contexts
):
if
not
_is_within
(
include_match
,
skippable_contexts
):
include_path
=
include_match
.
group
(
"path"
)
include_path
=
include_match
.
group
(
"path"
)
search_same_dir
=
include_match
.
group
(
1
)
==
'"'
search_same_dir
=
include_match
.
group
(
1
)
==
'"'
found_included_path
=
self
.
amalgamation
.
find_included_file
(
found_included_path
=
self
.
amalgamation
.
find_included_file
(
...
@@ -233,7 +236,7 @@ class TranslationUnit(object):
...
@@ -233,7 +236,7 @@ class TranslationUnit(object):
include_match
,
found_included_path
=
include
include_match
,
found_included_path
=
include
tmp_content
+=
self
.
content
[
prev_end
:
include_match
.
start
()]
tmp_content
+=
self
.
content
[
prev_end
:
include_match
.
start
()]
tmp_content
+=
"// {0}
\n
"
.
format
(
include_match
.
group
(
0
))
tmp_content
+=
"// {0}
\n
"
.
format
(
include_match
.
group
(
0
))
if
not
found_included_path
in
self
.
amalgamation
.
included_files
:
if
found_included_path
not
in
self
.
amalgamation
.
included_files
:
t
=
TranslationUnit
(
found_included_path
,
self
.
amalgamation
,
False
)
t
=
TranslationUnit
(
found_included_path
,
self
.
amalgamation
,
False
)
tmp_content
+=
t
.
content
tmp_content
+=
t
.
content
prev_end
=
include_match
.
end
()
prev_end
=
include_match
.
end
()
...
@@ -263,6 +266,7 @@ class TranslationUnit(object):
...
@@ -263,6 +266,7 @@ class TranslationUnit(object):
self
.
content
=
f
.
read
()
self
.
content
=
f
.
read
()
self
.
_process
()
self
.
_process
()
def
main
():
def
main
():
description
=
"Amalgamate C source and header files."
description
=
"Amalgamate C source and header files."
usage
=
" "
.
join
([
usage
=
" "
.
join
([
...
@@ -290,6 +294,6 @@ def main():
...
@@ -290,6 +294,6 @@ def main():
amalgamation
=
Amalgamation
(
argsparser
.
parse_args
())
amalgamation
=
Amalgamation
(
argsparser
.
parse_args
())
amalgamation
.
generate
()
amalgamation
.
generate
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
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