Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ Quick help is available on the command line::
--benchmark measure processing speed

Configuration:
The project options are read from the [pep8] section of the tox.ini
file or the setup.cfg file located in any parent folder of the path(s)
being processed. Allowed options are: exclude, filename, select,
The project options are read from the [pycodestyle] section of the
tox.ini file or the setup.cfg file located in any parent folder of the
path(s) being processed. Allowed options are: exclude, filename, select,
ignore, max-line-length, hang-closing, count, format, quiet, show-pep8,
show-source, statistics, verbose.

--config=path user config file location (default: ~/.config/pep8)
--config=path user config file location
(default: ~/.config/pycodestyle)


Configuration
Expand All @@ -184,23 +185,23 @@ The behaviour may be configured at two levels, the user and project levels.
At the user level, settings are read from the following locations:

If on Windows:
``~\.pep8``
``~\.pycodestyle``

Otherwise, if the :envvar:`XDG_CONFIG_HOME` environment variable is defined:
``XDG_CONFIG_HOME/pep8``
``XDG_CONFIG_HOME/pycodestyle``

Else if :envvar:`XDG_CONFIG_HOME` is not defined:
``~/.config/pep8``
``~/.config/pycodestyle``

Example::

[pep8]
[pycodestyle]
ignore = E226,E302,E41
max-line-length = 160

At the project level, a ``setup.cfg`` file or a ``tox.ini`` file is read if
present. If none of these files have a ``[pep8]`` section, no project specific
configuration is loaded.
present. If none of these files have a ``[pycodestyle]`` section, no project
specific configuration is loaded.


Error codes
Expand Down
10 changes: 5 additions & 5 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503'
try:
if sys.platform == 'win32':
USER_CONFIG = os.path.expanduser(r'~\.pep8')
USER_CONFIG = os.path.expanduser(r'~\.pycodestyle')
else:
USER_CONFIG = os.path.join(
os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
'pep8'
'pycodestyle'
)
except ImportError:
USER_CONFIG = None
Expand Down Expand Up @@ -1965,7 +1965,7 @@ def get_checks(self, argument_name):
return sorted(checks)


def get_parser(prog='pep8', version=__version__):
def get_parser(prog='pycodestyle', version=__version__):
"""Create the parser for the program."""
parser = OptionParser(prog=prog, version=version,
usage="%prog [options] input ...")
Expand Down Expand Up @@ -2033,7 +2033,7 @@ def read_config(options, args, arglist, parser):
If a config file is specified on the command line with the "--config"
option, then only it is used for configuration.

Otherwise, the user configuration (~/.config/pep8) and any local
Otherwise, the user configuration (~/.config/pycodestyle) and any local
configurations in the current directory or above will be merged together
(in that order) using the read method of ConfigParser.
"""
Expand Down Expand Up @@ -2101,7 +2101,7 @@ def process_options(arglist=None, parse_argv=False, config_file=None,
"""Process options passed either via arglist or via command line args.

Passing in the ``config_file`` parameter allows other tools, such as flake8
to specify their own options to be processed in pep8.
to specify their own options to be processed in pycodestyle.
"""
if not parser:
parser = get_parser()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[wheel]
universal = 1

[pep8]
[pycodestyle]
select =
ignore = E226,E24
max_line_length = 79
2 changes: 1 addition & 1 deletion testsuite/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_styleguide_options(self):
def test_styleguide_ignore_code(self):
def parse_argv(argstring):
_saved_argv = sys.argv
sys.argv = shlex.split('pep8 %s /dev/null' % argstring)
sys.argv = shlex.split('pycodestyle %s /dev/null' % argstring)
try:
return pycodestyle.StyleGuide(parse_argv=True)
finally:
Expand Down
8 changes: 4 additions & 4 deletions testsuite/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ParserTestCase(unittest.TestCase):

def test_vanilla_ignore_parsing(self):
contents = b"""
[pep8]
[pycodestyle]
ignore = E226,E24
"""
options, args = _process_file(contents)
Expand All @@ -28,7 +28,7 @@ def test_vanilla_ignore_parsing(self):

def test_multiline_ignore_parsing(self):
contents = b"""
[pep8]
[pycodestyle]
ignore =
E226,
E24
Expand All @@ -40,7 +40,7 @@ def test_multiline_ignore_parsing(self):

def test_trailing_comma_ignore_parsing(self):
contents = b"""
[pep8]
[pycodestyle]
ignore = E226,
"""

Expand All @@ -50,7 +50,7 @@ def test_trailing_comma_ignore_parsing(self):

