Skip to content

Commit 808bf81

Browse files
committed
Merge branch 'feature/types' into devel
2 parents cd9aceb + a703e7b commit 808bf81

28 files changed

+458
-206
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ Session.vim
6666
.idea/workspace.xml
6767
.idea/tasks.xml
6868
.idea/*.iws
69+
.idea/inspectionProfiles
6970
.mypy_cache/

.idea/ContextShell.iml

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

.idea/fileColors.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/scopes/Sources.xml

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

.idea/scopes/Tests.xml

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

Pipfile

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

66
[packages]
7-
coverage = "==4.5.1"
7+
coverage = "==5.0a1"
88

99
[dev-packages]
1010

Pipfile.lock

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

contextshell/TreeRoot.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
from typing import Dict, Union, Any, Tuple, List
44
from collections import OrderedDict
55

6-
7-
ActionArgsPack = Dict[Union[NodePath, int], Any]
6+
ArgumentValue = Any
7+
ActionArgsPack = Dict[Union[NodePath, int], ArgumentValue]
8+
PositionalArguments = List[ArgumentValue]
9+
KeywordArguments = Dict[str, ArgumentValue]
810

911

12+
# CHECK: Rename TreeRoot to ActionEndpoint or something more appropriate?
1013
class TreeRoot(ABC):
1114
@abstractmethod
12-
def execute(self, target: NodePath, action: NodePath, args: ActionArgsPack):
15+
def execute(self, target: NodePath, action: NodePath, args: ActionArgsPack = None):
1316
raise NotImplementedError()
1417

15-
def unpack_argument_tree(action_args: ActionArgsPack) -> Tuple[List[Any], Dict[str, Any]]:
16-
args = dict()
17-
kwargs: Dict[str, Any] = OrderedDict()
18+
19+
def unpack_argument_tree(action_args: ActionArgsPack) -> Tuple[PositionalArguments, KeywordArguments]:
20+
args: Dict[int, ArgumentValue] = dict()
21+
kwargs: KeywordArguments = OrderedDict()
1822
for key, value in action_args.items():
1923
if isinstance(key, int):
2024
args[key] = value
@@ -25,8 +29,8 @@ def unpack_argument_tree(action_args: ActionArgsPack) -> Tuple[List[Any], Dict[s
2529
return positional_args, kwargs
2630

2731

28-
def pack_argument_tree(args: List[Any], kwargs: Dict[str, Any]) -> ActionArgsPack:
29-
pack_list: List[Tuple[Union[NodePath, int], Any]] = []
32+
def pack_argument_tree(*args: PositionalArguments, **kwargs: KeywordArguments) -> ActionArgsPack:
33+
pack_list: List[Tuple[Union[NodePath, int], ArgumentValue]] = []
3034
for i, arg in enumerate(args):
3135
pack_list.append((i, arg))
3236
for key, value in kwargs.items():
@@ -36,7 +40,7 @@ def pack_argument_tree(args: List[Any], kwargs: Dict[str, Any]) -> ActionArgsPac
3640

3741
def parse_argument_tree(raw_arguments: List[str]) -> ActionArgsPack:
3842
from contextshell.CommandParser import convert_token_type
39-
pack_list: List[Tuple[Union[NodePath, int], Any]] = []
43+
pack_list: List[Tuple[Union[NodePath, int], ArgumentValue]] = []
4044
for i, arg in enumerate(raw_arguments):
4145
if isinstance(arg, str) and '=' in arg:
4246
key, value = arg.split('=')

contextshell/VirtualTree.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
from contextshell.TreeRoot import TreeRoot
1+
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
22
from contextshell.NodePath import NodePath
33
from collections import OrderedDict
44

55

66
class VirtualTree(TreeRoot):
7+
"""Abstract frontend allowing embedding (mounting) of more specific tree roots"""
8+
79
def __init__(self):
810
self.mounts: OrderedDict[NodePath, TreeRoot] = OrderedDict()
911

12+
# TODO: rename to attach/detach
1013
def mount(self, path: NodePath, root: TreeRoot):
1114
if path.is_relative:
1215
raise ValueError("Could not mount relative path")
1316
if path in self.mounts:
1417
raise KeyError("Path '{}' is already provided by {}".format(path, self.mounts[path]))
1518

19+
def path_length_extractor(path_root_pair):
20+
return len(path_root_pair[0])
21+
22+
# CHECK: use bisect module for maintaining mount point list?
1623
updated_items = list(self.mounts.items()) + [(path, root)]
17-
path_length_extractor = lambda pair: len(pair[0])
1824
self.mounts = OrderedDict(sorted(updated_items, key=path_length_extractor, reverse=True))
1925

2026
def umount(self, path: NodePath):
2127
del self.mounts[path]
2228

23-
def execute(self, target: NodePath, action: NodePath, *args):
29+
def execute(self, target: NodePath, action: NodePath, args: ActionArgsPack = None):
2430
if target.is_relative:
25-
raise ValueError("Could not execute with relative target path")
31+
raise ValueError("Could not invoke action with relative target path")
32+
if not args:
33+
args = OrderedDict()
2634
for path, root in self.mounts.items():
2735
if path.is_parent_of(target):
2836
remapped_target = target.relative_to(path)
2937
remapped_target.is_absolute = True
30-
return root.execute(remapped_target, action, *args)
38+
return root.execute(remapped_target, action, args)
3139
else:
3240
raise RuntimeError("Could not find provider for path: '{}'".format(target))

contextshell/backends/Filesystem.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from contextshell.NodePath import NodePath
2+
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
3+
from contextshell.backends.Module import Module
4+
5+
6+
class FilesystemRoot(TreeRoot):
7+
def __init__(self, root_directory_path: str):
8+
self.root_directory_path = root_directory_path
9+
10+
def execute(self, target: NodePath, action: NodePath, args: ActionArgsPack = None):
11+
pass
12+
13+
14+
class FilesystemModule(Module):
15+
pass

0 commit comments

Comments
 (0)