From d5094ee42b284d825fe368c6274275aeaa7f9011 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 29 Nov 2019 18:20:28 +0100 Subject: [PATCH] pylint karma --- .pylintrc | 24 +++++++++++++++++++ ocrd_repair_inconsistencies/config.py | 2 +- .../ocrd_repair_inconsistencies.py | 18 +++++++------- 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..f4d4c09 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,24 @@ +[MASTER] + +[MESSAGES CONTROL] +disable = + ungrouped-imports, + bad-continuation, + missing-docstring, + no-self-use, + superfluous-parens, + invalid-name, + line-too-long, + too-many-arguments, + too-many-branches, + too-many-statements, + too-many-locals, + too-few-public-methods, + wrong-import-order, + duplicate-code + +# allow indented whitespace (as required by interpreter): +no-space-check=empty-line + +# allow non-snake-case identifiers: +good-names=n,i diff --git a/ocrd_repair_inconsistencies/config.py b/ocrd_repair_inconsistencies/config.py index fc6e89e..01e0b23 100644 --- a/ocrd_repair_inconsistencies/config.py +++ b/ocrd_repair_inconsistencies/config.py @@ -1,4 +1,4 @@ import json from pkg_resources import resource_string -OCRD_TOOL = json.loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8')) \ No newline at end of file +OCRD_TOOL = json.loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8')) diff --git a/ocrd_repair_inconsistencies/ocrd_repair_inconsistencies.py b/ocrd_repair_inconsistencies/ocrd_repair_inconsistencies.py index 038922a..3e47b51 100644 --- a/ocrd_repair_inconsistencies/ocrd_repair_inconsistencies.py +++ b/ocrd_repair_inconsistencies/ocrd_repair_inconsistencies.py @@ -64,7 +64,7 @@ class RepairInconsistencies(Processor): page_id, region.id, textLineOrder) continue - _fix_segment(region, page_id, reverse=textLineOrder=='bottom-to-top') + _fix_segment(region, page_id, reverse=(textLineOrder == 'bottom-to-top')) lines = region.get_TextLine() for line in lines: @@ -80,7 +80,7 @@ class RepairInconsistencies(Processor): page_id, line.id, readingDirection) continue - _fix_segment(line, page_id, reverse=readingDirection=='right-to-left') + _fix_segment(line, page_id, reverse=(readingDirection == 'right-to-left')) words = line.get_Word() for word in words: @@ -96,7 +96,7 @@ class RepairInconsistencies(Processor): page_id, word.id, readingDirection) continue - _fix_segment(word, page_id, reverse=readingDirection=='right-to-left') + _fix_segment(word, page_id, reverse=(readingDirection == 'right-to-left')) file_id = input_file.ID.replace(self.input_file_grp, self.output_file_grp) if file_id == input_file.ID: @@ -124,10 +124,8 @@ def get_text(thing, joiner=''): texts = [_get_text_for_one(part) for part in thing] if all(texts): return joiner.join(texts) - else: - return None - else: - return _get_text_for_one(thing) + return None + return _get_text_for_one(thing) def _fix_segment(segment, page_id, reverse=False): """Fix order of child elements of (region/line/word) segment.""" @@ -160,8 +158,7 @@ def _fix_segment(segment, page_id, reverse=False): polygon = Polygon(polygon_from_points(child.get_Coords().points)) if horizontal: return polygon.centroid.x - else: - return polygon.centroid.y + return polygon.centroid.y sorted_children = sorted(children, reverse=reverse, key=polygon_position) sorted_concat_text = get_text(sorted_children, joiner) @@ -170,7 +167,8 @@ def _fix_segment(segment, page_id, reverse=False): LOG.info('Fixing element order of page "%s" segment "%s"', page_id, segment.id) adoption(sorted_children) else: - LOG.debug('Resorting children of page "%s" segment "%s" from %s to %s does not suffice to turn "%s" into "%s"', + LOG.debug('Resorting children of page "%s" segment "%s" from %s to %s' + + 'does not suffice to turn "%s" into "%s"', page_id, segment.id, str([seg.id for seg in children]), str([seg.id for seg in sorted_children]),