Skip to content

Commit

Permalink
Adjustments for flake8 3.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored and lordmauve committed May 13, 2020
1 parent e15ba66 commit af382e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions flake8_html/plugin.py
Expand Up @@ -13,6 +13,7 @@
import codecs
import datetime
import pkgutil
import sys

from operator import attrgetter
from collections import namedtuple, Counter
Expand All @@ -24,6 +25,11 @@
from flake8.formatting import base
from jinja2 import Environment, PackageLoader, Markup

if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata


jinja2_env = Environment(
loader=PackageLoader('flake8_html')
Expand Down Expand Up @@ -67,6 +73,9 @@ def find_severity(code):
class HTMLPlugin(base.BaseFormatter):
"""A plugin for flake8 to render errors as HTML reports."""

name = 'flake8-html'
version = importlib_metadata.version('flake8-html')

def after_init(self):
"""Configure the plugin run."""
self.report_template = jinja2_env.get_template('file-report.html')
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -13,7 +13,8 @@
requirements = [
'jinja2>=2.9.0',
'pygments>=2.2.0',
'flake8>=3.3.0'
'flake8>=3.3.0',
'importlib-metadata;python_version<"3.8"',
]

test_requirements = [
Expand Down
3 changes: 2 additions & 1 deletion tests/test_flake8_html.py
Expand Up @@ -49,8 +49,9 @@ 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):
with chdir(bad_sourcedir), pytest.raises(SystemExit) as excinfo:
main(['--exit-zero', '--format=html', '--htmldir=%s' % tmpdir, '.'])
assert excinfo.value.code == 0
names = ('index.html', 'styles.css', 'bad.report.html', 'bad.source.html')
written = os.listdir(str(tmpdir))
for n in names:
Expand Down

0 comments on commit af382e2

Please sign in to comment.