Skip to content

Commit a03c3c2

Browse files
committed
changes to reduce num of flake8 warning
1 parent 655debd commit a03c3c2

18 files changed

+212
-168
lines changed

pyjviz/code_block.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import code_block_rdf
22
from . import wb_stack
33

4+
45
class CodeBlock(wb_stack.WithBlock):
56
"""
67
CodeBlock (also has name alias CB) is diagram object representing code block defined via *with* statement.
@@ -9,14 +10,16 @@ class CodeBlock(wb_stack.WithBlock):
910
.. python code is here ..
1011
1112
```
12-
"""
13-
def __init__(self, label = None):
13+
""" # noqa : 501
14+
15+
def __init__(self, label=None):
1416
super().__init__(label)
1517
self.back = code_block_rdf.CodeBlockRDF(self)
1618

1719
self.back.dump_rdf()
1820

1921
def on_exit__(self):
2022
self.back.flush_triples()
21-
23+
24+
2225
CB = CodeBlock

pyjviz/code_block_rdf.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
from . import fstriplestore
22
from . import rdf_utils
33

4+
45
class CodeBlockRDF(rdf_utils.RDFRep):
56
def __init__(self, code_block):
6-
self.set_rdf_rep(rdf_type = "CodeBlock")
7+
self.set_rdf_rep(rdf_type="CodeBlock")
78
self.front = code_block
8-
9+
910
def dump_rdf(self):
1011
ts = fstriplestore.triple_store
1112
ts.dump_triple(self.uri, "rdf:type", self.rdf_type_uri)
12-
ts.dump_triple(self.uri, "rdf:label", f'"{self.front.label}"' if self.front.label else "rdf:nil")
13-
parent_uri = self.front.parent_stack_entry.back.uri if self.front.parent_stack_entry else "rdf:nil"
13+
if self.front.label:
14+
l_uri = f'"{self.front.label}"'
15+
else:
16+
l_uri = "rdf:nil"
17+
18+
if self.front.parent_stack_entry:
19+
parent_uri = self.front.parent_stack_entry.back.uri
20+
else:
21+
parent_uri = "rdf:nil"
22+
23+
ts.dump_triple(self.uri, "rdf:label", l_uri)
1424
ts.dump_triple(self.uri, "<part-of>", parent_uri)
1525

1626
def flush_triples(self):

pyjviz/dia_objs.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,36 @@ class TextRDF {
2727
+ dump_rdf()
2828
}
2929
```
30-
31-
32-
"""
30+
""" # noqa : 501
3331
from . import wb_stack
3432
from .dia_objs_rdf import TextRDF
3533

34+
3635
class DiagramObj:
3736
"""
3837
base class of python objects which will have visible diagram representation.
3938
The diagram object has corresponding <b>back</b> object which class belongs to RDFRep.
4039
E.g. Text class will have back ref to TextRDF class object.
41-
"""
40+
""" # noqa : 501
41+
4242
def __init__(self):
4343
self.back = None
4444

45+
4546
class Text(DiagramObj):
4647
"""
4748
Text class is to represent text box primitive for pyjviz diagram.
4849
"""
49-
def __init__(self, title, text, parent_obj = None):
50-
if parent_obj:
51-
if not isinstance(parent_obj, DiagramObj):
52-
raise Exception(f"parent_obj must be instance of subclass of DiagramObj, {type(parent_obj)}")
53-
else:
50+
def __init__(self, title, text, parent_obj=None):
51+
if not parent_obj:
5452
parent_obj = wb_stack.wb_stack.get_top()
5553

56-
self.back = TextRDF(self)
54+
if not isinstance(parent_obj, DiagramObj):
55+
msg = \
56+
f"parent_obj is not subclass of DiagramObj, {type(parent_obj)}"
57+
raise Exception(msg)
5758

59+
self.back = TextRDF(self)
5860
self.parent_obj = parent_obj
5961
self.title = title
6062
self.text = text

pyjviz/dia_objs_rdf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
class TextRDF(rdf_utils.RDFRep):
99
def __init__(self, text_obj: dia_objs.Text):
10-
self.set_rdf_rep(rdf_type = "Text")
10+
self.set_rdf_rep(rdf_type="Text")
1111
self.front = text_obj
1212

1313
def dump_rdf(self):
14-
ts = fstriplestore.triple_store
14+
ts = fstriplestore.triple_store
1515
ts.dump_triple(self.uri, "rdf:type", self.rdf_type_uri)
1616
parent_obj = self.front.parent_obj
1717
parent_uri = parent_obj.back.uri if parent_obj else "rdf:nil"
1818
ts.dump_triple(self.uri, "<part-of>", parent_uri)
1919
ts.dump_triple(self.uri, "<title>", '"' + self.front.title + '"')
20-
ts.dump_triple(self.uri, "<text>", '"' + fstriplestore.to_base64(self.front.text) + '"')
21-
20+
text_b64 = '"' + fstriplestore.to_base64(self.front.text) + '"'
21+
ts.dump_triple(self.uri, "<text>", text_b64)

