asottile / pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
MIT License
3.5k stars 177 forks source link

Add config file support #940

Closed chrisbouchard closed 5 months ago

chrisbouchard commented 5 months ago

Add support for configuration files in pyupgrade using ConfigArgParse.

By default, we'll look for a tool.pyupgrade section in pyupgrade.toml or pyproject.toml (in that order), and read the configuration from there. Command line arguments will override configuration file settings, which will override command line argument defaults. We also add a --config-file option to override the config file path.

Fixes #511.

Example Output

% pyupgrade -h
usage: pyupgrade [-h] [--config-file CONFIG_FILE] [--exit-zero-even-if-changed] [--keep-percent-format] [--keep-mock] [--keep-runtime-typing] [--py3-plus]
                 [--py36-plus] [--py37-plus] [--py38-plus] [--py39-plus] [--py310-plus] [--py311-plus] [--py312-plus]
                 [filenames ...]

positional arguments:
  filenames

options:
  -h, --help            show this help message and exit
  --config-file CONFIG_FILE
                        config file path
  --exit-zero-even-if-changed
  --keep-percent-format
  --keep-mock
  --keep-runtime-typing
  --py3-plus, --py3-only
  --py36-plus
  --py37-plus
  --py38-plus
  --py39-plus
  --py310-plus
  --py311-plus
  --py312-plus

Args that start with '--' can also be set in a config file (pyupgrade.toml or pyproject.toml or specified via --config-file). Config file syntax is Tom's
Obvious, Minimal Language. See https://github.com/toml-lang/toml/blob/v0.5.0/README.md for details. In general, command-line values override config file
values which override defaults.

TODO

asottile commented 5 months ago

no thanks, this has been rejected before please search next time

asottile commented 5 months ago

oh you did find the duplicate and decided to waste both of our time anyway