Skip to content

Commit b128a1e

Browse files
committed
Code formatting.
1 parent 8deda5f commit b128a1e

File tree

3 files changed

+75
-40
lines changed

3 files changed

+75
-40
lines changed

pyjviz/__init__.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
from .fstriplestore import set_triple_store__, FSTripleOutputOneShot
2-
from .wb_stack import get_wb_stack
3-
from .wb_stack_entries import *
4-
from .obj_utils import *
5-
from .viz import *
6-
from .rdf_node import arrow
2+
import os
3+
import sys
74

85
from .pf_pandas import enable_pf_pandas__
96

10-
pyjviz_enabled = not ('PYJVIZ_DISABLED' in os.environ and os.environ.get('PYJVIZ_DISABLED').lower() in ['1', 'true','yes'])
7+
pyjviz_enabled = not (
8+
"PYJVIZ_DISABLED" in os.environ
9+
and os.environ.get("PYJVIZ_DISABLED").lower() in ["1", "true", "yes"]
10+
)
1111

1212
if pyjviz_enabled:
13-
if os.path.basename(sys.argv[0]) == 'ipykernel_launcher.py':
14-
tstr = FSTripleOutputOneShot(None, None) # -- NB: how can we detect that this is notebook run
15-
else:
16-
pyjviz_output_dir = os.environ.get('PYJVIZ_OUTPUT_DIR') if 'PYJVIZ_OUTPUT_DIR' in os.environ else "~/.pyjviz"
13+
if os.path.basename(sys.argv[0]) == "ipykernel_launcher.py":
14+
tstr = FSTripleOutputOneShot(
15+
None, None
16+
) # -- NB: how can we detect that this is notebook run
17+
else:
18+
pyjviz_output_dir = (
19+
os.environ.get("PYJVIZ_OUTPUT_DIR")
20+
if "PYJVIZ_OUTPUT_DIR" in os.environ
21+
else "~/.pyjviz"
22+
)
1723
pyjviz_output_dir = os.path.expanduser(pyjviz_output_dir)
18-
tstr = FSTripleOutputOneShot(pyjviz_output_dir,
19-
os.path.basename(sys.argv[0]) + ".ttl")
24+
tstr = FSTripleOutputOneShot(
25+
pyjviz_output_dir, os.path.basename(sys.argv[0]) + ".ttl"
26+
)
2027

2128
set_triple_store__(tstr)
2229
enable_pf_pandas__()
23-

pyjviz/fstriplestore.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
#import ipdb
2-
import os, os.path, textwrap
3-
import tempfile
1+
# import ipdb
2+
import os
3+
import os.path
4+
import textwrap
45
import io
56
import rdflib
67

7-
base_uri = 'https://github.com/pyjanitor-devs/pyjviz/rdflog.shacl.ttl#'
8+
base_uri = "https://github.com/pyjanitor-devs/pyjviz/rdflog.shacl.ttl#"
9+
810

911
class FSTripleOutput:
1012
def __init__(self, out_fd):
1113
global base_uri
1214
self.base_uri = base_uri
1315
self.out_fd = out_fd
14-
16+
1517
def dump_prefixes__(self):
16-
print(f"@base <{self.base_uri}> .", file = self.out_fd)
17-
print("@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .", file = self.out_fd)
18-
print("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .", file = self.out_fd)
18+
print(f"@base <{self.base_uri}> .", file=self.out_fd)
19+
print(
20+
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .",
21+
file=self.out_fd,
22+
)
23+
print(
24+
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .",
25+
file=self.out_fd,
26+
)
1927

20-
print(textwrap.dedent("""
28+
print(
29+
textwrap.dedent(
30+
"""
2131
<WithBlock> rdf:type rdfs:Class .
2232
<CodeBlock> rdf:type rdfs:Class .
2333
<CodeBlock> rdfs:subClassOf <WithBlock> .
@@ -35,14 +45,18 @@ def dump_prefixes__(self):
3545
<CCGlance> rdfs:subClassOf <CC> .
3646
<CCBasicPlot> rdf:type rdfs:Class .
3747
<CCBasicPlot> rdfs:subClassOf <CC> .
38-
"""), file = self.out_fd)
39-
48+
"""
49+
),
50+
file=self.out_fd,
51+
)
52+
4053
def dump_triple(self, subj, pred, obj):
41-
print(f"{subj} {pred} {obj} .", file = self.out_fd)
54+
print(f"{subj} {pred} {obj} .", file=self.out_fd)
4255

