Skip to content

Commit 2289a54

Browse files
committed
Re-enable prospector hook and fix reported issues
1 parent b307930 commit 2289a54

20 files changed

+189
-156
lines changed

.idea/dictionaries/idlecode.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ repos:
88
- id: debug-statements
99
- id: end-of-file-fixer
1010
- 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"
2111
- repo: https://github.com/asottile/pyupgrade
2212
rev: master
2313
hooks:
@@ -28,6 +18,9 @@ repos:
2818
rev: master
2919
hooks:
3020
- id: isort
21+
args:
22+
- --multi-line=3
23+
- --keep-direct-and-as
3124
- repo: https://github.com/ambv/black
3225
rev: master
3326
hooks:
@@ -36,3 +29,13 @@ repos:
3629
args:
3730
- -l 100
3831
- --py36
32+
- repo: https://github.com/guykisel/prospector-mirror
33+
rev: master
34+
hooks:
35+
- id: prospector
36+
exclude: "tests"
37+
- repo: https://github.com/pre-commit/mirrors-mypy
38+
rev: master
39+
hooks:
40+
- id: mypy
41+
files: 'contextshell|tests'

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ max-locals=10
525525
max-parents=5
526526

527527
# Maximum number of public methods for a class (see R0904).
528-
max-public-methods=20
528+
max-public-methods=30
529529

530530
# Maximum number of return / yield for function / method body.
531531
max-returns=6

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7+
pre-commit = "*"
78

89
[dev-packages]
910
mypy = "*"

Pipfile.lock

Lines changed: 114 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contextshell/action.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
KeywordArguments = Dict[str, ArgumentValue]
1111

1212

13-
class Action(ABC): # pylint: disable=too-few-public-methods
13+
class Action(ABC):
1414
def __init__(self, name: NodePath) -> None:
1515
assert isinstance(name, NodePath)
1616
assert name.is_relative
@@ -87,23 +87,6 @@ def pack_argument_tree(*args: PositionalArguments, **kwargs: KeywordArguments) -
8787
return OrderedDict(pack_list)
8888

8989

90-
def parse_argument_tree(raw_arguments: List[str]) -> ActionArgsPack:
91-
from contextshell.command import convert_token_type
92-
93-
pack_list: List[Tuple[Union[NodePath, int], ArgumentValue]] = []
94-
for i, arg in enumerate(raw_arguments):
95-
if isinstance(arg, str) and "=" in arg:
96-
key, value = arg.split("=")
97-
key_path = NodePath.from_python_name(key)
98-
if key_path.is_absolute:
99-
raise ValueError(f"Named argument path must be relative - {key_path}")
100-
typed_value = convert_token_type(value)
101-
pack_list.append((key_path, typed_value))
102-
else:
103-
pack_list.append((i, arg))
104-
return OrderedDict(pack_list)
105-
106-
10790
class BuiltinExecutor(ActionExecutor):
10891
"""Manages built-in, global action registry"""
10992

contextshell/backends/node.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ class Node:
88
def __init__(self, value=None):
99
self._value = value
1010
self._subnodes = [] # TODO: use OrderedDict?
11-
self._parent = None
12-
13-
@property
14-
def parent(self) -> "Node":
15-
"""Return parent of this node"""
16-
return self._parent
11+
self.parent = None
1712

1813
def get(self):
1914
"""Get value stored in this node"""
@@ -46,7 +41,7 @@ def append(self, node: "Node", name: str = None):
4641
raise NameError("Invalid appended node name - empty")
4742
if self.get_node(name) is not None:
4843
raise NameError(f"Node '{name}' already exists")
49-
node._parent = self
44+
node.parent = self
5045
self._subnodes.append((name, node))
5146

5247
def get_node(self, name: str = None, index: int = None) -> Optional["Node"]:
@@ -78,7 +73,7 @@ def remove(self, name: str = None, index: int = None) -> "Node":
7873
if node_to_remove is None:
7974
raise NameError(f"Node '{name}' doesn't exists")
8075
self._subnodes = [p for p in self._subnodes if p[1] is not node_to_remove]
81-
node_to_remove._parent = None
76+
node_to_remove.parent = None
8277
return node_to_remove
8378

8479
def contains(self, name: str = None, index: int = None) -> bool:
@@ -94,7 +89,7 @@ class NodeTreeRoot(ActionExecutor):
9489
"""Frontend to the (passive) node-based data storage"""
9590

9691
def __init__(self):
97-
self.root = self.create_node(None)
92+
self.root = Node(None)
9893
self.install_default_actions()
9994

10095
def create_action(self, target: NodePath, path: str, value=None): # NOCOVER
@@ -198,12 +193,9 @@ def find_type(self, target: NodePath, type_name: NodePath): # TODO: add type-hi
198193
return None
199194
return type_node.get()
200195

201-
def create_node(self, value):
202-
return Node(value)
203-
204196
def create(self, path: NodePath, initial_value=None):
205197
parent = self._create_path(path.base_path)
206-
new_node = self.create_node(initial_value)
198+
new_node = Node(initial_value)
207199
parent.append(new_node, path.base_name)
208200

209201
def contains(self, path: NodePath) -> bool:
@@ -258,6 +250,6 @@ def _create_path(self, path: NodePath, root: Node = None) -> Node:
258250

259251
next_branch_name = path[0]
260252
if not root.contains(next_branch_name):
261-
new_node = self.create_node(None)
253+
new_node = Node(None)
262254
root.append(new_node, next_branch_name)
263255
return self._create_path(NodePath.cast(path[1:]), root.get_node(next_branch_name))

contextshell/command.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import List, Optional
1+
from collections.__init__ import OrderedDict
2+
from typing import List, Optional, Tuple, Union
23

3-
from contextshell.action import ActionExecutor, parse_argument_tree
4-
from contextshell.path import NodePath
4+
from .action import ActionArgsPack, ActionExecutor, ArgumentValue
5+
from .path import NodePath
56

67

78
class Command:
@@ -131,3 +132,18 @@ def _parse_scope(self, token_iterator) -> Command:
131132
cmd = Command(parts[0])
132133
cmd.arguments = parts[1:]
133134
return cmd
135+
136+
137+
def parse_argument_tree(raw_arguments: List[str]) -> ActionArgsPack:
138+
pack_list: List[Tuple[Union[NodePath, int], ArgumentValue]] = []
139+
for i, arg in enumerate(raw_arguments):
140+
if isinstance(arg, str) and "=" in arg:
141+
key, value = arg.split("=")
142+
key_path = NodePath.from_python_name(key)
143+
if key_path.is_absolute:
144+
raise ValueError(f"Named argument path must be relative - {key_path}")
145+
typed_value = convert_token_type(value)
146+
pack_list.append((key_path, typed_value))
147+
else:
148+
pack_list.append((i, arg))
149+
return OrderedDict(pack_list)

0 commit comments

Comments
 (0)