Skip to content

Commit 7872d77

Browse files
committed
flake
1 parent 6a7c6b3 commit 7872d77

9 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/semsql/builder/builder.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def db_from_owl(input: str) -> str:
7676
make(db)
7777
return db
7878
else:
79-
raise ValueError(f"Path must be an OWL file")
79+
raise ValueError("Path must be an OWL file")
8080

8181

8282
def download_obo_sqlite(ontology: str, destination: str):
@@ -108,8 +108,7 @@ def connect(owl_file: str):
108108
"""
109109
db = db_from_owl(owl_file)
110110
engine = create_engine(f"sqlite:///{db}")
111-
Session = sessionmaker(bind=engine)
112-
session = Session()
111+
session = sessionmaker(bind=engine)()
113112
return session
114113

115114

@@ -133,16 +132,18 @@ def compile_registry(registry_path: str, local_prefix_file: TextIO = None) -> st
133132
if ont == generic:
134133
command = "curl -L -s http://purl.obolibrary.org/obo/$*.owl > $@.tmp"
135134
elif ont.zip_extract_file:
136-
command = f"curl -L -s {ont.url} > $@.zip.tmp && unzip -p $@.zip.tmp {ont.zip_extract_file} > $@.tmp && rm $@.zip.tmp"
135+
command = (f"curl -L -s {ont.url} > $@.zip.tmp && "
136+
"unzip -p $@.zip.tmp {ont.zip_extract_file} "
137+
"> $@.tmp && rm $@.zip.tmp")
137138
else:
138139
command = f"curl -L -s {ont.url} > $@.tmp"
139140
download_rule = MakefileRule(
140141
target=f"download/{ont.id}.owl",
141142
dependencies=["STAMP"],
142143
commands=[
143144
command,
144-
f"sha256sum -b $@.tmp > $@.sha256",
145-
f"mv $@.tmp $@",
145+
"sha256sum -b $@.tmp > $@.sha256",
146+
"mv $@.tmp $@",
146147
],
147148
precious=True,
148149
)
@@ -151,11 +152,11 @@ def compile_registry(registry_path: str, local_prefix_file: TextIO = None) -> st
151152
target = f"db/{ont.id}.owl"
152153
dependencies = [f"download/{ont.id}.owl"]
153154
if ont.has_imports or (ont.format and ont.format != "rdfxml"):
154-
command = f"robot merge -i $< -o $@"
155+
command = "robot merge -i $< -o $@"
155156
elif ont.build_command:
156157
command = ont.build_command.format(ont=ont)
157158
else:
158-
command = f"cp $< $@"
159+
command = "cp $< $@"
159160
rule = MakefileRule(
160161
target=target, dependencies=dependencies, commands=[command]
161162
)

src/semsql/ontlib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from semsql.ontlib.subgraph import extract_subgraph
2+
3+
__all__ = ["extract_subgraph"]

src/semsql/ontlib/subgraph.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def to_obo_format(g: OboGraphDict) -> None:
164164
for n in g["nodes"]:
165165
id = n["id"]
166166
print()
167-
print(f"[Term]")
167+
print("[Term]")
168168
print(f"id: {id}")
169169
print(f'name: {n["lbl"]}')
170170
if "meta" in n:
@@ -189,14 +189,16 @@ def to_obo_format(g: OboGraphDict) -> None:
189189
print(f"relationship: {p} {o}{cmt}")
190190

191191

192-
def to_markdown(g: OboGraphDict, prefixes: PREFIX_MAP = {}, definitions=True) -> None:
192+
def to_markdown(g: OboGraphDict, prefixes: PREFIX_MAP = None, definitions=True) -> None:
193193
"""
194194
Serialization to markdown
195195
196196
This should probably move elsewhere
197197
:param g:
198198
:return:
199199
"""
200+
if prefixes is None:
201+
prefixes = {}
200202
eix = graph_to_subject_index(g)
201203
nix = {n["id"]: n for n in g["nodes"]}
202204
for n in g["nodes"]:
@@ -225,7 +227,7 @@ def to_markdown(g: OboGraphDict, prefixes: PREFIX_MAP = {}, definitions=True) ->
225227
print(f" * {plink} {olink} {cmt}")
226228

227229

228-
def _id_to_markdown_link(id: str, prefixes={}):
230+
def _id_to_markdown_link(id: str, prefixes=None):
229231
pfx, localid = id.split(":")
230232
if pfx in prefixes:
231233
url = f"{prefixes[pfx]}{localid}"
@@ -238,7 +240,7 @@ def render_edges(
238240
session,
239241
edges: List[Row],
240242
to_format: str = "text",
241-
seeds: List[CURIE] = [],
243+
seeds: List[CURIE] = None,
242244
stylemap: str = None,
243245
configure: str = None,
244246
):
@@ -251,6 +253,8 @@ def render_edges(
251253
:param stylemap: used for graphviz rendering
252254
:return:
253255
"""
256+
if seeds is None:
257+
seeds = []
254258
prefixes = get_prefixes(session)
255259
if to_format == "obojson":
256260
g = edges_to_obograph(session, edges, definitions=True)

