Skip to content

Commit 562158f

Browse files
authored
Merge pull request #57 from casework/add_flake8_and_isort_to_precommit
Add flake8 and isort to precommit
2 parents 6b90af7 + bee99f8 commit 562158f

File tree

18 files changed

+69
-47
lines changed

18 files changed

+69
-47
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
repos:
2-
- repo: https://github.com/psf/black
2+
- repo: https://github.com/psf/black
33
rev: 22.3.0
44
hooks:
5-
- id: black
5+
- id: black
6+
- repo: https://github.com/pycqa/flake8
7+
rev: 4.0.1
8+
hooks:
9+
- id: flake8
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.10.1
12+
hooks:
13+
- id: isort
14+
name: isort (python)

case_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
__version__ = "0.5.0"
1515

16-
from . import local_uuid
16+
from . import local_uuid # noqa: F401

case_utils/case_file/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
import rdflib # type: ignore
2929

3030
import case_utils
31-
from case_utils.namespace import *
31+
from case_utils.namespace import (
32+
NS_RDF,
33+
NS_UCO_CORE,
34+
NS_UCO_OBSERVABLE,
35+
NS_UCO_TYPES,
36+
NS_UCO_VOCABULARY,
37+
NS_XSD,
38+
)
3239

3340
DEFAULT_PREFIX = "http://example.org/kb/"
3441