def test_multiline_trailing_comma_ignore_parsing(self):
contents = b"""
[pep8]
[pycodestyle]
ignore =
E226,
E24,
Expand Down
48 changes: 26 additions & 22 deletions testsuite/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
self._saved_stdin_get_value = pycodestyle.stdin_get_value
self._config_filenames = []
self.stdin = ''
sys.argv = ['pep8']
sys.argv = ['pycodestyle']
sys.stdout = PseudoFile()
sys.stderr = PseudoFile()

Expand All @@ -39,7 +39,7 @@ def tearDown(self):
def stdin_get_value(self):
return self.stdin

def pep8(self, *args):
def pycodestyle(self, *args):
del sys.stdout[:], sys.stderr[:]
sys.argv[1:] = args
try:
Expand All @@ -50,28 +50,30 @@ def pep8(self, *args):
return sys.stdout.getvalue(), sys.stderr.getvalue(), errorcode

def test_print_usage(self):
stdout, stderr, errcode = self.pep8('--help')
stdout, stderr, errcode = self.pycodestyle('--help')
self.assertFalse(errcode)
self.assertFalse(stderr)
self.assertTrue(stdout.startswith("Usage: pep8 [options] input"))
self.assertTrue(stdout.startswith(
"Usage: pycodestyle [options] input"
))

stdout, stderr, errcode = self.pep8('--version')
stdout, stderr, errcode = self.pycodestyle('--version')
self.assertFalse(errcode)
self.assertFalse(stderr)
self.assertEqual(stdout.count('\n'), 1)

stdout, stderr, errcode = self.pep8('--obfuscated')
stdout, stderr, errcode = self.pycodestyle('--obfuscated')
self.assertEqual(errcode, 2)
self.assertEqual(stderr.splitlines(),
["Usage: pep8 [options] input ...", "",
"pep8: error: no such option: --obfuscated"])
["Usage: pycodestyle [options] input ...", "",
"pycodestyle: error: no such option: --obfuscated"])
self.assertFalse(stdout)

self.assertFalse(self._config_filenames)

def test_check_simple(self):
E11 = os.path.join(ROOT_DIR, 'testsuite', 'E11.py')
stdout, stderr, errcode = self.pep8(E11)
stdout, stderr, errcode = self.pycodestyle(E11)
stdout = stdout.splitlines()
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
Expand All @@ -82,20 +84,20 @@ def test_check_simple(self):
self.assertEqual(x, str(num))
self.assertEqual(y, str(col))
self.assertTrue(msg.startswith(' E11'))
# Config file read from the pep8's setup.cfg
# Config file read from the pycodestyle's setup.cfg
config_filenames = [os.path.basename(p)
for p in self._config_filenames]
self.assertTrue('setup.cfg' in config_filenames)

def test_check_stdin(self):
pycodestyle.PROJECT_CONFIG = ()
stdout, stderr, errcode = self.pep8('-')
stdout, stderr, errcode = self.pycodestyle('-')
self.assertFalse(errcode)
self.assertFalse(stderr)
self.assertFalse(stdout)

self.stdin = 'import os, sys\n'
stdout, stderr, errcode = self.pep8('-')
stdout, stderr, errcode = self.pycodestyle('-')
stdout = stdout.splitlines()
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
Expand All @@ -104,19 +106,19 @@ def test_check_stdin(self):

def test_check_non_existent(self):
self.stdin = 'import os, sys\n'
stdout, stderr, errcode = self.pep8('fictitious.py')
stdout, stderr, errcode = self.pycodestyle('fictitious.py')
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
self.assertTrue(stdout.startswith('fictitious.py:1:1: E902 '))

def test_check_noarg(self):
# issue #170: do not read stdin by default
pycodestyle.PROJECT_CONFIG = ()
stdout, stderr, errcode = self.pep8()
stdout, stderr, errcode = self.pycodestyle()
self.assertEqual(errcode, 2)
self.assertEqual(stderr.splitlines(),
["Usage: pep8 [options] input ...", "",
"pep8: error: input not specified"])
["Usage: pycodestyle [options] input ...", "",
"pycodestyle: error: input not specified"])
self.assertFalse(self._config_filenames)

def test_check_diff(self):
Expand All @@ -136,7 +138,7 @@ def test_check_diff(self):
]

self.stdin = '\n'.join(diff_lines)
stdout, stderr, errcode = self.pep8('--diff')
stdout, stderr, errcode = self.pycodestyle('--diff')
stdout = stdout.splitlines()
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
Expand All @@ -149,7 +151,7 @@ def test_check_diff(self):
diff_lines[:2] = ["--- a/testsuite/E11.py 2006-06-01 08:49 +0400",
"+++ b/testsuite/E11.py 2008-04-06 17:36 +0400"]
self.stdin = '\n'.join(diff_lines)
stdout, stderr, errcode = self.pep8('--diff')
stdout, stderr, errcode = self.pycodestyle('--diff')
stdout = stdout.splitlines()
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
Expand All @@ -167,23 +169,25 @@ def test_check_diff(self):
"@@ -5,0 +6 @@ if True:",
"+ print"]
self.stdin = '\n'.join(diff_lines)
stdout, stderr, errcode = self.pep8('--diff')
stdout, stderr, errcode = self.pycodestyle('--diff')
(stdout,) = stdout.splitlines()
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
self.assertTrue('testsuite/E11.py:6:6: E111 ' in stdout)

# missing '--diff'
self.stdin = '\n'.join(diff_lines)
stdout, stderr, errcode = self.pep8()
stdout, stderr, errcode = self.pycodestyle()
self.assertEqual(errcode, 2)
self.assertFalse(stdout)
self.assertTrue(stderr.startswith('Usage: pep8 [options] input ...'))
self.assertTrue(stderr.startswith(
'Usage: pycodestyle [options] input ...'
))

# no matching file in the diff
diff_lines[3] = "+++ b/testsuite/lost/E11.py"
self.stdin = '\n'.join(diff_lines)
stdout, stderr, errcode = self.pep8('--diff')
stdout, stderr, errcode = self.pycodestyle('--diff')
self.assertFalse(errcode)
self.assertFalse(stdout)
self.assertFalse(stderr)