tests/test_builder/test_builder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import os
22
import unittest
33

4-
from click.testing import CliRunner
5-
64
from semsql.builder import builder
7-
from semsql.builder.cli import main
85
from semsql.builder.registry import path_to_ontology_registry
96

107
cwd = os.path.abspath(os.path.dirname(__file__))

tests/test_ontlib/test_common_queries.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class CommonQueriesTestCase(unittest.TestCase):
2020
def setUp(self):
2121
path = os.path.join(DB_DIR, "go-nucleus.db")
2222
engine = create_engine(f"sqlite:///{path}")
23-
Session = sessionmaker(bind=engine)
24-
self.session = Session()
23+
self.session = sessionmaker(bind=engine)()
2524

2625
def test_common_queries(self):
2726

tests/test_ontlib/test_subgraph.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ class SubgraphTestCase(unittest.TestCase):
2323
def test_subgraph(self):
2424
path = os.path.join(DB_DIR, "go-nucleus.db")
2525
engine = create_engine(f"sqlite:///{path}")
26-
Session = sessionmaker(bind=engine)
27-
session = Session()
26+
session = sessionmaker(bind=engine)()
2827
edges = extract_subgraph(
2928
session, terms=["CL:0000000"], view=SubgraphEdgeByAncestor
3029
)
3130
lines = []
32-
print(f'graph for descendants of "cell"')
31+
print('graph for descendants of "cell"')
3332
for e in edges:
3433
line = f"{e.subject} {e.predicate} {e.object}"
3534
print(line)
3635
lines.append(line)
3736
assert "GO:0031967 BFO:0000050 GO:0043229" in lines
3837
assert "GO:0031975 rdfs:subClassOf GO:0110165" in lines
3938

40-
print(f'graph for ancestors of "nuclear membrane"')
39+
print('graph for ancestors of "nuclear membrane"')
4140
edges = extract_subgraph(
4241
session, terms=["GO:0031965"], view=SubgraphEdgeByDescendant
4342
)

tests/test_orm/test_basic_sqla.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class SQLAlchemyTestCase(unittest.TestCase):
1717
def setUp(self) -> None:
1818
path = os.path.join(DB_DIR, "go-nucleus.db")
1919
engine = create_engine(f"sqlite:///{path}")
20-
SessionClass = sessionmaker(bind=engine)
21-
self.session = SessionClass()
20+
self.session = sessionmaker(bind=engine)()
2221

2322
def test_basic_sqla(self):
2423
"""
@@ -87,8 +86,9 @@ def add_label(q, join_slot):
8786
q = add_label(q, RdfsSubclassOfStatement.subject)
8887
q = add_label(q, OwlSomeValuesFrom.filler)
8988
null = "NONE"
90-
for ax, ex, sl, fl in q.all():
91-
line = f'{ax.subject} "{sl.value if sl else null}" subClassOf {ex.on_property} SOME {ex.filler} "{fl.value if fl else null}"'
89+
for ax, _ex, sl, _fl in q.all():
90+
line = f'{ax.subject} "{sl.value if sl else null}"'
91+
' subClassOf {ex.on_property} SOME {ex.filler} "{fl.value if fl else null}"'
9292
logging.info(line)
9393
# print(line)
9494
lines.append(line)

tests/test_orm/test_crud.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def test_crud(self):
2323
"""
2424
copyfile(SRC_DB, TEST_DB)
2525
engine = create_engine(f"sqlite:///{TEST_DB}")
26-
Session = sessionmaker(bind=engine)
27-
session = Session()
26+
session = sessionmaker(bind=engine)()
2827
q = (
2928
session.query(Statements)
3029
.filter(Statements.predicate == "rdfs:label")

tests/test_orm/test_problems.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def test_problems(self):
1818
"""
1919
path = os.path.join(DB_DIR, "go-nucleus.db")
2020
engine = create_engine(f"sqlite:///{path}")
21-
Session = sessionmaker(bind=engine)
22-
session = Session()
21+
session = sessionmaker(bind=engine)()
2322
print("OWL query:")
2423
q = session.query(AllProblems)
2524
n = 0

0 commit comments

Comments
 (0)