@@ -147,7 +154,7 @@ def create_file_node(
147154
sha1obj.update(buf)
148155
sha256obj.update(buf)
149156
sha512obj.update(buf)
150-
if not stashed_error is None:
157+
if stashed_error is not None:
151158
raise stashed_error
152159
current_hashdict = HashDict(
153160
byte_tally,
@@ -182,7 +189,7 @@ def create_file_node(
182189

183190
# Add confirmed hashes into graph.
184191
for key in successful_hashdict._fields:
185-
if not key in ("md5", "sha1", "sha256", "sha512"):
192+
if key not in ("md5", "sha1", "sha256", "sha512"):
186193
continue
187194
n_hash = rdflib.BNode()
188195
graph.add((n_contentdata_facet, NS_UCO_OBSERVABLE.hash, n_hash))
@@ -247,7 +254,7 @@ def main() -> None:
247254
serialize_kwargs["context"] = context_dictionary
248255

249256
node_iri = NS_BASE["file-" + case_utils.local_uuid.local_uuid()]
250-
n_file = create_file_node(
257+
create_file_node(
251258
graph,
252259
args.in_file,
253260
node_iri=node_iri,

case_utils/case_sparql_construct/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import rdflib.plugins.sparql # type: ignore
2727

2828
import case_utils.ontology
29-
30-
from case_utils.ontology.version_info import *
29+
from case_utils.ontology.version_info import (
30+
CURRENT_CASE_VERSION,
31+
built_version_choices_list,
32+
)
3133

3234
_logger = logging.getLogger(os.path.basename(__file__))
3335

@@ -81,7 +83,7 @@ def main() -> None:
8183
construct_query_text = None
8284
with open(args.in_sparql, "r") as in_fh:
8385
construct_query_text = in_fh.read().strip()
84-
assert not construct_query_text is None
86+
assert construct_query_text is not None
8587

8688
if "subClassOf" in construct_query_text:
8789
case_utils.ontology.load_subclass_hierarchy(

case_utils/case_sparql_select/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import argparse
3232
import binascii
33-
import importlib.resources
3433
import logging
3534
import os
3635
import sys
@@ -39,8 +38,10 @@
3938
import rdflib.plugins.sparql # type: ignore
4039

4140
import case_utils.ontology
42-
43-
from case_utils.ontology.version_info import *
41+
from case_utils.ontology.version_info import (
42+
CURRENT_CASE_VERSION,
43+
built_version_choices_list,
44+
)
4445

4546
NS_XSD = rdflib.XSD
4647

case_utils/case_validate/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@
3535
import importlib.resources
3636
import logging
3737
import os
38-
import pathlib
3938
import sys
4039
import typing
4140

42-
import rdflib.util # type: ignore
4341
import pyshacl # type: ignore
42+
import rdflib.util # type: ignore
4443

4544
import case_utils.ontology
46-
47-
from case_utils.ontology.version_info import *
45+
from case_utils.ontology.version_info import (
46+
CURRENT_CASE_VERSION,
47+
built_version_choices_list,
48+
)
4849

4950
_logger = logging.getLogger(os.path.basename(__file__))
5051

case_utils/local_uuid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import pathlib
2323
import sys
2424
import typing
25-
import warnings
2625
import uuid
26+
import warnings
2727

2828
DEMO_UUID_BASE: typing.Optional[str] = None
2929

case_utils/ontology/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Yes, this next import is self-referential (/circular). But, it does work with importlib.
2323
import case_utils.ontology
2424

25-
from .version_info import *
25+
from .version_info import CURRENT_CASE_VERSION
2626

2727
_logger = logging.getLogger(os.path.basename(__file__))
2828

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ console_scripts =
3737
[options.package_data]
3838
case_utils = py.typed
3939
case_utils.ontology = *.ttl
40+
41+
[flake8]
42+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
43+
extend-ignore =
44+
E203
45+
E302
46+
E501
47+
48+
[isort]
49+
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html
50+
profile = black

tests/case_utils/case_file/test_case_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import rdflib.plugins.sparql # type: ignore
2020

2121
import case_utils.ontology
22-
from case_utils.namespace import *
22+
from case_utils.namespace import NS_UCO_CORE, NS_UCO_OBSERVABLE, NS_UCO_TYPES
2323

2424
_logger = logging.getLogger(os.path.basename(__file__))
2525

@@ -117,12 +117,12 @@ def test_confirm_mtime(
117117
for result in graph_case_file_disable_hashes.query(query_object):
118118
(n_observable_object,) = result
119119
assert (
120-
not n_observable_object is None
120+
n_observable_object is not None
121121
), "File object with expected mtime not found in hashless graph."
122122

123123
n_observable_object = None
124124
for result in graph_case_file.query(query_object):
125125
(n_observable_object,) = result
126126
assert (
127-
not n_observable_object is None
127+
n_observable_object is not None
128128
), "File object with expected mtime not found in fuller graph."

tests/case_utils/case_sparql_construct/test_case_sparql_construct.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import rdflib.plugins.sparql # type: ignore
1717

18-
import case_utils
19-
2018

2119
def _test_subclass_templates_result(filename: str, expected: typing.Set[str]) -> None:
2220
computed: typing.Set[str] = set()
@@ -38,8 +36,7 @@ def _test_subclass_templates_result(filename: str, expected: typing.Set[str]) ->
3836

3937

4038
def _test_w3_templates_with_blank_nodes_result(filename: str) -> None:
41-
ground_truth_positive = {("Alice", "Hacker"), ("Bob", "Hacker")}
42-
ground_truth_negative: typing.Set[str] = set()
39+
expected = {("Alice", "Hacker"), ("Bob", "Hacker")}
4340

4441
graph = rdflib.Graph()
4542
graph.parse(filename)
@@ -59,7 +56,7 @@ def _test_w3_templates_with_blank_nodes_result(filename: str) -> None:
5956
for result in graph.query(query_string):
6057
(l_given_name, l_family_name) = result
6158
computed.add((l_given_name.toPython(), l_family_name.toPython()))
62-
assert computed == ground_truth_positive
59+
assert expected == computed
6360

6461

6562
def test_w3_templates_with_blank_nodes_result_json() -> None:

tests/case_utils/case_validate/cli/test_format_output_flags.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_format_jsonld_output_jsonld() -> None:
8181
subject_file = "format_jsonld_output_jsonld.jsonld"
8282
asserted_format = _guess_format(subject_file)
8383
assert asserted_format == "json-ld"
84-
graph = _parse_graph(subject_file, asserted_format)
84+
_parse_graph(subject_file, asserted_format)
8585

8686

8787
@pytest.mark.xfail(
@@ -107,7 +107,7 @@ def test_format_jsonld_output_unspecified() -> None:
107107
subject_file = "format_jsonld_output_unspecified.jsonld"
108108
asserted_format = _guess_format(subject_file)
109109
assert asserted_format == "json-ld"
110-
graph = _parse_graph(subject_file, asserted_format)
110+
_parse_graph(subject_file, asserted_format)
111111

112112

113113
@pytest.mark.xfail(
@@ -124,7 +124,7 @@ def test_format_turtle_output_turtle() -> None:
124124
subject_file = "format_turtle_output_turtle.ttl"
125125
asserted_format = _guess_format(subject_file)
126126
assert asserted_format == "turtle"
127-
graph = _parse_graph(subject_file, asserted_format)
127+
_parse_graph(subject_file, asserted_format)
128128

129129

130130
def test_format_turtle_output_txt() -> None:
@@ -138,7 +138,7 @@ def test_format_turtle_output_unspecified() -> None:
138138
subject_file = "format_turtle_output_unspecified.ttl"
139139
asserted_format = _guess_format(subject_file)
140140
assert asserted_format == "turtle"
141-
graph = _parse_graph(subject_file, asserted_format)
141+
_parse_graph(subject_file, asserted_format)
142142

143143

144144
@pytest.mark.xfail(

tests/case_utils/ontology/test_version_info.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import rdflib # type: ignore
1919

2020
import case_utils.ontology
21-
22-
from case_utils.ontology.version_info import *
21+
from case_utils.ontology.version_info import (
22+
CURRENT_CASE_VERSION,
23+
built_version_choices_list,
24+
)
2325

2426
NS_OWL = rdflib.OWL
2527

@@ -30,7 +32,7 @@ def test_built_version_choices_list() -> None:
3032
continue
3133
ttl_filename = built_version_choice + ".ttl"
3234
with importlib.resources.open_text(case_utils.ontology, ttl_filename) as tmp_fh:
33-
pass
35+
assert tmp_fh
3436

3537

3638
def test_case_ontology_version_info_versus_monolithic() -> None:
@@ -49,7 +51,7 @@ def test_case_ontology_version_info_versus_monolithic() -> None:
4951
)
5052
):
5153
version_info = str(triple[2])
52-
assert not version_info is None, "Failed to retrieve owl:versionInfo"
54+
assert version_info is not None, "Failed to retrieve owl:versionInfo"
5355

5456
assert (
5557
CURRENT_CASE_VERSION == version_info
@@ -79,7 +81,7 @@ def test_case_ontology_version_info_versus_submodule() -> None:
7981
)
8082
):
8183
version_info = str(triple[2])
82-
assert not version_info is None, "Failed to retrieve owl:versionInfo"
84+
assert version_info is not None, "Failed to retrieve owl:versionInfo"
8385

8486
assert (
8587
CURRENT_CASE_VERSION == version_info

tests/case_utils/test_guess_format.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import pytest
1515
import rdflib # type: ignore
1616

17-
import case_utils
18-
1917
PATH_TO_TTL = "/nonexistent/foo.ttl"
2018
PATH_TO_JSON = "/nonexistent/foo.json"
2119
PATH_TO_JSONLD = "/nonexistent/foo.jsonld"

tests/case_utils/test_local_uuid.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#
1212
# We would appreciate acknowledgement if the software is used.
1313

14-
import os
15-
1614
import pytest
1715

1816
import case_utils.local_uuid

tests/src/compact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
__version__ = "0.2.0"
2222

23+
import json
2324
import logging
2425
import os
25-
import json
2626
import typing
2727

2828
import pyld # type: ignore
@@ -35,7 +35,7 @@ def main() -> None:
3535
doc = None
3636
with open(args.in_json, "r") as in_fh:
3737
doc = json.load(in_fh)
38-
assert not doc is None
38+
assert doc is not None
3939
assert isinstance(
4040
doc, (dict, list)
4141
), "JSON parsed top-level type assumption invalidated"
@@ -46,7 +46,7 @@ def main() -> None:
4646
def _accrue_local_context(doc_object: typing.Dict[str, typing.Any]) -> None:
4747
local_context = doc_object.get("@context", dict())
4848
for key in local_context.keys():
49-
if not key in total_context:
49+
if key not in total_context:
5050
# Accrue new key.
5151
total_context[key] = local_context[key]
5252

tests/src/glom_graph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import rdflib # type: ignore
2121

22-
import case_utils
23-
2422

2523
def main() -> None:
2624
g = rdflib.Graph()

tests/src/isomorphic_diff.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
import rdflib.compare # type: ignore
3838

39-
import case_utils
40-
4139
_logger = logging.getLogger(os.path.basename(__file__))
4240

4341

0 commit comments

Comments
 (0)