pyjviz/fstriplestore.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import os
22
import os.path
33
import textwrap
4-
import io, base64
4+
import io
5+
import base64
56
import rdflib
67

78
base_uri = "https://github.com/pyjanitor-devs/pyjviz/rdflog.shacl.ttl#"
89

10+
911
def to_base64(s):
1012
return base64.b64encode(s.encode('ascii')).decode('ascii')
1113

14+
1215
def from_base64(s):
1316
return base64.b64decode(s).decode('ascii')
1417

18+
1519
class FSTripleOutput:
1620
def __init__(self, out_fd):
1721
global base_uri
@@ -45,8 +49,10 @@ def dump_prefixes__(self):
4549
4650
<CC> rdf:type rdfs:Class .
4751
<CCObjStateLabel> rdf:type rdfs:Class .
48-
<CCObjStateLabelDataFrame> rdf:type rdfs:Class; rdfs:subClassOf <CCObjStateLabel> .
49-
<CCObjStateLabelSeries> rdf:type rdfs:Class; rdfs:subClassOf <CCObjStateLabel> .
52+
<CCObjStateLabelDataFrame> rdf:type rdfs:Class .
53+
<CCObjStateLabelDataFrame> rdfs:subClassOf <CCObjStateLabel> .
54+
<CCObjStateLabelSeries> rdf:type rdfs:Class .
55+
<CCObjStateLabelSeries> rdfs:subClassOf <CCObjStateLabel> .
5056
<CCGlance> rdf:type rdfs:class; rdfs:subClassOf <CC> .
5157
<CCBasicPlot> rdf:type rdfs:Class; rdfs:subClassOf <CC> .
5258
"""
@@ -98,6 +104,5 @@ def dump_triple(self, s, p, o):
98104

99105

100106
def set_triple_store__(o):
101-
#print("setting up triple_store:", o)
102107
global triple_store
103108
triple_store = o

pyjviz/method_call.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import ipdb
21
import threading
32
import pandas as pd
43
import inspect
54

65
from . import wb_stack
7-
from . import fstriplestore
86
from . import obj_tracking
97
from . import obj_utils
8+
from . import method_call_rdf
9+
from . import rdf_io
1010

1111
from .nested_call import NestedCall
1212

13-
from . import method_call_rdf
13+
# NB: should be better way to count method calls
14+
method_counter = 0
1415

15-
from . import rdf_io
1616

17-
method_counter = 0 # NB: should be better way to count method calls
1817
class MethodCall(wb_stack.WithBlock):
1918
def __init__(self, method_name):
2019
super().__init__(method_name)
@@ -23,27 +22,29 @@ def __init__(self, method_name):
2322
self.method_bound_args = None
2423

2524
self.args_l = None
26-
25+
2726
def add_args_l_entry__(self, arg_name, arg_obj):
28-
if arg_name is None: arg_name = f"arg_{len(self.args_l)}"
29-
27+
if arg_name is None:
28+
arg_name = f"arg_{len(self.args_l)}"
29+
3030
if type(arg_obj).__name__ == "NestedCall":
3131
self.args_l.append((arg_name, arg_obj))
32-
elif isinstance(arg_obj, pd.DataFrame) or isinstance(arg_obj, pd.Series):
32+
elif isinstance(arg_obj, pd.DataFrame) \
33+
or isinstance(arg_obj, pd.Series):
3334
arg_obj_id, found = obj_tracking.get_tracking_obj(arg_obj)
34-
#print("arg id:", id(arg_obj), found)
35+
3536
if found:
3637
arg_obj_state = arg_obj_id.last_obj_state
3738
else:
3839
arg_obj_state = obj_utils.ObjState(arg_obj, arg_obj_id)
39-
40+
4041
self.args_l.append((arg_name, arg_obj_state))
4142
else:
4243
self.args_l.append((arg_name, arg_obj))
43-
44+
4445
def build_args_l__(self):
4546
self.args_l = []
46-
for arg_name, arg_obj in self.method_bound_args.arguments.items():
47+
for arg_name, arg_obj in self.method_bound_args.arguments.items():
4748
arg_kind = self.method_signature.parameters.get(arg_name).kind
4849
if arg_kind == inspect.Parameter.VAR_KEYWORD:
4950
for kwarg_name, kwarg_obj in arg_obj.items():
@@ -54,7 +55,7 @@ def build_args_l__(self):
5455
self.add_args_l_entry__(None, p_arg_obj)
5556
else:
5657
self.add_args_l_entry__(arg_name, arg_obj)
57-
58+
5859
def handle_start_method_call(self, method_name, method_signature, method_args, method_kwargs):
5960
if method_name == "pin":
6061
arg0_obj = method_args[0]
@@ -64,47 +65,54 @@ def handle_start_method_call(self, method_name, method_signature, method_args, m
6465
else:
6566
raise Exception("logical error: expected to have obj state created before")
6667
return method_args, method_kwargs
67-
68+
6869
self.thread_id = threading.get_native_id()
6970

7071
all_args = method_args
7172
self.method_signature = method_signature
7273
self.method_bound_args = self.method_signature.bind(*all_args, **method_kwargs)
7374
args_w_specified_values = self.method_bound_args.arguments.keys()
7475
# NB:
75-
# according to python doc default values are evaluated and saved only once when function is defined
76-
# apply_defaults method is to be used to put default values to method_bound_args.arguments
77-
# decision to call or not to call apply_defaults could affect program execution since we could modify arguments
78-
# of real method call which will happen after this method returns new args and kwargs.
76+
# according to python doc default values are evaluated and saved only
77+
# once when function is defined. apply_defaults method is to be used to
78+
# put default values to `method_bound_args.arguments`. decision to call
79+
# or not to call apply_defaults could affect program execution since we
80+
# could modify arguments of real method call which will happen after this
81+
# method returns new args and kwargs.
7982
# E.g. loop over all arguments will be affected
80-
# since apply_defaults will add new entries which were skipped by method_signature.bind since they are omit and use default values
83+
# since apply_defaults will add new entries which were skipped by
84+
# method_signature.bind since they are omit and use default values
8185
# --- >>>> commented out ---> self.method_bound_args.apply_defaults()
8286

8387
# NB:
84-
# loop over args_w_specified_values will skip the args where func value should be supplied and default func value is used.
85-
# purpose of the loop is to replace such func arg values with equivalent obj of class NestedCall which suppose to collect
86-
# call tracking information for visualization. so no such information will be collected for fund args where default value is used
88+
# loop over args_w_specified_values will skip the args where func value
89+
# should be supplied and default func value is used.
90+
# purpose of the loop is to replace such func arg values with
91+
# equivalent obj of class NestedCall which suppose to collect call
92+
# tracking information for visualization. so no such information will
93+
# be collected for fund args where default value is used
8794
for arg_name in args_w_specified_values:
8895
arg_value = self.method_bound_args.arguments.get(arg_name)
8996
arg_kind = method_signature.parameters.get(arg_name).kind
9097

91-
#print(method_name, arg_name, arg_kind)
9298
if arg_kind == inspect.Parameter.VAR_KEYWORD:
9399
# case for lambda args of assign
94100
updates_d = {}
95101
for kwarg_name, kwarg_value in arg_value.items():
96102
if inspect.isfunction(kwarg_value):
97-
# create empty nested call obj as placeholder for future results
103+
# create empty nested call obj
104+
# as placeholder for future results
98105
new_kwarg_value = NestedCall(kwarg_name, kwarg_value)
99106
updates_d[kwarg_name] = new_kwarg_value
100107
self.method_bound_args.arguments[arg_name].update(updates_d)
101108

102109
self.build_args_l__()
103-
110+
104111
new_args = self.method_bound_args.args
105112
new_kwargs = self.method_bound_args.kwargs
106-
107-
# NB: since apply_defaults is not called then no tracking of args with default values will take place
113+
114+
# NB: since apply_defaults is not called then no tracking of args
115+
# with default values will take place
108116
self.back.dump_rdf_method_call_in()
109117

110118
return new_args, new_kwargs
@@ -114,14 +122,16 @@ def handle_end_method_call(self, ret):
114122
return
115123

116124
if ret is None:
117-
raise Exception(f"method call of {self.method_name} returned None, can't use it chained method calls")
118-
125+
msg = f"method call of {self.method_name} returned None,"
126+
" can't use it chained method calls"
127+
raise Exception(msg)
128+
119129
ret_obj_id, found = obj_tracking.get_tracking_obj(ret)
120130
if found:
121131
ret_obj_id.last_version_num += 1
122132

123133
# since we don't know was object state changed or not
124134
# we create new object state and set it as last obj state in obj id
125135
self.ret_obj_state = obj_utils.ObjState(ret, ret_obj_id)
126-
136+
127137
self.back.dump_rdf_method_call_out()

0 commit comments

Comments
 (0)