🚨 removed linter warnings for Python code

This commit is contained in:
Niels Lohmann 2018-01-13 11:15:23 +01:00
parent f4a55f26b0
commit a66b2d20c6
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 259 additions and 245 deletions

View file

@ -0,0 +1,10 @@
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`

View file

@ -1,4 +1,5 @@
#!/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
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):
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):
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):
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):
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):
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):
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):
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():
amalgamation = Amalgamation(argsparser.parse_args()) amalgamation = Amalgamation(argsparser.parse_args())
amalgamation.generate() amalgamation.generate()
if __name__ == "__main__": if __name__ == "__main__":
main() main()