Skip to content

Commit b307930

Browse files
committed
Integrate many pre-commit hooks
1 parent f3e8274 commit b307930

37 files changed

+280
-127
lines changed

.coveragerc

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ exclude_lines =
99
if __name__ == .__main__.:
1010
def __str__
1111
def __repr__
12-

.idea/ContextShell.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dictionaries/idlecode.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scopes/Sources.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scopes/Tests.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
exclude: '^\.idea/.*$'
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: master
5+
hooks:
6+
- id: check-executables-have-shebangs
7+
- id: check-merge-conflict
8+
- id: debug-statements
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
- repo: https://github.com/pre-commit/mirrors-mypy
12+
rev: master
13+
hooks:
14+
- id: mypy
15+
files: 'contextshell|tests'
16+
# - repo: https://github.com/guykisel/prospector-mirror
17+
# rev: master
18+
# hooks:
19+
# - id: prospector
20+
# exclude: "tests"
21+
- repo: https://github.com/asottile/pyupgrade
22+
rev: master
23+
hooks:
24+
- id: pyupgrade
25+
args:
26+
- --py36-plus
27+
- repo: https://github.com/doublify/pre-commit-isort
28+
rev: master
29+
hooks:
30+
- id: isort
31+
- repo: https://github.com/ambv/black
32+
rev: master
33+
hooks:
34+
- id: black
35+
exclude: "tests"
36+
args:
37+
- -l 100
38+
- --py36

.pylintrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ disable=print-statement,
140140
deprecated-sys-function,
141141
exception-escape,
142142
comprehension-escape,
143-
C0111, # Missing docstrings # TODO: re-enable when interfaces are more stable
144-
W0511 # fixme-like strings
143+
bad-continuation,
144+
too-few-public-methods, # TODO: re-enable when interfaces are more stable
145+
C0111, # Missing docstrings # TODO: re-enable when interfaces are more stable
146+
W0511 # fixme-like strings
145147

146148
# Enable the message, report, category or checker with the given id(s). You can
147149
# either give multiple identifier separated by comma (,) or put this option

Pipfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7+
8+
[dev-packages]
9+
mypy = "*"
710
coverage = "==5.0a1"
811
pylint = "*"
912
git-pylint-commit-hook = "*"
10-
11-
[dev-packages]
13+
pre-commit = "*"
1214

1315
[requires]
1416
python_version = "3.7"

Pipfile.lock

+120-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

all_tests.sh

-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ if [[ $TESTS_PASSED -eq 0 ]];
1616
then
1717
coverage report -m
1818
fi
19-

contextshell/action.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from abc import ABC, abstractmethod
22
from collections import OrderedDict
3-
from typing import Union, Any, Tuple
4-
from typing import Callable
5-
from typing import Optional, List, Dict
6-
from .path import NodePath
3+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
74

5+
from .path import NodePath
86

9-
ArgumentValue = Any
7+
ArgumentValue = Any # pylint: disable=invalid-name
108
ActionArgsPack = Dict[Union[NodePath, int], ArgumentValue]
119
PositionalArguments = List[ArgumentValue]
1210
KeywordArguments = Dict[str, ArgumentValue]
1311

1412

15-
class Action(ABC):
13+
class Action(ABC): # pylint: disable=too-few-public-methods
1614
def __init__(self, name: NodePath) -> None:
1715
assert isinstance(name, NodePath)
1816
assert name.is_relative
@@ -25,6 +23,7 @@ def invoke(self, target: NodePath, action: NodePath, arguments: ActionArgsPack):
2523

2624
class CallableAction(Action):
2725
"""Action with implementation based on python callables"""
26+
2827
def __init__(self, implementation: Callable, name: NodePath) -> None:
2928
super().__init__(name)
3029
self.implementation = implementation
@@ -37,8 +36,8 @@ def invoke(self, target: NodePath, action: NodePath, arguments: ActionArgsPack):
3736

3837
def action_from_function(function_to_wrap: Callable) -> Action:
3938
action_name: str = function_to_wrap.__name__
40-
if action_name.endswith('_action'):
41-
action_name = action_name[:-len('_action')]
39+
if action_name.endswith("_action"):
40+
action_name = action_name[: -len("_action")]
4241
action_path = NodePath.from_python_name(action_name)
4342
return CallableAction(function_to_wrap, action_path)
4443

@@ -60,19 +59,21 @@ def execute(self, target: NodePath, action_name: NodePath, args: ActionArgsPack
6059
args = OrderedDict()
6160
action_impl = self.find_action(target, action_name)
6261
if action_impl is None:
63-
raise NameError("Could not find action named '{}'".format(action_name))
62+
raise NameError(f"Could not find action named '{action_name}'")
6463
return action_impl.invoke(target, action_name, args)
6564

6665

67-
def unpack_argument_tree(action_args: ActionArgsPack) -> Tuple[PositionalArguments, KeywordArguments]:
66+
def unpack_argument_tree(
67+
action_args: ActionArgsPack
68+
) -> Tuple[PositionalArguments, KeywordArguments]:
6869
args: Dict[int, ArgumentValue] = dict()
6970
kwargs: KeywordArguments = OrderedDict()
7071
for key, value in action_args.items():
7172
if isinstance(key, int):
7273
args[key] = value
7374
else:
7475
kwargs[key.to_python_name()] = value
75-
assert not args or max(args.keys()) < len(args)+len(kwargs)
76+
assert not args or max(args.keys()) < len(args) + len(kwargs)
7677
positional_args = [a[1] for a in sorted(args.items())]
7778
return positional_args, kwargs
7879

@@ -88,13 +89,14 @@ def pack_argument_tree(*args: PositionalArguments, **kwargs: KeywordArguments) -
8889

8990
def parse_argument_tree(raw_arguments: List[str]) -> ActionArgsPack:
9091
from contextshell.command import convert_token_type
92+
9193
pack_list: List[Tuple[Union[NodePath, int], ArgumentValue]] = []
9294
for i, arg in enumerate(raw_arguments):
93-
if isinstance(arg, str) and '=' in arg:
94-
key, value = arg.split('=')
95+
if isinstance(arg, str) and "=" in arg:
96+
key, value = arg.split("=")
9597
key_path = NodePath.from_python_name(key)
9698
if key_path.is_absolute:
97-
raise ValueError("Named argument path must be relative - {}".format(key_path))
99+
raise ValueError(f"Named argument path must be relative - {key_path}")
98100
typed_value = convert_token_type(value)
99101
pack_list.append((key_path, typed_value))
100102
else:
@@ -104,6 +106,7 @@ def parse_argument_tree(raw_arguments: List[str]) -> ActionArgsPack:
104106

105107
class BuiltinExecutor(ActionExecutor):
106108
"""Manages built-in, global action registry"""
109+
107110
def __init__(self):
108111
super().__init__()
109112
self.builtin_actions: Dict[NodePath, Action] = {}

0 commit comments

Comments
 (0)