diff --git a/fix-mock-patch-with-python3.4.patch b/fix-mock-patch-with-python3.4.patch deleted file mode 100644 index 8788c5f..0000000 --- a/fix-mock-patch-with-python3.4.patch +++ /dev/null @@ -1,40 +0,0 @@ -From: Antonio Larrosa -Subject: Fix mock.patch with python3.4 - -In python 3.5, mock.patch uses create=True automatically if you are patching -builtins in a module, but in python 3.4 the argument is still needed. -diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py -index d096457..47e74a6 100644 ---- a/tests/unit/test_base_formatter.py -+++ b/tests/unit/test_base_formatter.py -@@ -23,7 +23,7 @@ def test_start(filename): - """Verify we open a new file in the start method.""" - mock_open = mock.mock_open() - formatter = base.BaseFormatter(options(output_file=filename)) -- with mock.patch("flake8.formatting.base.open", mock_open): -+ with mock.patch("flake8.formatting.base.open", mock_open, create=True): - formatter.start() - - if filename is None: -diff --git a/tests/unit/test_debug.py b/tests/unit/test_debug.py -index 2da4bf8..074b409 100644 ---- a/tests/unit/test_debug.py -+++ b/tests/unit/test_debug.py -@@ -95,7 +95,7 @@ def test_information(system, pyversion, pyimpl): - system.assert_called_once_with() - - --@mock.patch("flake8.main.debug.print") -+@mock.patch("flake8.main.debug.print", create=True) - @mock.patch("flake8.main.debug.information", return_value={}) - @mock.patch("json.dumps", return_value="{}") - def test_print_information_no_plugins(dumps, information, print_mock): -@@ -112,7 +112,7 @@ def test_print_information_no_plugins(dumps, information, print_mock): - assert print_mock.called is False - - --@mock.patch("flake8.main.debug.print") -+@mock.patch("flake8.main.debug.print", create=True) - @mock.patch("flake8.main.debug.information", return_value={}) - @mock.patch("json.dumps", return_value="{}") - def test_print_information(dumps, information, print_mock): diff --git a/fix-recent-flake8-stdoutWriteHook-change.patch b/fix-recent-flake8-stdoutWriteHook-change.patch deleted file mode 100644 index 55e5624..0000000 --- a/fix-recent-flake8-stdoutWriteHook-change.patch +++ /dev/null @@ -1,74 +0,0 @@ -diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py -index 7919f92..ea351ca 100644 ---- a/src/flake8/formatting/base.py -+++ b/src/flake8/formatting/base.py -@@ -179,12 +179,26 @@ class BaseFormatter: - # one - return f"{error.physical_line}{indent}^" - -+ def _stdout_write_hook(self, value: str) -> None: -+ """sys.stdout.write() with fallbacks.""" -+ try: -+ sys.stdout.write(value) -+ except UnicodeEncodeError: -+ byte_value = value.encode(sys.stdout.encoding, "backslashreplace") -+ if hasattr(sys.stdout, "buffer"): -+ sys.stdout.buffer.write(byte_value) -+ else: -+ sys.stdout.write( -+ byte_value.decode(sys.stdout.encoding, "strict") -+ ) -+ - def _write(self, output: str) -> None: - """Handle logic of whether to use an output file or print().""" - if self.output_fd is not None: - self.output_fd.write(output + self.newline) - if self.output_fd is None or self.options.tee: -- sys.stdout.buffer.write(output.encode() + self.newline.encode()) -+ self._stdout_write_hook(output) -+ self._stdout_write_hook(self.newline) - - def write(self, line: Optional[str], source: Optional[str]) -> None: - """Write the line either to the output file or stdout. -diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py -index 8958903..5959636 100644 ---- a/tests/unit/test_base_formatter.py -+++ b/tests/unit/test_base_formatter.py -@@ -136,6 +136,37 @@ def test_write_produces_stdout(capsys): - assert capsys.readouterr().out == f"{line}\n{source}\n" - - -+@pytest.mark.parametrize("buffered_stdout", [True, False]) -+def test_write_hook_fallbacks(buffered_stdout): -+ """Varify stdout.write() fallbacks.""" -+ mock_line = mock.Mock(name="Mock Line") -+ -+ stdout_spec = ["write", "encoding"] -+ if buffered_stdout: -+ stdout_spec.append("buffer") -+ -+ with mock.patch("sys.stdout", spec=stdout_spec) as mock_stdout: -+ -+ def _stdout_write_effect(value): -+ if value is mock_line: -+ raise UnicodeEncodeError("unittest-codec", "", 42, 43, "NOPE") -+ return None -+ -+ mock_stdout.write.side_effect = _stdout_write_effect -+ mock_stdout.encoding = "ascii" -+ -+ formatter = base.BaseFormatter(options()) -+ formatter.write(mock_line, None) -+ -+ mock_line.encode.assert_called_once_with("ascii", "backslashreplace") -+ byte_mock_line = mock_line.encode.return_value -+ if buffered_stdout: -+ mock_stdout.buffer.write.assert_any_call(byte_mock_line) -+ else: -+ byte_mock_line.decode.assert_called_once_with("ascii", "strict") -+ mock_stdout.write.assert_any_call(byte_mock_line.decode.return_value) -+ -+ - class AfterInitFormatter(base.BaseFormatter): - """Subclass for testing after_init.""" - diff --git a/flake8-4.0.1.tar.gz b/flake8-4.0.1.tar.gz deleted file mode 100644 index ee22293..0000000 --- a/flake8-4.0.1.tar.gz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d -size 154905 diff --git a/flake8-5.0.4.tar.gz b/flake8-5.0.4.tar.gz new file mode 100644 index 0000000..8b56780 --- /dev/null +++ b/flake8-5.0.4.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db +size 145862 diff --git a/gen-pycodestyle-plugin b/gen-pycodestyle-plugin new file mode 100644 index 0000000..7ec822a --- /dev/null +++ b/gen-pycodestyle-plugin @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +import inspect +import os.path +from typing import Any +from typing import Callable +from typing import Generator +from typing import NamedTuple +from typing import Tuple + +import pycodestyle + + +def _too_long(s: str) -> str: + if len(s) >= 80: + return f"{s} # noqa: E501" + else: + return s + + +class Call(NamedTuple): + name: str + is_generator: bool + params: Tuple[str, ...] + + def to_src(self) -> str: + params_s = ", ".join(self.params) + if self.is_generator: + return _too_long(f" yield from _{self.name}({params_s})") + else: + lines = ( + _too_long(f" ret = _{self.name}({params_s})"), + " if ret is not None:", + " yield ret", + ) + return "\n".join(lines) + + @classmethod + def from_func(cls, func: Callable[..., Any]) -> "Call": + spec = inspect.getfullargspec(func) + params = tuple(spec.args) + return cls(func.__name__, inspect.isgeneratorfunction(func), params) + + +def lines() -> Generator[str, None, None]: + logical = [] + physical = [] + + logical = [ + Call.from_func(check) for check in pycodestyle._checks["logical_line"] + ] + physical = [ + Call.from_func(check) for check in pycodestyle._checks["physical_line"] + ] + assert not pycodestyle._checks["tree"] + + yield f'"""Generated using ./bin/{os.path.basename(__file__)}."""' + yield "# fmt: off" + yield "from typing import Any" + yield "from typing import Generator" + yield "from typing import Tuple" + yield "" + imports = sorted(call.name for call in logical + physical) + for name in imports: + yield _too_long(f"from pycodestyle import {name} as _{name}") + yield "" + yield "" + + yield "def pycodestyle_logical(" + logical_params = {param for call in logical for param in call.params} + for param in sorted(logical_params): + yield f" {param}: Any," + yield ") -> Generator[Tuple[int, str], None, None]:" + yield ' """Run pycodestyle logical checks."""' + for call in sorted(logical): + yield call.to_src() + yield "" + yield "" + + yield "def pycodestyle_physical(" + physical_params = {param for call in physical for param in call.params} + for param in sorted(physical_params): + yield f" {param}: Any," + yield ") -> Generator[Tuple[int, str], None, None]:" + yield ' """Run pycodestyle physical checks."""' + for call in sorted(physical): + yield call.to_src() + + +def main() -> int: + for line in lines(): + print(line) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/python-flake8.changes b/python-flake8.changes index 3ffb9b1..91c08ba 100644 --- a/python-flake8.changes +++ b/python-flake8.changes @@ -1,3 +1,19 @@ +------------------------------------------------------------------- +Thu Aug 18 08:44:15 UTC 2022 - Dirk Müller + +- update to 5.0.4: + * Remove ``indent_size_str`` (See also :pull:`1411`). + * Remove some dead code (See also :pull:`1453`, :pull:`1540`, :pull:`1541`). + * Missing explicitly-specified configuration is now an error (See also + :issue:`1497`, :pull:`1498`). + * Always read configuration files as UTF-8 (See also :issue:`1532`, + :pull:`1533`). + * Remove manpage from docs -- use ``help2man`` or related tools instead (See + also :pull:`1557`). + * Forbid invalid plugin codes (See also :issue:`325`, :pull:`1579`). + * lots of bugfixes, see included changelog +- drop fix-mock-patch-with-python3.4.patch fix-recent-flake8-stdoutWriteHook-change.patch (obsolete/upstream) + ------------------------------------------------------------------- Thu Mar 17 16:09:27 UTC 2022 - pgajdos@suse.com diff --git a/python-flake8.spec b/python-flake8.spec index 77c3d0e..ab664ea 100644 --- a/python-flake8.spec +++ b/python-flake8.spec @@ -19,30 +19,30 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %bcond_without python2 Name: python-flake8 -Version: 4.0.1 +Version: 5.0.4 Release: 0 Summary: Modular source code checker: pep8, pyflakes and co License: MIT URL: https://gitlab.com/pycqa/flake8 Source: https://files.pythonhosted.org/packages/source/f/flake8/flake8-%{version}.tar.gz -Patch0: fix-mock-patch-with-python3.4.patch -Patch1: fix-recent-flake8-stdoutWriteHook-change.patch +# workaround for https://github.com/PyCQA/flake8/pull/1669 +Source2: https://raw.githubusercontent.com/PyCQA/flake8/5.0.4/bin/gen-pycodestyle-plugin BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros -Requires: python-importlib-metadata -Requires: python-mccabe >= 0.6.0 -Requires: python-pycodestyle >= 2.8.0 -Requires: python-pyflakes >= 2.4.0 +Requires: python-importlib-metadata >= 1.1.0 +Requires: python-mccabe >= 0.7.0 +Requires: python-pycodestyle >= 2.9.0 +Requires: python-pyflakes >= 2.5.0 Requires: python-typing Requires(post): update-alternatives Requires(postun):update-alternatives BuildArch: noarch # SECTION test requirements -BuildRequires: %{python_module importlib-metadata} -BuildRequires: %{python_module mccabe >= 0.6.0} -BuildRequires: %{python_module pycodestyle >= 2.8.0} -BuildRequires: %{python_module pyflakes >= 2.4.0} +BuildRequires: %{python_module importlib-metadata >= 1.1.0} +BuildRequires: %{python_module mccabe >= 0.7.0} +BuildRequires: %{python_module pycodestyle >= 2.9.0} +BuildRequires: %{python_module pyflakes >= 2.5.0} BuildRequires: %{python_module pytest} BuildRequires: %{python_module typing} %if %{with python2} @@ -79,8 +79,8 @@ Flake8 is a modular extensible source code checker. This package provides documentation for %{name}. %prep -%setup -q -n flake8-%{version} -%autopatch -p1 +%autosetup -p1 -n flake8-%{version} +install -m 0755 -D %{SOURCE2} bin/gen-pycodestyle-plugin %build %python_build @@ -101,7 +101,6 @@ This package provides documentation for %{name}. %files %{python_files} %license LICENSE -%doc docs/source/manpage.rst %python_alternative %{_bindir}/flake8 %dir %{python_sitelib}/flake8 %{python_sitelib}/flake8/*