Skip to content

Commit

Permalink
Enable flake8 and pylint (pycontribs#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored and ahmubashshir committed May 30, 2022
1 parent 01ca8a3 commit 6c816b3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 23 deletions.
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -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
40 changes: 19 additions & 21 deletions ansi2html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"""


class _State(object):
class _State:
def __init__(self):
self.reset()

Expand Down Expand Up @@ -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'<a href="\1">\1</a>', line)
return url_matcher.sub(r'<a href="\1">\1</a>', line)


def map_vt100_box_code(char):
Expand All @@ -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:
Expand Down Expand Up @@ -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 '<style type="text/css">\n%(style)s\n</style>\n' % {
Expand Down
2 changes: 1 addition & 1 deletion ansi2html/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# <http://www.gnu.org/licenses/>.


class Rule(object):
class Rule:
def __init__(self, klass, **kw):

self.klass = klass
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/test_ansi2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6c816b3

Please sign in to comment.