Skip to content

Commit

Permalink
Upgrade pre-commit and apply fixes automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Aug 26, 2021
1 parent 6218638 commit 06e678a
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
fail_fast: true
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: fix-encoding-pragma
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 21.7b0
hooks:
- id: black
args:
- --exclude=/(tests)/
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.2
rev: 3.9.2
hooks:
- id: flake8
args:
Expand Down
16 changes: 14 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,20 @@

# Custom sidebar templates, maps document names to template names.
html_sidebars = {
"index": ["slim_searchbox.html", "sidebarintro.html", "globaltoc.html", "links.html", "sourcelink.html",],
"**": ["slim_searchbox.html", "globaltoc.html", "relations.html", "links.html", "sourcelink.html",],
"index": [
"slim_searchbox.html",
"sidebarintro.html",
"globaltoc.html",
"links.html",
"sourcelink.html",
],
"**": [
"slim_searchbox.html",
"globaltoc.html",
"relations.html",
"links.html",
"sourcelink.html",
],
}

# Additional templates that should be rendered to pages, maps page names to
Expand Down
10 changes: 8 additions & 2 deletions prospector/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def blend_line(messages, blend_combos=None):
for blend_combo_idx, blend_list in enumerate(blend_lists):
if len(blend_list) == 0:
continue
blend_list.sort(key=lambda msg: blend_combos[blend_combo_idx].index((msg.source, msg.code),),)
blend_list.sort(
key=lambda msg: blend_combos[blend_combo_idx].index(
(msg.source, msg.code),
),
)
if blend_list[0] not in blended:
# We may have already added this message if it represents
# several messages in other tools which are not being run -
Expand All @@ -81,7 +85,9 @@ def blend(messages, blend_combos=None):
msgs_grouped = defaultdict(lambda: defaultdict(list))

for message in messages:
msgs_grouped[message.location.path][message.location.line].append(message,)
msgs_grouped[message.location.path][message.location.line].append(
message,
)

# now blend together all messages on the same line
out = []
Expand Down
59 changes: 50 additions & 9 deletions prospector/config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,33 @@ def build_manager():

manager.add(soc.BooleanSetting("messages_only", default=False))
manager.add(soc.BooleanSetting("summary_only", default=False))
manager.add(soc.ListSetting("output_format", OutputChoice(sorted(FORMATTERS.keys())), default=None,))
manager.add(
soc.ListSetting(
"output_format",
OutputChoice(sorted(FORMATTERS.keys())),
default=None,
)
)
manager.add(soc.BooleanSetting("absolute_paths", default=False))

manager.add(soc.ListSetting("tools", soc.Choice(sorted(TOOLS.keys())), default=None,))
manager.add(
soc.ListSetting(
"tools",
soc.Choice(sorted(TOOLS.keys())),
default=None,
)
)
manager.add(soc.ListSetting("with_tools", soc.String, default=[]))
manager.add(soc.ListSetting("without_tools", soc.String, default=[]))
manager.add(soc.ListSetting("profiles", soc.String, default=[]))
manager.add(soc.ListSetting("profile_path", soc.String, default=[]))
manager.add(soc.ChoiceSetting("strictness", ["veryhigh", "high", "medium", "low", "verylow"], default=None,))
manager.add(
soc.ChoiceSetting(
"strictness",
["veryhigh", "high", "medium", "low", "verylow"],
default=None,
)
)
manager.add(soc.BooleanSetting("show_profile", default=False))

manager.add(soc.BooleanSetting("no_external_config", default=False))
Expand All @@ -58,8 +76,19 @@ def build_default_sources():
sources = [
build_command_line_source(),
soc.EnvironmentVariableSource(),
soc.ConfigFileSource((".prospectorrc", "setup.cfg", "tox.ini",)),
soc.ConfigFileSource((soc.ConfigDirectory(".prospectorrc"), soc.HomeDirectory(".prospectorrc"),)),
soc.ConfigFileSource(
(
".prospectorrc",
"setup.cfg",
"tox.ini",
)
),
soc.ConfigFileSource(
(
soc.ConfigDirectory(".prospectorrc"),
soc.HomeDirectory(".prospectorrc"),
)
),
]

