Skip to content

Commit 1646d65

Browse files
chore: fix lint errors
1 parent aece22f commit 1646d65

11 files changed

+244
-200
lines changed

ipyvue/ForceLoad.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
class ForceLoad(DOMWidget):
7-
_model_name = Unicode('ForceLoadModel').tag(sync=True)
8-
_model_module = Unicode('jupyter-vue').tag(sync=True)
7+
_model_name = Unicode("ForceLoadModel").tag(sync=True)
8+
_model_module = Unicode("jupyter-vue").tag(sync=True)
99
_model_module_version = Unicode(semver).tag(sync=True)
1010

1111

ipyvue/Html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Html(VueWidget):
66

7-
_model_name = Unicode('HtmlModel').tag(sync=True)
7+
_model_name = Unicode("HtmlModel").tag(sync=True)
88

99
tag = Unicode().tag(sync=True)
1010

1111

12-
__all__ = ['Html']
12+
__all__ = ["Html"]

ipyvue/Template.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
template_registry = {}
77

88

9-
def watch(path=''):
9+
def watch(path=""):
1010
import logging
1111
from watchdog.observers import Observer
1212
from watchdog.events import FileSystemEventHandler
1313

14-
log = logging.getLogger('ipyvue')
14+
log = logging.getLogger("ipyvue")
15+
1516
class VueEventHandler(FileSystemEventHandler):
1617
def on_modified(self, event):
1718
super(VueEventHandler, self).on_modified(event)
1819
if not event.is_directory:
1920
if event.src_path in template_registry:
20-
log.info(f'updating: {event.src_path}')
21+
log.info(f"updating: {event.src_path}")
2122
with open(event.src_path) as f:
2223
template_registry[event.src_path].template = f.read()
2324

2425
observer = Observer()
2526
path = os.path.normpath(path)
26-
log.info(f'watching {path}')
27+
log.info(f"watching {path}")
2728
observer.schedule(VueEventHandler(), path, recursive=True)
2829
observer.start()
2930

@@ -41,11 +42,11 @@ def get_template(abs_path):
4142

4243

4344
class Template(Widget):
44-
_model_name = Unicode('TemplateModel').tag(sync=True)
45-
_model_module = Unicode('jupyter-vue').tag(sync=True)
45+
_model_name = Unicode("TemplateModel").tag(sync=True)
46+
_model_module = Unicode("jupyter-vue").tag(sync=True)
4647
_model_module_version = Unicode(semver).tag(sync=True)
4748

4849
template = Unicode(None, allow_none=True).tag(sync=True)
4950

5051

51-
__all__ = ['Template', 'watch']
52+
__all__ = ["Template", "watch"]

ipyvue/VueComponentRegistry.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
class VueComponent(DOMWidget):
7-
_model_name = Unicode('VueComponentModel').tag(sync=True)
8-
_model_module = Unicode('jupyter-vue').tag(sync=True)
7+
_model_name = Unicode("VueComponentModel").tag(sync=True)
8+
_model_module = Unicode("jupyter-vue").tag(sync=True)
99
_model_module_version = Unicode(semver).tag(sync=True)
1010

1111
name = Unicode().tag(sync=True)
@@ -31,4 +31,8 @@ def register_component_from_file(self, name, file_name):
3131
register_component_from_string(name, f.read())
3232

3333

34-
__all__ = ['VueComponent', 'register_component_from_string', 'register_component_from_file']
34+
__all__ = [
35+
"VueComponent",
36+
"register_component_from_string",
37+
"register_component_from_file",
38+
]

ipyvue/VueTemplateWidget.py

+56-48
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import inspect
1010
from importlib import import_module
1111

12-
OBJECT_REF = 'objectRef'
13-
FUNCTION_REF = 'functionRef'
12+
OBJECT_REF = "objectRef"
13+
FUNCTION_REF = "functionRef"
1414

1515

