diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 99469da..214d3b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,3 +20,20 @@ repos: - id: check-merge-conflict - id: debug-statements language_version: python3 + - repo: https://gitlab.com/pycqa/flake8.git + rev: 3.8.4 + hooks: + - id: flake8 + additional_dependencies: + - pydocstyle>=5.1.1 + - flake8-absolute-import + - flake8-black>=0.1.1 + - flake8-docstrings>=1.5.0 + language_version: python3 + - repo: https://github.com/pre-commit/mirrors-pylint + rev: v2.6.0 + hooks: + - id: pylint + additional_dependencies: + - ansible-base + - testinfra diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..455ad61 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,29 @@ +[MESSAGES CONTROL] + +disable = + # TODO(ssbarnea): remove temporary skips adding during initial adoption: + attribute-defined-outside-init, + consider-using-dict-comprehension, + consider-using-enumerate, + deprecated-module, + import-error, + invalid-name, + line-too-long, + missing-class-docstring, + missing-function-docstring, + missing-module-docstring, + no-self-use, + redefined-builtin, + redefined-outer-name, + too-few-public-methods, + too-many-arguments, + too-many-branches, + too-many-instance-attributes, + too-many-locals, + too-many-public-methods, + too-many-statements, + unused-argument, + unused-variable, + +[REPORTS] +output-format = colorized diff --git a/ansi2html/converter.py b/ansi2html/converter.py index 4d8ff5b..5f75796 100644 --- a/ansi2html/converter.py +++ b/ansi2html/converter.py @@ -114,7 +114,7 @@ """ -class _State(object): +class _State: def __init__(self): self.reset() @@ -228,8 +228,7 @@ def linkify(line, latex_mode): ) if latex_mode: return url_matcher.sub(r"\\url{\1}", line) - else: - return url_matcher.sub(r'\1', line) + return url_matcher.sub(r'\1', line) def map_vt100_box_code(char): @@ -243,11 +242,11 @@ def _needs_extra_newline(text): return True -class CursorMoveUp(object): +class CursorMoveUp: pass -class Ansi2HTMLConverter(object): +class Ansi2HTMLConverter: """Convert Ansi color codes to CSS+HTML Example: @@ -508,24 +507,23 @@ def convert(self, ansi, full=True, ensure_trailing_newline=False): attrs = self.prepare(ansi, ensure_trailing_newline=ensure_trailing_newline) if not full: return attrs["body"] + if self.latex: + _template = _latex_template else: - if self.latex: - _template = _latex_template - else: - _template = _html_template - all_styles = get_styles(self.dark_bg, self.line_wrap, self.scheme) - backgrounds = all_styles[:6] - used_styles = filter( - lambda e: e.klass.lstrip(".") in attrs["styles"], all_styles - ) + _template = _html_template + all_styles = get_styles(self.dark_bg, self.line_wrap, self.scheme) + backgrounds = all_styles[:6] + used_styles = filter( + lambda e: e.klass.lstrip(".") in attrs["styles"], all_styles + ) - return _template % { - "style": "\n".join(list(map(str, backgrounds + list(used_styles)))), - "title": self.title, - "font_size": self.font_size, - "content": attrs["body"], - "output_encoding": self.output_encoding, - } + return _template % { + "style": "\n".join(list(map(str, backgrounds + list(used_styles)))), + "title": self.title, + "font_size": self.font_size, + "content": attrs["body"], + "output_encoding": self.output_encoding, + } def produce_headers(self): return '\n' % { diff --git a/ansi2html/style.py b/ansi2html/style.py index 74ffc11..d8603f9 100644 --- a/ansi2html/style.py +++ b/ansi2html/style.py @@ -17,7 +17,7 @@ # . -class Rule(object): +class Rule: def __init__(self, klass, **kw): self.klass = klass diff --git a/setup.cfg b/setup.cfg index 36cf482..c859710 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,3 +41,8 @@ setup_requires = [options.packages.find] where = . + +[flake8] +format = pylint +# E203: https://github.com/python/black/issues/315 +ignore = E741,W503,W504,H,E501,E203,D diff --git a/tests/test_ansi2html.py b/tests/test_ansi2html.py index 902af7d..7d9d25f 100644 --- a/tests/test_ansi2html.py +++ b/tests/test_ansi2html.py @@ -92,7 +92,8 @@ def test_conversion_as_command(self, mock_stdout, mock_argv): with open(join(_here, "ansicolor.html"), "rb") as output: expected_data = "".join(read_to_unicode(output)) - f = lambda: StringIO(test_data) + def f(): + return StringIO(test_data) with patch("sys.stdin", new_callable=f): main()