return sources
Expand Down Expand Up @@ -102,8 +131,14 @@ def build_command_line_source(prog=None, description="Performs static analysis o
" the same error. Use this option to see all unmerged"
" messages.",
},
"doc_warnings": {"flags": ["-D", "--doc-warnings"], "help": "Include warnings about documentation.",},
"test_warnings": {"flags": ["-T", "--test-warnings"], "help": "Also check test modules and packages.",},
"doc_warnings": {
"flags": ["-D", "--doc-warnings"],
"help": "Include warnings about documentation.",
},
"test_warnings": {
"flags": ["-T", "--test-warnings"],
"help": "Also check test modules and packages.",
},
"no_style_warnings": {
"flags": ["-8", "--no-style-warnings"],
"help": "Don't create any warnings about style. This disables the"
Expand Down Expand Up @@ -148,7 +183,10 @@ def build_command_line_source(prog=None, description="Performs static analysis o
"tools to run. To add extra tools to the defaults, see "
"--with-tool. Possible values are: %s. By "
"default, the following tools will be run: %s"
% (", ".join(sorted(TOOLS.keys())), ", ".join(sorted(DEFAULT_TOOLS)),),
% (
", ".join(sorted(TOOLS.keys())),
", ".join(sorted(DEFAULT_TOOLS)),
),
},
"with_tools": {
"flags": ["-w", "--with-tool"],
Expand Down Expand Up @@ -264,5 +302,8 @@ def build_command_line_source(prog=None, description="Performs static analysis o
)

return soc.CommandLineSource(
options=options, version=__version__, parser_options=parser_options, positional=positional,
options=options,
version=__version__,
parser_options=parser_options,
positional=positional,
)
7 changes: 6 additions & 1 deletion prospector/formatters/emacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
class EmacsFormatter(TextFormatter):
def render_message(self, message):
output = [
"%s:%s:%d:" % (message.location.path, message.location.line, (message.location.character or 0) + 1,),
"%s:%s:%d:"
% (
message.location.path,
message.location.line,
(message.location.character or 0) + 1,
),
" L%s:%s %s: %s - %s"
% (
message.location.line or "-",
Expand Down
8 changes: 7 additions & 1 deletion prospector/formatters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def render_summary(self):
value = summary_label[2](self.summary[key])
else:
value = self.summary[key]
output.append(" %s: %s" % (label.rjust(label_width), value,))
output.append(
" %s: %s"
% (
label.rjust(label_width),
value,
)
)

return "\n".join(output)

Expand Down
7 changes: 6 additions & 1 deletion prospector/formatters/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ def render(self, summary=True, messages=True, profile=False):
if messages:
output["messages"] = [m.as_dict() for m in self.messages]

return yaml.safe_dump(output, indent=2, default_flow_style=False, allow_unicode=True,)
return yaml.safe_dump(
output,
indent=2,
default_flow_style=False,
allow_unicode=True,
)
5 changes: 4 additions & 1 deletion prospector/postfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def filter_messages(relative_filepaths, root, messages):
# first get rid of the pylint informational messages
relative_message_path = os.path.relpath(message.location.path)

if message.source == "pylint" and message.code in ("suppressed-message", "file-ignored",):
if message.source == "pylint" and message.code in (
"suppressed-message",
"file-ignored",
):
continue

# some files are skipped entirely by messages
Expand Down
28 changes: 23 additions & 5 deletions prospector/profiles/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def __init__(self, name, profile_path):
self.profile_path = profile_path

def __repr__(self):
return "Could not find profile %s; searched in %s" % (self.name, ":".join(self.profile_path),)
return "Could not find profile %s; searched in %s" % (
self.name,
":".join(self.profile_path),
)


class CannotParseProfile(Exception):
Expand Down Expand Up @@ -113,7 +116,10 @@ def as_yaml(self):
def load(name_or_path, profile_path, allow_shorthand=True, forced_inherits=None):
# First simply load all of the profiles and those that it explicitly inherits from
data, inherits = _load_and_merge(
name_or_path, profile_path, allow_shorthand, forced_inherits=forced_inherits or [],
name_or_path,
profile_path,
allow_shorthand,
forced_inherits=forced_inherits or [],
)
return ProspectorProfile(name_or_path, data, inherits)

Expand Down Expand Up @@ -301,7 +307,10 @@ def _append_profiles(name, profile_path, data, inherit_list, allow_shorthand=Fal
def _load_and_merge(name_or_path, profile_path, allow_shorthand=True, forced_inherits=None):
# First simply load all of the profiles and those that it explicitly inherits from
data, inherit_list, shorthands_found = _load_profile(
name_or_path, profile_path, allow_shorthand=allow_shorthand, forced_inherits=forced_inherits or [],
name_or_path,
profile_path,
allow_shorthand=allow_shorthand,
forced_inherits=forced_inherits or [],
)

if allow_shorthand:
Expand Down Expand Up @@ -335,7 +344,12 @@ def _load_and_merge(name_or_path, profile_path, allow_shorthand=True, forced_inh


def _load_profile(
name_or_path, profile_path, shorthands_found=None, already_loaded=None, allow_shorthand=True, forced_inherits=None,
name_or_path,
profile_path,
shorthands_found=None,
already_loaded=None,
allow_shorthand=True,
forced_inherits=None,
):
# recursively get the contents of the basic profile and those it inherits from
base_contents = _load_content(name_or_path, profile_path)
Expand Down Expand Up @@ -366,7 +380,11 @@ def _load_profile(

already_loaded.append(inherit_profile)
new_cd, new_il, new_sh = _load_profile(
inherit_profile, profile_path, shorthands_found, already_loaded, allow_shorthand,
inherit_profile,
profile_path,
shorthands_found,
already_loaded,
allow_shorthand,
)
contents_dict.update(new_cd)
inherit_order += new_il
Expand Down
22 changes: 18 additions & 4 deletions prospector/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def execute(self):
summary.update(self.config.get_summary_information())

found_files = find_python(
self.config.ignores, self.config.paths, self.config.explicit_file_mode, self.config.workdir,
self.config.ignores,
self.config.paths,
self.config.explicit_file_mode,
self.config.workdir,
)

# Run the tools
Expand All @@ -70,10 +73,16 @@ def execute(self):
loc = Location(self.config.workdir, None, None, None, None)

if capture.get_hidden_stderr():
msg = "stderr from %s:\n%s" % (toolname, capture.get_hidden_stderr(),)
msg = "stderr from %s:\n%s" % (
toolname,
capture.get_hidden_stderr(),
)
messages.append(Message(toolname, "hidden-output", loc, message=msg))
if capture.get_hidden_stdout():
msg = "stdout from %s:\n%s" % (toolname, capture.get_hidden_stdout(),)
msg = "stdout from %s:\n%s" % (
toolname,
capture.get_hidden_stdout(),
)
messages.append(Message(toolname, "hidden-output", loc, message=msg))

except FatalProspectorException as fatal:
Expand All @@ -86,7 +95,12 @@ def execute(self):
else:
loc = Location(self.config.workdir, None, None, None, None)
msg = "Tool %s failed to run (exception was raised)" % (toolname,)
message = Message(toolname, "failure", loc, message=msg,)
message = Message(
toolname,
"failure",
loc,
message=msg,
)
messages.append(message)

messages = self.process_messages(found_files, messages)
Expand Down
5 changes: 4 additions & 1 deletion prospector/suppression.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def get_noqa_suppressions(file_contents):

_PYLINT_EQUIVALENTS = {
# TODO: blending has this info already?
"unused-import": (("pyflakes", "FL0001"), ("frosted", "E101"),)
"unused-import": (
("pyflakes", "FL0001"),
("frosted", "E101"),
)
}


Expand Down
9 changes: 8 additions & 1 deletion prospector/tools/dodgy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ def run(self, found_files):
for warning in warnings:
path = warning["path"]
prefix = os.path.commonprefix([found_files.rootpath, path])
loc = Location(path, module_from_path(path[len(prefix) :]), "", warning["line"], 0, absolute_path=True,)
loc = Location(
path,
module_from_path(path[len(prefix) :]),
"",
warning["line"],
0,
absolute_path=True,
)
msg = Message("dodgy", warning["code"], loc, warning["message"])
messages.append(msg)

Expand Down
19 changes: 16 additions & 3 deletions prospector/tools/frosted/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@ def record_message(self, filename=None, line=None, character=None, code=None, me
if code in self.ignore:
return

location = Location(path=filename, module=None, function=None, line=line, character=character,)
message = Message(source="frosted", code=code, location=location, message=message,)
location = Location(
path=filename,
module=None,
function=None,
line=line,
character=character,
)
message = Message(
source="frosted",
code=code,
location=location,
message=message,
)
self._messages.append(message)

def unexpected_error(self, filename, msg):
self.record_message(
filename=filename, code="U999", message=msg,
filename=filename,
code="U999",
message=msg,
)

def flake(self, message):
Expand Down
Loading

0 comments on commit 06e678a

Please sign in to comment.