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."

0 commit comments

Comments
 (0)