Skip to content

Add flake8 and isort to precommit #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
repos:
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- id: black
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
2 changes: 1 addition & 1 deletion case_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

__version__ = "0.5.0"

from . import local_uuid
from . import local_uuid # noqa: F401
15 changes: 11 additions & 4 deletions case_utils/case_file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
import rdflib # type: ignore

import case_utils
from case_utils.namespace import *
from case_utils.namespace import (
NS_RDF,
NS_UCO_CORE,
NS_UCO_OBSERVABLE,
NS_UCO_TYPES,
NS_UCO_VOCABULARY,
NS_XSD,
)

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

Expand Down Expand Up @@ -147,7 +154,7 @@ def create_file_node(
sha1obj.update(buf)
sha256obj.update(buf)
sha512obj.update(buf)
if not stashed_error is None:
if stashed_error is not None:
raise stashed_error
current_hashdict = HashDict(
byte_tally,
Expand Down Expand Up @@ -182,7 +189,7 @@ def create_file_node(

# Add confirmed hashes into graph.
for key in successful_hashdict._fields:
if not key in ("md5", "sha1", "sha256", "sha512"):
if key not in ("md5", "sha1", "sha256", "sha512"):
continue
n_hash = rdflib.BNode()
graph.add((n_contentdata_facet, NS_UCO_OBSERVABLE.hash, n_hash))
Expand Down Expand Up @@ -247,7 +254,7 @@ def main() -> None:
serialize_kwargs["context"] = context_dictionary

node_iri = NS_BASE["file-" + case_utils.local_uuid.local_uuid()]
n_file = create_file_node(
create_file_node(
graph,
args.in_file,
node_iri=node_iri,
Expand Down
8 changes: 5 additions & 3 deletions case_utils/case_sparql_construct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import rdflib.plugins.sparql # type: ignore

import case_utils.ontology

from case_utils.ontology.version_info import *
from case_utils.ontology.version_info import (
CURRENT_CASE_VERSION,
built_version_choices_list,
)

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

Expand Down Expand Up @@ -81,7 +83,7 @@ def main() -> None:
construct_query_text = None
with open(args.in_sparql, "r") as in_fh:
construct_query_text = in_fh.read().strip()
assert not construct_query_text is None
assert construct_query_text is not None

if "subClassOf" in construct_query_text:
case_utils.ontology.load_subclass_hierarchy(
Expand Down
7 changes: 4 additions & 3 deletions case_utils/case_sparql_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import argparse
import binascii
import importlib.resources
import logging
import os
import sys
Expand All @@ -39,8 +38,10 @@
import rdflib.plugins.sparql # type: ignore

import case_utils.ontology

from case_utils.ontology.version_info import *
from case_utils.ontology.version_info import (
CURRENT_CASE_VERSION,
built_version_choices_list,
)

NS_XSD = rdflib.XSD

Expand Down
9 changes: 5 additions & 4 deletions case_utils/case_validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
import importlib.resources
import logging
import os
import pathlib
import sys
import typing

import rdflib.util # type: ignore
import pyshacl # type: ignore
import rdflib.util # type: ignore

import case_utils.ontology

from case_utils.ontology.version_info import *
from case_utils.ontology.version_info import (
CURRENT_CASE_VERSION,
built_version_choices_list,
)

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

Expand Down
2 changes: 1 addition & 1 deletion case_utils/local_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import pathlib
import sys
import typing
import warnings
import uuid
import warnings

DEMO_UUID_BASE: typing.Optional[str] = None

Expand Down
2 changes: 1 addition & 1 deletion case_utils/ontology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Yes, this next import is self-referential (/circular). But, it does work with importlib.
import case_utils.ontology

from .version_info import *
from .version_info import CURRENT_CASE_VERSION

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

Expand Down
11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ console_scripts =
[options.package_data]
case_utils = py.typed
case_utils.ontology = *.ttl

[flake8]
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
extend-ignore =
E203
E302
E501

[isort]
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html
profile = black
6 changes: 3 additions & 3 deletions tests/case_utils/case_file/test_case_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import rdflib.plugins.sparql # type: ignore

import case_utils.ontology
from case_utils.namespace import *
from case_utils.namespace import NS_UCO_CORE, NS_UCO_OBSERVABLE, NS_UCO_TYPES

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

Expand Down Expand Up @@ -117,12 +117,12 @@ def test_confirm_mtime(
for result in graph_case_file_disable_hashes.query(query_object):
(n_observable_object,) = result
assert (
not n_observable_object is None
n_observable_object is not None
), "File object with expected mtime not found in hashless graph."

n_observable_object = None
for result in graph_case_file.query(query_object):
(n_observable_object,) = result
assert (
not n_observable_object is None
n_observable_object is not None
), "File object with expected mtime not found in fuller graph."
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import rdflib.plugins.sparql # type: ignore

import case_utils


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


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

graph = rdflib.Graph()
graph.parse(filename)
Expand All @@ -59,7 +56,7 @@ def _test_w3_templates_with_blank_nodes_result(filename: str) -> None:
for result in graph.query(query_string):
(l_given_name, l_family_name) = result
computed.add((l_given_name.toPython(), l_family_name.toPython()))
assert computed == ground_truth_positive
assert expected == computed


def test_w3_templates_with_blank_nodes_result_json() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_format_jsonld_output_jsonld() -> None:
subject_file = "format_jsonld_output_jsonld.jsonld"
asserted_format = _guess_format(subject_file)
assert asserted_format == "json-ld"
graph = _parse_graph(subject_file, asserted_format)
_parse_graph(subject_file, asserted_format)


@pytest.mark.xfail(
Expand All @@ -107,7 +107,7 @@ def test_format_jsonld_output_unspecified() -> None:
subject_file = "format_jsonld_output_unspecified.jsonld"
asserted_format = _guess_format(subject_file)
assert asserted_format == "json-ld"
graph = _parse_graph(subject_file, asserted_format)
_parse_graph(subject_file, asserted_format)


@pytest.mark.xfail(
Expand All @@ -124,7 +124,7 @@ def test_format_turtle_output_turtle() -> None:
subject_file = "format_turtle_output_turtle.ttl"
asserted_format = _guess_format(subject_file)
assert asserted_format == "turtle"
graph = _parse_graph(subject_file, asserted_format)
_parse_graph(subject_file, asserted_format)


def test_format_turtle_output_txt() -> None:
Expand All @@ -138,7 +138,7 @@ def test_format_turtle_output_unspecified() -> None:
subject_file = "format_turtle_output_unspecified.ttl"
asserted_format = _guess_format(subject_file)
assert asserted_format == "turtle"
graph = _parse_graph(subject_file, asserted_format)
_parse_graph(subject_file, asserted_format)


@pytest.mark.xfail(
Expand Down
12 changes: 7 additions & 5 deletions tests/case_utils/ontology/test_version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import rdflib # type: ignore

import case_utils.ontology

from case_utils.ontology.version_info import *
from case_utils.ontology.version_info import (
CURRENT_CASE_VERSION,
built_version_choices_list,
)

NS_OWL = rdflib.OWL

Expand All @@ -30,7 +32,7 @@ def test_built_version_choices_list() -> None:
continue
ttl_filename = built_version_choice + ".ttl"
with importlib.resources.open_text(case_utils.ontology, ttl_filename) as tmp_fh:
pass
assert tmp_fh


def test_case_ontology_version_info_versus_monolithic() -> None:
Expand All @@ -49,7 +51,7 @@ def test_case_ontology_version_info_versus_monolithic() -> None:
)
):
version_info = str(triple[2])
assert not version_info is None, "Failed to retrieve owl:versionInfo"
assert version_info is not None, "Failed to retrieve owl:versionInfo"

assert (
CURRENT_CASE_VERSION == version_info
Expand Down Expand Up @@ -79,7 +81,7 @@ def test_case_ontology_version_info_versus_submodule() -> None:
)
):
version_info = str(triple[2])
assert not version_info is None, "Failed to retrieve owl:versionInfo"
assert version_info is not None, "Failed to retrieve owl:versionInfo"

assert (
CURRENT_CASE_VERSION == version_info
Expand Down
2 changes: 0 additions & 2 deletions tests/case_utils/test_guess_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import pytest
import rdflib # type: ignore

import case_utils

PATH_TO_TTL = "/nonexistent/foo.ttl"
PATH_TO_JSON = "/nonexistent/foo.json"
PATH_TO_JSONLD = "/nonexistent/foo.jsonld"
Expand Down
2 changes: 0 additions & 2 deletions tests/case_utils/test_local_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#
# We would appreciate acknowledgement if the software is used.

import os

import pytest

import case_utils.local_uuid
Expand Down
6 changes: 3 additions & 3 deletions tests/src/compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

__version__ = "0.2.0"

import json
import logging
import os
import json
import typing

import pyld # type: ignore
Expand All @@ -35,7 +35,7 @@ def main() -> None:
doc = None
with open(args.in_json, "r") as in_fh:
doc = json.load(in_fh)
assert not doc is None
assert doc is not None
assert isinstance(
doc, (dict, list)
), "JSON parsed top-level type assumption invalidated"
Expand All @@ -46,7 +46,7 @@ def main() -> None:
def _accrue_local_context(doc_object: typing.Dict[str, typing.Any]) -> None:
local_context = doc_object.get("@context", dict())
for key in local_context.keys():
if not key in total_context:
if key not in total_context:
# Accrue new key.
total_context[key] = local_context[key]

Expand Down
2 changes: 0 additions & 2 deletions tests/src/glom_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import rdflib # type: ignore

import case_utils


def main() -> None:
g = rdflib.Graph()
Expand Down
2 changes: 0 additions & 2 deletions tests/src/isomorphic_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

import rdflib.compare # type: ignore

import case_utils

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


Expand Down