1616
class Events(object):
@@ -23,94 +23,98 @@ def resolve_ref(value):
2323
if isinstance(value, dict):
2424
if OBJECT_REF in value.keys():
2525
obj = getattr(self, value[OBJECT_REF])
26-
for path_item in value.get('path', []):
26+
for path_item in value.get("path", []):
2727
obj = obj[path_item]
2828
return obj
2929
if FUNCTION_REF in value.keys():
3030
fn = getattr(self, value[FUNCTION_REF])
31-
args = value.get('args', [])
32-
kwargs = value.get('kwargs', {})
31+
args = value.get("args", [])
32+
kwargs = value.get("kwargs", {})
3333
return fn(*args, **kwargs)
3434
return value
3535

36-
if 'create_widget' in content.keys():
37-
module_name = content['create_widget'][0]
38-
class_name = content['create_widget'][1]
39-
props = {k: resolve_ref(v) for k, v in content['props'].items()}
36+
if "create_widget" in content.keys():
37+
module_name = content["create_widget"][0]
38+
class_name = content["create_widget"][1]
39+
props = {k: resolve_ref(v) for k, v in content["props"].items()}
4040
module = import_module(module_name)
41-
widget = getattr(module, class_name)(**props, model_id=content['id'])
41+
widget = getattr(module, class_name)(**props, model_id=content["id"])
4242
self._component_instances = [*self._component_instances, widget]
43-
elif 'update_ref' in content.keys():
44-
widget = DOMWidget.widgets[content['id']]
45-
prop = content['prop']
46-
obj = resolve_ref(content['update_ref'])
43+
elif "update_ref" in content.keys():
44+
widget = DOMWidget.widgets[content["id"]]
45+
prop = content["prop"]
46+
obj = resolve_ref(content["update_ref"])
4747
setattr(widget, prop, obj)
48-
elif 'destroy_widget' in content.keys():
49-
self._component_instances = [w for w in self._component_instances
50-
if w.model_id != content['destroy_widget']]
51-
elif 'event' in content.keys():
48+
elif "destroy_widget" in content.keys():
49+
self._component_instances = [
50+
w
51+
for w in self._component_instances
52+
if w.model_id != content["destroy_widget"]
53+
]
54+
elif "event" in content.keys():
5255
event = content.get("event", "")
5356
data = content.get("data", {})
5457
if buffers:
55-
getattr(self, 'vue_' + event)(data, buffers)
58+
getattr(self, "vue_" + event)(data, buffers)
5659
else:
57-
getattr(self, 'vue_' + event)(data)
60+
getattr(self, "vue_" + event)(data)
5861

5962

6063
def _value_to_json(x, obj):
6164
if inspect.isclass(x):
62-
return {
63-
'class': [x.__module__, x.__name__],
64-
'props': x.class_trait_names()
65-
}
66-
return widget_serialization['to_json'](x, obj)
65+
return {"class": [x.__module__, x.__name__], "props": x.class_trait_names()}
66+
return widget_serialization["to_json"](x, obj)
6767

6868

6969
def _class_to_json(x, obj):
7070
if not x:
71-
return widget_serialization['to_json'](x, obj)
71+
return widget_serialization["to_json"](x, obj)
7272
return {k: _value_to_json(v, obj) for k, v in x.items()}
7373

7474

7575
def as_refs(name, data):
7676
def to_ref_structure(obj, path):
7777
if isinstance(obj, list):
78-
return [to_ref_structure(item, [*path, index]) for index, item in enumerate(obj)]
78+
return [
79+
to_ref_structure(item, [*path, index]) for index, item in enumerate(obj)
80+
]
7981
if isinstance(obj, dict):
8082
return {k: to_ref_structure(v, [*path, k]) for k, v in obj.items()}
8183

8284
# add object id to detect a new object in the same structure
83-
return {OBJECT_REF: name, 'path': path, 'id': id(obj)}
85+
return {OBJECT_REF: name, "path": path, "id": id(obj)}
8486

8587
return to_ref_structure(data, [])
8688

8789

8890
class VueTemplate(DOMWidget, Events):
8991

