From f536c53a6db51bdecdf800e90058d54bcf244e94 Mon Sep 17 00:00:00 2001 From: Lukasz Sobczuk Date: Sun, 27 Oct 2024 08:45:36 +0100 Subject: [PATCH] Delivery of compatibility for Flake8 from version 4 to the latest version. --- NEWS.rst | 9 +++++++++ pyproject.toml | 2 +- pytest_flake8.py | 27 +++------------------------ tests/test_flake8.py | 7 +++++++ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 1d4638c..85feb53 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,12 @@ +v1.3.0 +====== + +Features +-------- + +- Compatible for Flake8 from version flake8>=4. (#??) + + v1.2.2 ====== diff --git a/pyproject.toml b/pyproject.toml index f73ab99..ec7e05e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ ] requires-python = ">=3.8" dependencies = [ - "flake8 >= 5, < 6", + "flake8 >= 4.0", "pytest >= 7.0", ] dynamic = ["version"] diff --git a/pytest_flake8.py b/pytest_flake8.py index 78475bd..8fafe02 100644 --- a/pytest_flake8.py +++ b/pytest_flake8.py @@ -6,7 +6,6 @@ from io import BytesIO, TextIOWrapper from flake8.main import application -from flake8.options import config import pytest @@ -223,29 +222,9 @@ def check_file( args += ['--show-source'] if statistics: args += ['--statistics'] - args += [str(path)] app = application.Application() - prelim_opts, remaining_args = app.parse_preliminary_options(args) - cfg, cfg_dir = config.load_config( - config=prelim_opts.config, - extra=prelim_opts.append_config, - isolated=prelim_opts.isolated, - ) - app.find_plugins( - cfg, - cfg_dir, - enable_extensions=prelim_opts.enable_extensions, - require_plugins=prelim_opts.require_plugins, - ) - app.register_plugin_options() - app.parse_configuration_and_cli(cfg, cfg_dir, remaining_args) if flake8ignore: - app.options.ignore = flake8ignore - app.make_formatter() # fix this - app.make_guide() - app.make_file_checker_manager() - app.run_checks() - app.formatter.start() - app.report_errors() - app.formatter.stop() + args += ["--ignore", flake8ignore] + args += [str(path)] + app.run(args) return app.result_count diff --git a/tests/test_flake8.py b/tests/test_flake8.py index 8c8b73f..3ff63e2 100644 --- a/tests/test_flake8.py +++ b/tests/test_flake8.py @@ -2,9 +2,12 @@ import pathlib import textwrap +from packaging import version import pytest +from flake8 import __version__ as flake8_version + pytest_plugins = ("pytester",) @@ -39,6 +42,10 @@ def test_ignores(self, tmpdir): assert ign(tmpdir.join("a/y.py")) == "E203 E300".split() assert ign(tmpdir.join("a/z.py")) is None + @pytest.mark.xfail( + version.parse(flake8_version) >= version.parse("6.0.0"), + reason="Requires Flake8 version earlier than 6.0.0.", + ) def test_default_flake8_ignores(self, testdir): testdir.makeini(""" [pytest]