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

Add config file support #940

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions pyupgrade/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Match
from typing import Sequence

import configargparse
from tokenize_rt import NON_CODING_TOKENS
from tokenize_rt import parse_string_literal
from tokenize_rt import reversed_enumerate
Expand Down Expand Up @@ -339,9 +340,18 @@ def _fix_file(filename: str, args: argparse.Namespace) -> int:
return contents_text != contents_text_orig


def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
def _build_config_arg_parser() -> configargparse.ArgumentParser:
config_parser = configargparse.TomlConfigParser(['tool.pyupgrade'])
parser = configargparse.ArgumentParser(
default_config_files=['pyupgrade.toml', 'pyproject.toml'],
config_file_parser_class=config_parser,
)

parser.add_argument('filenames', nargs='*')
parser.add_argument(
'--config-file',
is_config_file=True, help='config file path',
)
parser.add_argument('--exit-zero-even-if-changed', action='store_true')
parser.add_argument('--keep-percent-format', action='store_true')
parser.add_argument('--keep-mock', action='store_true')
Expand Down Expand Up @@ -378,6 +388,12 @@ def main(argv: Sequence[str] | None = None) -> int:
'--py312-plus',
action='store_const', dest='min_version', const=(3, 12),
)

return parser


def main(argv: Sequence[str] | None = None) -> int:
parser = _build_config_arg_parser()
args = parser.parse_args(argv)

ret = 0
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers =
[options]
packages = find:
install_requires =
ConfigArgParse>=1.7.0
tokenize-rt>=5.2.0
python_requires = >=3.8.1

Expand Down