9092
class_component_serialization = {
91-
'from_json': widget_serialization['to_json'],
92-
'to_json': _class_to_json
93+
"from_json": widget_serialization["to_json"],
94+
"to_json": _class_to_json,
9395
}
9496

95-
# Force the loading of jupyter-vue before dependent extensions when in a static context (embed,
96-
# voila)
97-
_jupyter_vue = Any(force_load_instance, read_only=True).tag(sync=True, **widget_serialization)
97+
# Force the loading of jupyter-vue before dependent extensions when in a static
98+
# context (embed, voila)
99+
_jupyter_vue = Any(force_load_instance, read_only=True).tag(
100+
sync=True, **widget_serialization
101+
)
98102

99-
_model_name = Unicode('VueTemplateModel').tag(sync=True)
103+
_model_name = Unicode("VueTemplateModel").tag(sync=True)
100104

101-
_view_name = Unicode('VueView').tag(sync=True)
105+
_view_name = Unicode("VueView").tag(sync=True)
102106

103-
_view_module = Unicode('jupyter-vue').tag(sync=True)
107+
_view_module = Unicode("jupyter-vue").tag(sync=True)
104108

105-
_model_module = Unicode('jupyter-vue').tag(sync=True)
109+
_model_module = Unicode("jupyter-vue").tag(sync=True)
106110

107111
_view_module_version = Unicode(semver).tag(sync=True)
108112

109113
_model_module_version = Unicode(semver).tag(sync=True)
110114

111-
template = Union([
112-
Instance(Template),
113-
Unicode()]).tag(sync=True, **widget_serialization)
115+
template = Union([Instance(Template), Unicode()]).tag(
116+
sync=True, **widget_serialization
117+
)
114118

115119
css = Unicode(None, allow_none=True).tag(sync=True)
116120

@@ -121,15 +125,16 @@ class VueTemplate(DOMWidget, Events):
121125
events = List(Unicode(), allow_none=True).tag(sync=True)
122126

123127
components = Dict(default_value=None, allow_none=True).tag(
124-
sync=True, **class_component_serialization)
128+
sync=True, **class_component_serialization
129+
)
125130

126131
_component_instances = List().tag(sync=True, **widget_serialization)
127132

128133
template_file = None
129134

130135
def __init__(self, *args, **kwargs):
131136
if self.template_file:
132-
abs_path = ''
137+
abs_path = ""
133138
if type(self.template_file) == str:
134139
abs_path = os.path.abspath(self.template_file)
135140
elif type(self.template_file) == tuple:
@@ -140,21 +145,24 @@ def __init__(self, *args, **kwargs):
140145

141146
super().__init__(*args, **kwargs)
142147

143-
sync_ref_traitlets = [v for k, v in self.traits().items()
144-
if 'sync_ref' in v.metadata.keys()]
148+
sync_ref_traitlets = [
149+
v for k, v in self.traits().items() if "sync_ref" in v.metadata.keys()
150+
]
145151

146152
def create_ref_and_observe(traitlet):
147153
data = traitlet.get(self)
148-
ref_name = traitlet.name + '_ref'
149-
self.add_traits(**{ref_name: Any(as_refs(traitlet.name, data)).tag(sync=True)})
154+
ref_name = traitlet.name + "_ref"
155+
self.add_traits(
156+
**{ref_name: Any(as_refs(traitlet.name, data)).tag(sync=True)}
157+
)
150158

151159
def on_ref_source_change(change):
152-
setattr(self, ref_name, as_refs(traitlet.name, change['new']))
160+
setattr(self, ref_name, as_refs(traitlet.name, change["new"]))
153161

154162
self.observe(on_ref_source_change, traitlet.name)
155163

156164
for traitlet in sync_ref_traitlets:
157165
create_ref_and_observe(traitlet)
158166

159167

160-
__all__ = ['VueTemplate']
168+
__all__ = ["VueTemplate"]

0 commit comments

Comments
 (0)