diff --git a/README.rst b/README.rst index 08bd01ad..3af6e0a8 100644 --- a/README.rst +++ b/README.rst @@ -332,12 +332,12 @@ Or with options: Configuration ============= -By default, if ``$HOME/.config/.pep8`` exists, it will be used as global -configuration file. It can specify the configuration file with the -``--global-config`` option. +By default, if ``$HOME/.config/.pycodestyle`` (``~\.pycodestyle`` in Windows +environment) exists, it will be used as global configuration file. It can +specify the configuration file with the ``--global-config`` option. -Also, if ``setup.cfg``, ``tox.ini`` and ``.pep8`` files exist in the -directory where the target file exists, it will be used as the +Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist +in the directory where the target file exists, it will be used as the configuration file. ``pep8``, ``pycodestyle``, and ``flake8`` can be used as a section. diff --git a/autopep8.py b/autopep8.py index 46bf5ec1..b4a50c6b 100755 --- a/autopep8.py +++ b/autopep8.py @@ -122,11 +122,18 @@ class documentation for more information. if sys.platform == 'win32': # pragma: no cover - DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') + DEFAULT_CONFIG = os.path.expanduser(r'~\.pycodestyle') else: DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or - os.path.expanduser('~/.config'), 'pep8') -PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8') + os.path.expanduser('~/.config'), + 'pycodestyle') +# fallback, use .pep8 +if not os.path.exists(DEFAULT_CONFIG): # pragma: no cover + if sys.platform == 'win32': + DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') + else: + DEFAULT_CONFIG = os.path.join(os.path.expanduser('~/.config'), 'pep8') +PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8', '.flake8') MAX_PYTHON_FILE_DETECTION_BYTES = 1024 @@ -1303,8 +1310,8 @@ def fix_w504(self, result): if m: next_line_indent = m.span()[1] self.source[line_index + 1] = '{}{} {}'.format( - next_line[:next_line_indent], target_operator, - next_line[next_line_indent:]) + next_line[:next_line_indent], target_operator, + next_line[next_line_indent:]) def fix_w605(self, result): (line_index, _, target) = get_index_offset_contents(result, @@ -1315,7 +1322,7 @@ def fix_w605(self, result): return for (pos, _msg) in get_w605_position(tokens): self.source[line_index] = '{}r{}'.format( - target[:pos], target[pos:]) + target[:pos], target[pos:]) def get_w605_position(tokens): @@ -1850,7 +1857,7 @@ def _shorten_line(tokens, source, indentation, indent_word, second_indent = indentation if (first.rstrip().endswith('(') and - source[end_offset:].lstrip().startswith(')')): + source[end_offset:].lstrip().startswith(')')): pass elif first.rstrip().endswith('('): second_indent += indent_word