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

feat: remove flake8 dependency #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions blue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import re
import sys

from configparser import ConfigParser

from importlib import machinery

__version__ = '0.9.1'
Expand Down Expand Up @@ -86,9 +88,6 @@ def path_hook(cls):
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
Expand Down Expand Up @@ -393,21 +392,19 @@ 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"""
config_dict = {}
pwd = Path('.').resolve()
kaweantonio marked this conversation as resolved.
Show resolved Hide resolved
supported_config_files = ('setup.cfg', 'tox.ini', '.blue')
filenames = [(pwd / config_file) for config_file in supported_config_files]
cfg = ConfigParser()
cfg.read(filenames)

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(
Expand All @@ -416,12 +413,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 {})
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run_tests(self):
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',
Expand Down