pep8 API
The library provides classes which are usable by third party tools.
The StyleGuide class is used to configure a style guide checker
instance to check multiple files.
The Checker class can be used to check a single file.
-
class pep8.StyleGuide(parse_argv=False, config_file=None, parser=None, paths=None, report=None, **kwargs)[source]
Initialize a PEP-8 instance with few options.
-
init_report(reporter=None)[source]
Initialize the report instance.
-
check_files(paths=None)[source]
Run all checks on the paths.
-
input_file(filename, lines=None, expected=None, line_offset=0)[source]
Run all checks on a Python source file.
-
input_dir(dirname)[source]
Check all files in this directory and all subdirectories.
-
excluded(filename)[source]
Check if options.exclude contains a pattern that matches filename.
-
ignore_code(code)[source]
Check if the error code should be ignored.
If ‘options.select’ contains a prefix of the error code,
return False. Else, if ‘options.ignore’ contains a prefix of
the error code, return True.
-
get_checks(argument_name)[source]
Find all globally visible functions where the first argument name
starts with argument_name and which contain selected tests.
-
class pep8.Checker(filename=None, lines=None, report=None, **kwargs)[source]
Load a Python source file, tokenize it, check coding style.
-
readline()[source]
Get the next line from the input buffer.
-
readline_check_physical()[source]
Check and return the next physical line. This method can be
used to feed tokenize.generate_tokens.
-
run_check(check, argument_names)[source]
Run a check plugin.
-
check_physical(line)[source]
Run all physical checks on a raw input line.
-
build_tokens_line()[source]
Build a logical line from tokens.
-
check_logical()[source]
Build a line from tokens and run all logical checks on it.
-
check_ast()[source]
-
generate_tokens()[source]
-
check_all(expected=None, line_offset=0)[source]
Run all checks on the input file.
-
class pep8.BaseReport(options)[source]
Collect the results of the checks.
-
start()[source]
Start the timer.
-
stop()[source]
Stop the timer.
-
init_file(filename, lines, expected, line_offset)[source]
Signal a new file.
-
increment_logical_line()[source]
Signal a new logical line.
-
error(line_number, offset, text, check)[source]
Report an error, according to options.
-
get_file_results()[source]
Return the count of errors and warnings for this file.
-
get_count(prefix='')[source]
Return the total count of errors and warnings.
-
get_statistics(prefix='')[source]
Get statistics for message codes that start with the prefix.
prefix=’’ matches all errors and warnings
prefix=’E’ matches all errors
prefix=’W’ matches all warnings
prefix=’E4’ matches all errors that have to do with imports
-
print_statistics(prefix='')[source]
Print overall statistics (number of errors and warnings).
-
print_benchmark()[source]
Print benchmark numbers.
-
class pep8.FileReport(options)[source]
Collect the results of the checks and print only the filenames.
-
class pep8.StandardReport(options)[source]
Collect and print the results of the checks.
-
class pep8.DiffReport(options)[source]
Collect and print the results for the changed lines only.
-
pep8.expand_indent(line)[source]
Return the amount of indentation.
Tabs are expanded to the next multiple of 8.
>>> expand_indent(' ')
4
>>> expand_indent('\t')
8
>>> expand_indent(' \t')
8
>>> expand_indent(' \t')
8
>>> expand_indent(' \t')
16
-
pep8.mute_string(text)[source]
Replace contents with ‘xxx’ to prevent syntax matching.
>>> mute_string('"abc"')
'"xxx"'
>>> mute_string("'''abc'''")
"'''xxx'''"
>>> mute_string("r'abc'")
"r'xxx'"
-
pep8.read_config(options, args, arglist, parser)[source]
Read both user configuration and local configuration.
-
pep8.process_options(arglist=None, parse_argv=False, config_file=None)[source]
Process options passed either via arglist or via command line args.
-
pep8.register_check(func_or_cls, codes=None)[source]
Register a new check object.