From c4cc4fbf8c0749e5833b3187218587355e33ae93db3a7dda0ad50de9989b6410 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Wed, 22 Nov 2023 07:53:22 +0000 Subject: [PATCH] - Make compatible with latest python-flake8 and python-black bsc#1217371 - Add patch flake8-v6-compatibility.patch, gh#grantjenks/blue#96 - Remove patch flake8-v5-compatibility.patch - Refresh patch python-blue.changes OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-blue?expand=0&rev=24 --- black-23.3.patch | 4 +- flake8-v5-compatibility.patch | 28 -------- flake8-v6-compatibility.patch | 122 ++++++++++++++++++++++++++++++++++ python-blue.changes | 9 +++ python-blue.spec | 4 +- 5 files changed, 135 insertions(+), 32 deletions(-) delete mode 100644 flake8-v5-compatibility.patch create mode 100644 flake8-v6-compatibility.patch diff --git a/black-23.3.patch b/black-23.3.patch index bb5c4fd..9b3114a 100644 --- a/black-23.3.patch +++ b/black-23.3.patch @@ -2,12 +2,12 @@ Index: blue-0.9.1/blue/__init__.py =================================================================== --- blue-0.9.1.orig/blue/__init__.py +++ blue-0.9.1/blue/__init__.py -@@ -451,7 +451,7 @@ def main(): +@@ -476,7 +476,7 @@ def main(): 'Black', 'Blue' ) # Change the config param callback to support setup.cfg, tox.ini, etc. - config_param = black.main.params[25] -+ config_param = black.main.params[26] ++ config_param = black.main.params[27] assert config_param.name == 'config' config_param.callback = read_configs # Change the version string by adding a redundant Click `version_option` diff --git a/flake8-v5-compatibility.patch b/flake8-v5-compatibility.patch deleted file mode 100644 index 345f5d5..0000000 --- a/flake8-v5-compatibility.patch +++ /dev/null @@ -1,28 +0,0 @@ ---- a/blue/__init__.py -+++ b/blue/__init__.py -@@ -397,9 +397,12 @@ def format_file_in_place(*args, **kws): - - - try: -- BaseConfigParser = flake8_config.ConfigParser # flake8 v4 -+ BaseConfigParser = flake8_config.configparser.ConfigParser # flake8 v5 - except AttributeError: -- BaseConfigParser = flake8_config.MergedConfigParser # flake8 v3 -+ try: -+ BaseConfigParser = flake8_config.ConfigParser # flake8 v4 -+ except AttributeError: -+ BaseConfigParser = flake8_config.MergedConfigParser # flake8 v3 - - - class MergedConfigParser(BaseConfigParser): ---- blue-0.9.1.orig/setup.py -+++ blue-0.9.1/setup.py -@@ -37,7 +37,7 @@ setup( - packages=['blue'], - tests_require=['tox'], - cmdclass={'test': Tox}, -- install_requires=['black==22.1.0', 'flake8>=3.8,<5.0.0'], -+ install_requires=['black==22.1.0', 'flake8>=3.8'], - project_urls={ - 'Documentation': 'https://blue.readthedocs.io/en/latest', - 'Source': 'https://github.com/grantjenks/blue.git', diff --git a/flake8-v6-compatibility.patch b/flake8-v6-compatibility.patch new file mode 100644 index 0000000..18da478 --- /dev/null +++ b/flake8-v6-compatibility.patch @@ -0,0 +1,122 @@ +Index: blue-0.9.1/blue/__init__.py +=================================================================== +--- blue-0.9.1.orig/blue/__init__.py ++++ blue-0.9.1/blue/__init__.py +@@ -7,6 +7,8 @@ import logging + import re + import sys + ++from configparser import ConfigParser ++ + from importlib import machinery + + __version__ = '0.9.1' +@@ -74,6 +76,7 @@ try: + from black.files import tomli + except ImportError: + from black.files import tomllib as tomli ++from black.files import find_user_pyproject_toml + from black.linegen import LineGenerator as BlackLineGenerator + from black.lines import Line + from black.nodes import ( +@@ -89,9 +92,6 @@ from black.strings import ( + sub_twice, + ) + +-from flake8.options import config as flake8_config +-from flake8.options import manager as flake8_manager +- + from enum import Enum + from functools import lru_cache + from typing import Any, Dict, Iterator, List, Optional, Pattern +@@ -396,21 +396,49 @@ def format_file_in_place(*args, **kws): + return black_format_file_in_place(*args, **kws) + + +-try: +- BaseConfigParser = flake8_config.ConfigParser # flake8 v4 +-except AttributeError: +- BaseConfigParser = flake8_config.MergedConfigParser # flake8 v3 ++def load_configs_from_file() -> Dict[str, Any]: ++ """Parses supported config files using configparser""" ++ supported_config_files = ('setup.cfg', 'tox.ini', '.blue') ++ config_dict = {} ++ pwd = Path.cwd() ++ cfg = ConfigParser() ++ ++ config_file_found = False ++ ++ # search config files from pwd and its parents ++ for dir in (pwd, *pwd.parents): ++ filenames = [ ++ (dir / config_file) for config_file in supported_config_files ++ ] ++ files_read = cfg.read(filenames) ++ ++ # if config file was read, stop search ++ if len(files_read) > 0: ++ config_file_found = True ++ break ++ ++ if not config_file_found: ++ # config file not found yet ++ # last try using top-level user configuration for black ++ try: ++ top_level_full_path = find_user_pyproject_toml() ++ ++ top_level_dir = top_level_full_path.parent ++ ++ filenames = [ ++ (top_level_dir / config_file) ++ for config_file in supported_config_files ++ ] ++ ++ cfg.read(filenames) ++ except PermissionError: ++ # ignore user level config directory if no access permission was given ++ pass + ++ if cfg.has_section('blue'): ++ config_dict.update(cfg.items('blue')) + +-class MergedConfigParser(BaseConfigParser): +- def _parse_config(self, config_parser, parent=None): +- """Skip option parsing in flake8's config parsing.""" +- config_dict = {} +- for option_name in config_parser.options(self.program_name): +- value = config_parser.get(self.program_name, option_name) +- LOG.debug('Option "%s" has value: %r', option_name, value) +- config_dict[option_name] = value +- return config_dict ++ return config_dict + + + def read_configs( +@@ -419,12 +447,9 @@ def read_configs( + """Read configs through the config param's callback hook.""" + # Use black's `read_pyproject_toml` for the default + result = black.read_pyproject_toml(ctx, param, value) +- # Use flake8's config file parsing to load setup.cfg, tox.ini, and .blue ++ # parses setup.cfg, tox.ini, and .blue config files + # The parsing looks both in the project and user directories. +- finder = flake8_config.ConfigFileFinder('blue') +- manager = flake8_manager.OptionManager('blue', '0') +- parser = MergedConfigParser(manager, finder) +- config = parser.parse() ++ config = load_configs_from_file() + # Merge the configs into Click's `default_map`. + default_map: Dict[str, Any] = {} + default_map.update(ctx.default_map or {}) +Index: blue-0.9.1/setup.py +=================================================================== +--- blue-0.9.1.orig/setup.py ++++ blue-0.9.1/setup.py +@@ -37,7 +37,7 @@ setup( + packages=['blue'], + tests_require=['tox'], + cmdclass={'test': Tox}, +- install_requires=['black==22.1.0', 'flake8>=3.8,<5.0.0'], ++ install_requires=['black==22.1.0'], + project_urls={ + 'Documentation': 'https://blue.readthedocs.io/en/latest', + 'Source': 'https://github.com/grantjenks/blue.git', diff --git a/python-blue.changes b/python-blue.changes index 0f77279..326a278 100644 --- a/python-blue.changes +++ b/python-blue.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Wed Nov 22 07:48:48 UTC 2023 - Daniel Garcia + +- Make compatible with latest python-flake8 and python-black + bsc#1217371 + - Add patch flake8-v6-compatibility.patch, gh#grantjenks/blue#96 + - Remove patch flake8-v5-compatibility.patch + - Refresh patch python-blue.changes + ------------------------------------------------------------------- Thu May 4 12:02:24 UTC 2023 - Daniel Garcia diff --git a/python-blue.spec b/python-blue.spec index bedb511..814594d 100644 --- a/python-blue.spec +++ b/python-blue.spec @@ -26,8 +26,8 @@ URL: https://github.com/grantjenks/blue Source: https://github.com/grantjenks/blue/archive/v%{version}.tar.gz#/blue-%{version}.tar.gz # PATCH-FIX-OPENSUSE unpin-tomli.patch -- gh#grantjenks/blue#66 Patch1: unpin-tomli.patch -# PATCH-FIX-UPSTREAM flake8-v5-compatibility.patch -- gh#grantjenks/blue#78 -Patch2: flake8-v5-compatibility.patch +# PATCH-FIX-UPSTREAM flake8-v6-compatibility.patch -- gh#grantjenks/blue#96 +Patch2: flake8-v6-compatibility.patch # PATCH-FIX-OPENSUSE black-23.3.patch -- gh#grantjenks/blue#97 Patch3: black-23.3.patch BuildRequires: %{python_module Sphinx}