diff --git a/.codespellrc b/.codespellrc deleted file mode 100644 index 25245058f..000000000 --- a/.codespellrc +++ /dev/null @@ -1,4 +0,0 @@ -[codespell] -skip = env,venv,*.svg -ignore-words-list = HSI -builtin = clear,rare diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..bb93c8a93 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length=79 +exclude = + scripts/editProperties.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e38b9c78..8cf1e3ea2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,11 +11,29 @@ repos: - id: check-ast - id: check-added-large-files - id: check-merge-conflict + +# Sorts Python imports alphabetically and by section with `isort`. +- repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: [--settings-path, pyproject.toml] + - repo: https://github.com/psf/black rev: 24.3.0 hooks: - id: black + - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: - id: codespell + args: [--toml, pyproject.toml] + additional_dependencies: [tomli] + +- repo: https://github.com/pyCQA/flake8 + rev: 7.1.0 + hooks: + - id: flake8 + args: [--config, .flake8, --verbose] + additional_dependencies: [flake8-bugbear] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..44bf682b2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[tool.black] +line-length = 79 + +[tool.codespell] +skip = "env,venv,*.svg,pyproject.toml" +ignore-words-list = "HSI" +builtin = "clear,rare" + +[tool.isort] +combine_as_imports = true +line_length = 79 +profile = "black" +skip_gitignore = true diff --git a/scripts/editProperties.py b/scripts/editProperties.py index e045df606..b6f1ce921 100644 --- a/scripts/editProperties.py +++ b/scripts/editProperties.py @@ -1,4 +1,5 @@ import sys + import rdflib as rl from pytablewriter import MarkdownTableWriter @@ -81,7 +82,11 @@ def edit_properties(version): writer.value_matrix = [] del props["klass_desc"] for val, comment in sorted(props.items()): - property = [val[2], comment, f"[{val[1]}{val[2]}]({val[1]}{val[2]})"] + property = [ + val[2], + comment, + f"[{val[1]}{val[2]}]({val[1]}{val[2]})", + ] writer.value_matrix.append(property) writer.margin = 1 # add a whitespace for both sides of each cell doc.append("\n") diff --git a/scripts/jsonParser.py b/scripts/jsonParser.py index d3ef9c78c..16c4d5b0b 100644 --- a/scripts/jsonParser.py +++ b/scripts/jsonParser.py @@ -1,9 +1,9 @@ -import os import json +import os schema_dirs = ["contexts", "schemas", "terms"] tested = 0 -for root, dirs, files in os.walk(".", topdown=True): +for root, _, files in os.walk(".", topdown=True): if os.path.basename(root) in schema_dirs: for name in files: with open(os.path.join(root, name)) as fp: diff --git a/scripts/makeRelease.py b/scripts/makeRelease.py index 5a81ca88e..f933d973a 100644 --- a/scripts/makeRelease.py +++ b/scripts/makeRelease.py @@ -1,9 +1,11 @@ +import json import os import sys -import json -from pyld import jsonld -import rdflib as rl from shutil import copyfile + +import rdflib as rl +from pyld import jsonld + from reproschema.jsonldutils import to_newformat @@ -12,7 +14,9 @@ def create_release(version): terms = [] for root, _, files in os.walk("terms"): for name in files: - terms.extend(json.loads(to_newformat(os.path.join(root, name), "jsonld"))) + terms.extend( + json.loads(to_newformat(os.path.join(root, name), "jsonld")) + ) kwargs = {"algorithm": "URDNA2015", "format": "application/n-quads"} data = jsonld.normalize(terms, kwargs)