🚨 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
# coding=utf-8
# amalgamate.py - Amalgamate C source and header files.
# Copyright (c) 2012, Erik Edlund <erik.edlund@32767.se>
@ -37,7 +38,7 @@ import datetime
import json
import os
import re
import sys
class Amalgamation(object):
@ -88,7 +89,7 @@ class Amalgamation(object):
for file_path in self.sources:
# Do not check the include paths while processing the source
# 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))
t = TranslationUnit(file_path, self, True)
amalgamation += t.content
@ -102,8 +103,16 @@ class Amalgamation(object):
print("Files included: {0}".format(self.included_files))
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.
cpp_comment_pattern = re.compile(r"//.*?\n")
@ -165,12 +174,6 @@ class TranslationUnit(object):
return skippable_contexts
# 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
def _process_pragma_once(self):
@ -185,7 +188,7 @@ class TranslationUnit(object):
pragmas = []
pragma_once_match = self.pragma_once_pattern.search(self.content)
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)
pragma_once_match = self.pragma_once_pattern.search(self.content,
@ -215,7 +218,7 @@ class TranslationUnit(object):
includes = []
include_match = self.include_pattern.search(self.content)
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")
search_same_dir = include_match.group(1) == '"'
found_included_path = self.amalgamation.find_included_file(
@ -233,7 +236,7 @@ class TranslationUnit(object):
include_match, found_included_path = include
tmp_content += self.content[prev_end:include_match.start()]
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)
tmp_content += t.content
prev_end = include_match.end()
@ -263,6 +266,7 @@ class TranslationUnit(object):
self.content = f.read()
self._process()
def main():
description = "Amalgamate C source and header files."
usage = " ".join([
@ -290,6 +294,6 @@ def main():
amalgamation = Amalgamation(argsparser.parse_args())
amalgamation.generate()
if __name__ == "__main__":
main()