Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for flake8 version >= 5.0.0 #32

Merged
merged 1 commit into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion flake8_html/plugin.py
Expand Up @@ -17,6 +17,7 @@
from operator import attrgetter
from collections import namedtuple, Counter

import flake8
from pygments import highlight
from collections import defaultdict
from pygments.lexers import PythonLexer
Expand Down Expand Up @@ -278,14 +279,23 @@ def write_index(self):
key=lambda e: (e.highest_sev, -e.error_count)
),
now=datetime.datetime.now(),
versions=self.option_manager.generate_versions(),
versions=self._get_plugin_version_summary(),
highest_sev=highest_sev,
title=self.options.htmltitle,
)
indexfile = os.path.join(self.outdir, 'index.html')
with codecs.open(indexfile, 'w', encoding='utf8') as f:
f.write(rendered)

def _get_plugin_version_summary(self):
option_manager = self.option_manager
if flake8.__version_info__ < (5, 0, 0):
return option_manager.generate_versions()
else:
# Below return info prefixed with "Installed with:". This is different from
# option_manager.generate_versions() but using this as it is a cleaner way
return option_manager.parser.epilog

@classmethod
def add_options(cls, options):
"""Add a --htmldir option to the OptionsManager."""
Expand Down
6 changes: 5 additions & 1 deletion tests/test_flake8_html.py
Expand Up @@ -7,6 +7,7 @@
import shutil
import contextlib

import flake8
import pytest
from flake8.main.cli import main

Expand Down Expand Up @@ -50,7 +51,10 @@ def chdir(dest):
def test_report(bad_sourcedir, tmpdir):
"""Test that a report on a bad file creates the expected files."""
with chdir(bad_sourcedir), pytest.raises(SystemExit) as excinfo:
main(['--exit-zero', '--format=html', '--htmldir=%s' % tmpdir, '.'])
code = main(['--exit-zero', '--format=html', '--htmldir=%s' % tmpdir, '.'])
# earlier flake8 version were raising the SystemExit, now raise it explicitly to cover recent versions too
if flake8.__version_info__ >= (5, 0, 0):
raise SystemExit(code)
assert excinfo.value.code == 0
names = ('index.html', 'styles.css', 'bad.report.html', 'bad.source.html')
written = os.listdir(str(tmpdir))
Expand Down