4356
def flush(self):
4457
self.out_fd.flush()
4558

59+
4660
class FSTripleOutputOneShot(FSTripleOutput):
4761
def __init__(self, output_dir, output_filename):
4862
self.output_dir = output_dir
@@ -51,7 +65,7 @@ def __init__(self, output_dir, output_filename):
5165
if self.output_dir is None:
5266
out_fd = io.StringIO()
5367
else:
54-
#ipdb.set_trace()
68+
# ipdb.set_trace()
5569
self.output_dir = os.path.expanduser(self.output_dir)
5670
if not os.path.exists(self.output_dir):
5771
os.makedirs(self.output_dir)
@@ -63,19 +77,23 @@ def __init__(self, output_dir, output_filename):
6377

6478
super().__init__(out_fd)
6579
self.dump_prefixes__()
66-
80+
6781
def get_graph(self):
6882
g = rdflib.Graph()
6983
self.out_fd.seek(0)
7084
g.parse(self.out_fd)
7185
return g
7286

87+
7388
class FSTripleOutputNull:
74-
def dump_triple(self, s, p, o): pass
75-
89+
def dump_triple(self, s, p, o):
90+
pass
91+
92+
7693
triple_store = None
94+
95+
7796
def set_triple_store__(o):
7897
print("setting up triple_store:", o)
7998
global triple_store
8099
triple_store = o
81-

pyjviz/wb_stack.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
from . import fstriplestore
22
from . import rdf_node
33

4+
45
class WithBlock(rdf_node.RDFNode):
56
"""
67
Code blocks in python - https://docs.python.org/3/reference/executionmodel.html#:~:text=A%20Python%20program%20is%20constructed,typed%20interactively%20is%20a%20block.
78
With PEP use of 'block' - https://peps.python.org/pep-0343/#specification-the-with-statement
89
910
Base class for CodeBlock, MethodCall and NestedCall.
1011
- uri - to identify itself in graph as node
11-
- rdf_type_uri - to identify node type
12-
"""
12+
- rdf_type_uri- to identify node type
13+
""" # noqa: E501
14+
1315
def __init__(self, *, rdf_type, label):
1416
super().__init__(rdf_type, label)
1517
rdfl = fstriplestore.triple_store
1618
global wb_stack
17-
parent_uri = wb_stack.stack_entries__[-1].uri if wb_stack.size() > 0 else "rdf:nil"
19+
parent_uri = (
20+
wb_stack.stack_entries__[-1].uri
21+
if wb_stack.size() > 0
22+
else "rdf:nil"
23+
)
1824
rdfl.dump_triple(self.uri, "<part-of>", parent_uri)
19-
25+
2026
def __enter__(self):
2127
global wb_stack
2228
wb_stack.push(self)
@@ -26,20 +32,23 @@ def __exit__(self, type, value, traceback):
2632
fstriplestore.triple_store.flush()
2733
global wb_stack
2834
wb_stack.pop()
29-
35+
36+
3037
class WithBlockStack:
3138
def __init__(self):
3239
self.stack_entries__ = []
3340

3441
def to_string(self):
35-
return ":".join([f"{x.label}@{x.rdf_type}" for x in self.stack_entries__])
36-
42+
return ":".join(
43+
[f"{x.label}@{x.rdf_type}" for x in self.stack_entries__]
44+
)
45+
3746
def size(self):
3847
return len(self.stack_entries__)
3948

4049
def push(self, e):
4150
self.stack_entries__.append(e)
42-
51+
4352
def pop(self):
4453
return self.stack_entries__.pop()
4554

@@ -61,9 +70,11 @@ def get_latest_method_call(self):
6170
def get_parent_of_current_entry(self):
6271
ret = self.stack_entries__[-1] if self.size() > 0 else None
6372
return ret
64-
65-
73+
74+
6675
wb_stack = WithBlockStack()
76+
77+
6778
def get_wb_stack():
6879
global wb_stack
6980
return wb_stack

0 commit comments

Comments
 (0)