|
68 | 68 | DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704'
|
69 | 69 | try:
|
70 | 70 | if sys.platform == 'win32':
|
71 |
| - DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') |
| 71 | + USER_CONFIG = os.path.expanduser(r'~\.pep8') |
72 | 72 | else:
|
73 |
| - DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or |
74 |
| - os.path.expanduser('~/.config'), 'pep8') |
| 73 | + USER_CONFIG = os.path.join( |
| 74 | + os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'), |
| 75 | + 'pep8' |
| 76 | + ) |
75 | 77 | except ImportError:
|
76 |
| - DEFAULT_CONFIG = None |
| 78 | + USER_CONFIG = None |
77 | 79 |
|
78 | 80 | PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8')
|
79 | 81 | TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
|
@@ -1735,13 +1737,11 @@ def __init__(self, *args, **kwargs):
|
1735 | 1737 | # build options from the command line
|
1736 | 1738 | self.checker_class = kwargs.pop('checker_class', Checker)
|
1737 | 1739 | parse_argv = kwargs.pop('parse_argv', False)
|
1738 |
| - config_file = kwargs.pop('config_file', None) |
1739 | 1740 | parser = kwargs.pop('parser', None)
|
1740 | 1741 | # build options from dict
|
1741 | 1742 | options_dict = dict(*args, **kwargs)
|
1742 | 1743 | arglist = None if parse_argv else options_dict.get('paths', None)
|
1743 |
| - options, self.paths = process_options( |
1744 |
| - arglist, parse_argv, config_file, parser) |
| 1744 | + options, self.paths = process_options(arglist, parse_argv, parser) |
1745 | 1745 | if options_dict:
|
1746 | 1746 | options.__dict__.update(options_dict)
|
1747 | 1747 | if 'paths' in options_dict:
|
@@ -1928,17 +1928,22 @@ def read_config(options, args, arglist, parser):
|
1928 | 1928 | """Read both user configuration and local configuration."""
|
1929 | 1929 | config = RawConfigParser()
|
1930 | 1930 |
|
1931 |
| - user_conf = options.config |
1932 |
| - if user_conf and os.path.isfile(user_conf): |
1933 |
| - if options.verbose: |
1934 |
| - print('user configuration: %s' % user_conf) |
1935 |
| - config.read(user_conf) |
| 1931 | + cli_conf = options.config |
1936 | 1932 |
|
| 1933 | + if cli_conf and os.path.isfile(cli_conf): |
| 1934 | + if options.verbose: |
| 1935 | + print('cli configuration: %s' % cli_conf) |
| 1936 | + config.read(cli_conf) |
1937 | 1937 | else:
|
| 1938 | + if USER_CONFIG and os.path.isfile(USER_CONFIG): |
| 1939 | + if options.verbose: |
| 1940 | + print('user configuration: %s' % USER_CONFIG) |
| 1941 | + config.read(USER_CONFIG) |
| 1942 | + |
1938 | 1943 | local_dir = os.curdir
|
1939 | 1944 | parent = tail = args and os.path.abspath(os.path.commonprefix(args))
|
1940 | 1945 | while tail:
|
1941 |
| - if config.read([os.path.join(parent, fn) for fn in PROJECT_CONFIG]): |
| 1946 | + if config.read(os.path.join(parent, fn) for fn in PROJECT_CONFIG): |
1942 | 1947 | local_dir = parent
|
1943 | 1948 | if options.verbose:
|
1944 | 1949 | print('local configuration: in %s' % parent)
|
@@ -1979,21 +1984,18 @@ def read_config(options, args, arglist, parser):
|
1979 | 1984 | return options
|
1980 | 1985 |
|
1981 | 1986 |
|
1982 |
| -def process_options(arglist=None, parse_argv=False, config_file=None, |
1983 |
| - parser=None): |
| 1987 | +def process_options(arglist=None, parse_argv=False, parser=None): |
1984 | 1988 | """Process options passed either via arglist or via command line args."""
|
1985 | 1989 | if not parser:
|
1986 | 1990 | parser = get_parser()
|
1987 | 1991 | if not parser.has_option('--config'):
|
1988 |
| - if config_file is True: |
1989 |
| - config_file = DEFAULT_CONFIG |
1990 | 1992 | group = parser.add_option_group("Configuration", description=(
|
1991 | 1993 | "The project options are read from the [%s] section of the "
|
1992 | 1994 | "tox.ini file or the setup.cfg file located in any parent folder "
|
1993 | 1995 | "of the path(s) being processed. Allowed options are: %s." %
|
1994 | 1996 | (parser.prog, ', '.join(parser.config_options))))
|
1995 |
| - group.add_option('--config', metavar='path', default=config_file, |
1996 |
| - help="user config file location (default: %default)") |
| 1997 | + group.add_option('--config', metavar='path', default=None, |
| 1998 | + help="user config file location") |
1997 | 1999 | # Don't read the command line if the module is used as a library.
|
1998 | 2000 | if not arglist and not parse_argv:
|
1999 | 2001 | arglist = []
|
|
0 commit comments