Skip to content

Commit

Permalink
Merge pull request #435 from hhatto/change-read-configs
Browse files Browse the repository at this point in the history
Change read configs
  • Loading branch information
hhatto committed Oct 2, 2018
2 parents 7c376c8 + c1a9c4f commit 4d8dc22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.rst
Expand Up @@ -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.
Expand Down
21 changes: 14 additions & 7 deletions autopep8.py
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d8dc22

Please sign in to comment.