From ca92802da698d1907164c911ce78c4d700a7697e Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Fri, 24 Jan 2025 16:55:03 +1000 Subject: [PATCH] Remove Black, switch to Ruff Format. --- Makefile | 12 +-- poetry.lock | 80 +------------------ pyproject.toml | 44 ++-------- pyshacl/cli.py | 8 +- pyshacl/cli_rules.py | 8 +- pyshacl/constraints/advanced/__init__.py | 1 + pyshacl/constraints/constraint_component.py | 1 + .../core/cardinality_constraints.py | 1 + .../constraints/core/logical_constraints.py | 1 + pyshacl/constraints/core/other_constraints.py | 1 + .../core/property_pair_constraints.py | 9 ++- .../core/shape_based_constraints.py | 1 + .../core/string_based_constraints.py | 1 + pyshacl/constraints/core/value_constraints.py | 1 + .../sparql_based_constraint_components.py | 1 + .../sparql/sparql_based_constraints.py | 4 +- pyshacl/extras/js/loader.py | 4 +- pyshacl/extras/js/rules.py | 1 - pyshacl/helper/sparql_query_helper.py | 1 + pyshacl/rdfutil/load.py | 12 +-- pyshacl/shape.py | 10 +-- pyshacl/validator_conformance.py | 9 ++- 22 files changed, 59 insertions(+), 152 deletions(-) diff --git a/Makefile b/Makefile index 456e96a..0aaee86 100644 --- a/Makefile +++ b/Makefile @@ -32,25 +32,25 @@ dev-test: venvcheck ## Run the tests in dev environment poetry run pytest --cov=pyshacl test/ .PHONY: format -format: venvcheck ## Run Black and isort Formatters +format: venvcheck ## Run Ruff and isort Formatters ifeq ("$(FilePath)", "") poetry run ruff check --select I --fix ./pyshacl #isort fix - poetry run black --config=./pyproject.toml --verbose pyshacl + poetry run ruff format --no-preview --target-version py39 pyshacl else poetry run ruff check --select I --fix "$(FilePath)" #isort fix - poetry run black --config=./pyproject.toml --verbose "$(FilePath)" + poetry run ruff format --no-preview --target-version py39 "$(FilePath)" endif .PHONY: lint -lint: venvcheck ## Validate with Black and isort in check-only mode +lint: venvcheck ## Validate with Ruff and isort in check-only mode ifeq ("$(FilePath)", "") poetry run ruff check ./pyshacl #flake8 poetry run ruff check --select I ./pyshacl #isort - poetry run black --config=./pyproject.toml --check --verbose pyshacl + poetry run ruff format --check --no-preview --target-version py39 pyshacl else poetry run ruff check ./"$(FilePath)" #flake8 poetry run ruff check --select I ./"$(FilePath)" #isort - poetry run black --config=./pyproject.toml --check --verbose "$(FilePath)" + poetry run ruff format --check --no-preview --target-version py39 "$(FilePath)" endif .PHONY: type-check diff --git a/poetry.lock b/poetry.lock index 987e5d4..2cded31 100644 --- a/poetry.lock +++ b/poetry.lock @@ -13,68 +13,6 @@ files = [ {file = "aiofiles-24.1.0.tar.gz", hash = "sha256:22a075c9e5a3810f0c2e48f3008c94d68c65d763b9b03857924c99e57355166c"}, ] -[[package]] -name = "black" -version = "24.3.0" -description = "The uncompromising code formatter." -optional = true -python-versions = ">=3.8" -groups = ["main", "dev"] -files = [ - {file = "black-24.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395"}, - {file = "black-24.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995"}, - {file = "black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7"}, - {file = "black-24.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0"}, - {file = "black-24.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9"}, - {file = "black-24.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597"}, - {file = "black-24.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d"}, - {file = "black-24.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5"}, - {file = "black-24.3.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f"}, - {file = "black-24.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11"}, - {file = "black-24.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4"}, - {file = "black-24.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5"}, - {file = "black-24.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837"}, - {file = "black-24.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd"}, - {file = "black-24.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213"}, - {file = "black-24.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959"}, - {file = "black-24.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb"}, - {file = "black-24.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7"}, - {file = "black-24.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7"}, - {file = "black-24.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f"}, - {file = "black-24.3.0-py3-none-any.whl", hash = "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93"}, - {file = "black-24.3.0.tar.gz", hash = "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -packaging = ">=22.0" -pathspec = ">=0.9.0" -platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - -[[package]] -name = "click" -version = "8.1.7" -description = "Composable command line interface toolkit" -optional = true -python-versions = ">=3.7" -groups = ["main", "dev"] -files = [ - {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, - {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} - [[package]] name = "colorama" version = "0.4.6" @@ -82,7 +20,7 @@ description = "Cross-platform colored terminal text." optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" groups = ["main", "dev"] -markers = "platform_system == \"Windows\" or sys_platform == \"win32\"" +markers = "sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -485,18 +423,6 @@ files = [ {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"}, ] -[[package]] -name = "pathspec" -version = "0.12.1" -description = "Utility library for gitignore style pattern matching of file paths." -optional = true -python-versions = ">=3.8" -groups = ["main", "dev"] -files = [ - {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, - {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, -] - [[package]] name = "platformdirs" version = "4.3.6" @@ -1202,7 +1128,7 @@ type = ["pytest-mypy"] [extras] dev-coverage = ["coverage", "platformdirs", "pytest-cov"] -dev-lint = ["black", "platformdirs", "ruff"] +dev-lint = ["platformdirs", "ruff"] dev-type-checking = ["mypy", "platformdirs", "types-setuptools"] http = ["sanic", "sanic-cors", "sanic-ext"] js = ["pyduktape2"] @@ -1210,4 +1136,4 @@ js = ["pyduktape2"] [metadata] lock-version = "2.1" python-versions = ">=3.9,<4" -content-hash = "60d8842dd4f12702c833fa63800d6430f81c02efe2dd41251a6214c5eafa3176" +content-hash = "a29e234e2dca54f523fe251507b87557432cf4a2191ccba6ace6c965e5d655ef" diff --git a/pyproject.toml b/pyproject.toml index 83254fa..cf1185e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api" name = "pyshacl" # Don't forget to change the version number in __init__.py, Dockerfile, and CITATION.cff along with this one version = "0.29.1" -# Black and Ruff both now read target-version from [project.requires-python] +# Ruff and Poetry both now read target-version from [project.requires-python] # The <4 is reauired for compatiblity with OWL-RL that requdires Python <4 requires-python = ">=3.9,<4" description = "Python SHACL Validator" @@ -72,8 +72,7 @@ http = [ "sanic-cors==2.2.0" ] dev-lint = [ - "ruff>=0.9.1", - "black==24.3.0", + "ruff<0.10,>=0.9.3", "platformdirs" ] dev-type-checking = [ @@ -120,8 +119,7 @@ include = [ pytest = "^7.2" coverage = {version=">6,<7,!=6.0.*,!=6.1,!=6.1.1", optional=true} pytest-cov = {version="^2.8.1", optional=true} -ruff = {version="^0.9.1", optional=true} -black = {version="24.3.0", optional=true} +ruff = {version="<0.10,>=0.9.3", optional=true} mypy = {version=">=1.13.0", optional=true} types-setuptools = {version="*", optional=true} platformdirs = {version="*", optional=true} @@ -130,37 +128,7 @@ platformdirs = {version="*", optional=true} from = {format = "poetry", path = "pyproject.toml"} to = {format = "setuppy", path = "setup.py"} -[tool.black] -required-version = "24.3.0" -line-length = "119" -skip-string-normalization = true -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.ruff_cache - | \.pytest_cache - | \.tox - | \.venv - | _build - | htmlcov - | benchmarks - | examples - | pyshacl.egg-info - | buck-out - | build - | dist - | venv - )/ -) -''' - [tool.ruff] - # Exclude a variety of commonly ignored directories. exclude = [ ".bzr", @@ -189,9 +157,11 @@ exclude = [ "node_modules", "venv", ] -# Same as Black. line-length = 119 +[tool.ruff.format] +quote-style = "preserve" + [lint] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. select = ["E", "F"] @@ -256,7 +226,7 @@ commands = - poetry show poetry run ruff check ./pyshacl poetry run ruff check --select I ./pyshacl #isort - poetry run black --check --verbose --config ./pyproject.toml pyshacl + poetry run ruff format --check --no-preview --target-version py39 pyshacl #black [testenv:type-checking] commands_pre = diff --git a/pyshacl/cli.py b/pyshacl/cli.py index c02f07d..98e7166 100644 --- a/pyshacl/cli.py +++ b/pyshacl/cli.py @@ -175,7 +175,7 @@ def str_is_true(s_var: str): '--format', dest='format', action='store', - help='Choose an output format. Default is \"human\".', + help='Choose an output format. Default is "human".', default='human', choices=('human', 'table', 'turtle', 'xml', 'json-ld', 'nt', 'n3'), ) @@ -184,7 +184,7 @@ def str_is_true(s_var: str): '--data-file-format', dest='data_file_format', action='store', - help='Explicitly state the RDF File format of the input DataGraph file. Default=\"auto\".', + help='Explicitly state the RDF File format of the input DataGraph file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'json-ld', 'nt', 'n3'), ) @@ -193,7 +193,7 @@ def str_is_true(s_var: str): '--shacl-file-format', dest='shacl_file_format', action='store', - help='Explicitly state the RDF File format of the input SHACL file. Default=\"auto\".', + help='Explicitly state the RDF File format of the input SHACL file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'json-ld', 'nt', 'n3'), ) @@ -202,7 +202,7 @@ def str_is_true(s_var: str): '--ont-file-format', dest='ont_file_format', action='store', - help='Explicitly state the RDF File format of the extra ontology file. Default=\"auto\".', + help='Explicitly state the RDF File format of the extra ontology file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'json-ld', 'nt', 'n3'), ) diff --git a/pyshacl/cli_rules.py b/pyshacl/cli_rules.py index 2ff1dda..dfbbb2a 100644 --- a/pyshacl/cli_rules.py +++ b/pyshacl/cli_rules.py @@ -106,7 +106,7 @@ '--format', dest='format', action='store', - help='Choose an output format. Default is \"trig\" for Datasets and \"turtle\" for Graphs.', + help='Choose an output format. Default is "trig" for Datasets and "turtle" for Graphs.', default='auto', choices=('auto', 'turtle', 'xml', 'trig', 'json-ld', 'nt', 'n3', 'nquads'), ) @@ -115,7 +115,7 @@ '--data-file-format', dest='data_file_format', action='store', - help='Explicitly state the RDF File format of the input DataGraph file. Default=\"auto\".', + help='Explicitly state the RDF File format of the input DataGraph file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'trig', 'json-ld', 'nt', 'n3', 'nquads'), ) @@ -124,7 +124,7 @@ '--shacl-file-format', dest='shacl_file_format', action='store', - help='Explicitly state the RDF File format of the input SHACL file. Default=\"auto\".', + help='Explicitly state the RDF File format of the input SHACL file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'trig', 'json-ld', 'nt', 'n3', 'nquads'), ) @@ -133,7 +133,7 @@ '--ont-file-format', dest='ont_file_format', action='store', - help='Explicitly state the RDF File format of the extra ontology file. Default=\"auto\".', + help='Explicitly state the RDF File format of the extra ontology file. Default="auto".', default='auto', choices=('auto', 'turtle', 'xml', 'trig', 'json-ld', 'nt', 'n3', 'nquads'), ) diff --git a/pyshacl/constraints/advanced/__init__.py b/pyshacl/constraints/advanced/__init__.py index 13e48a1..051074e 100644 --- a/pyshacl/constraints/advanced/__init__.py +++ b/pyshacl/constraints/advanced/__init__.py @@ -4,6 +4,7 @@ SHACL-AF Advanced Constraints https://www.w3.org/TR/shacl-af/#ExpressionConstraintComponent """ + import typing from typing import Dict, List diff --git a/pyshacl/constraints/constraint_component.py b/pyshacl/constraints/constraint_component.py index 35fe60d..2448f0c 100644 --- a/pyshacl/constraints/constraint_component.py +++ b/pyshacl/constraints/constraint_component.py @@ -3,6 +3,7 @@ """ https://www.w3.org/TR/shacl/#core-components-value-type """ + import abc import re import typing diff --git a/pyshacl/constraints/core/cardinality_constraints.py b/pyshacl/constraints/core/cardinality_constraints.py index 113c089..7cac2ee 100644 --- a/pyshacl/constraints/core/cardinality_constraints.py +++ b/pyshacl/constraints/core/cardinality_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-count """ + from typing import Dict, List, Optional from rdflib.namespace import XSD diff --git a/pyshacl/constraints/core/logical_constraints.py b/pyshacl/constraints/core/logical_constraints.py index b81f2ae..0f7b853 100644 --- a/pyshacl/constraints/core/logical_constraints.py +++ b/pyshacl/constraints/core/logical_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-logical """ + from typing import Dict, List from warnings import warn diff --git a/pyshacl/constraints/core/other_constraints.py b/pyshacl/constraints/core/other_constraints.py index 9bb0e1d..99311e3 100644 --- a/pyshacl/constraints/core/other_constraints.py +++ b/pyshacl/constraints/core/other_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-others """ + import logging from typing import Dict, List, Set, Union, cast diff --git a/pyshacl/constraints/core/property_pair_constraints.py b/pyshacl/constraints/core/property_pair_constraints.py index 52de276..c6b8311 100644 --- a/pyshacl/constraints/core/property_pair_constraints.py +++ b/pyshacl/constraints/core/property_pair_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-property-pairs """ + from typing import Dict, List import rdflib @@ -94,7 +95,7 @@ def _evaluate_property_equals_sparql(self, eq, target_graph, f_v_dict): non_conformant = False prefixes = dict(target_graph.namespaces()) eq_path = shacl_path_to_sparql_path(self.shape.sg, eq, prefixes=prefixes) - eq_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i,_ in enumerate(f_v_dict))} WHERE {{\n" + eq_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i, _ in enumerate(f_v_dict))} WHERE {{\n" init_bindings = {} f_eq_results = {} for i, f in enumerate(f_v_dict.keys()): @@ -221,7 +222,7 @@ def _evaluate_property_disjoint_sparql(self, dj, target_graph, f_v_dict): non_conformant = False prefixes = dict(target_graph.namespaces()) dj_path = shacl_path_to_sparql_path(self.shape.sg, dj, prefixes=prefixes) - dj_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i,_ in enumerate(f_v_dict))} WHERE {{\n" + dj_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i, _ in enumerate(f_v_dict))} WHERE {{\n" init_bindings = {} f_dj_results = {} for i, f in enumerate(f_v_dict.keys()): @@ -383,7 +384,7 @@ def _evaluate_less_than_sparql(self, lt, target_graph, f_v_dict): non_conformant = False prefixes = dict(target_graph.namespaces()) lt_path = shacl_path_to_sparql_path(self.shape.sg, lt, prefixes=prefixes) - lt_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i,_ in enumerate(f_v_dict))} WHERE {{\n" + lt_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i, _ in enumerate(f_v_dict))} WHERE {{\n" init_bindings = {} f_lt_results = {} for i, f in enumerate(f_v_dict.keys()): @@ -534,7 +535,7 @@ def _evaluate_ltoe_sparql(self, ltoe, target_graph, f_v_dict): non_conformant = False prefixes = dict(target_graph.namespaces()) ltoe_path = shacl_path_to_sparql_path(self.shape.sg, ltoe, prefixes=prefixes) - ltoe_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i,_ in enumerate(f_v_dict))} WHERE {{\n" + ltoe_lookup_query = f"SELECT DISTINCT {' '.join(f'?v{i}' for i, _ in enumerate(f_v_dict))} WHERE {{\n" init_bindings = {} f_ltoe_results = {} for i, f in enumerate(f_v_dict.keys()): diff --git a/pyshacl/constraints/core/shape_based_constraints.py b/pyshacl/constraints/core/shape_based_constraints.py index 628b551..d359ae6 100644 --- a/pyshacl/constraints/core/shape_based_constraints.py +++ b/pyshacl/constraints/core/shape_based_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-shape """ + from textwrap import indent from typing import Dict, List, Optional from warnings import warn diff --git a/pyshacl/constraints/core/string_based_constraints.py b/pyshacl/constraints/core/string_based_constraints.py index 8a098f1..2356716 100644 --- a/pyshacl/constraints/core/string_based_constraints.py +++ b/pyshacl/constraints/core/string_based_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-string """ + import logging import re from typing import Dict, List, cast diff --git a/pyshacl/constraints/core/value_constraints.py b/pyshacl/constraints/core/value_constraints.py index 2929483..8d364b8 100644 --- a/pyshacl/constraints/core/value_constraints.py +++ b/pyshacl/constraints/core/value_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#core-components-value-type """ + from datetime import date, datetime, time from decimal import Decimal from typing import Dict, List diff --git a/pyshacl/constraints/sparql/sparql_based_constraint_components.py b/pyshacl/constraints/sparql/sparql_based_constraint_components.py index e67cce3..adebe31 100644 --- a/pyshacl/constraints/sparql/sparql_based_constraint_components.py +++ b/pyshacl/constraints/sparql/sparql_based_constraint_components.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#sparql-constraint-components """ + import typing from typing import Dict, List, Tuple, Type, Union diff --git a/pyshacl/constraints/sparql/sparql_based_constraints.py b/pyshacl/constraints/sparql/sparql_based_constraints.py index 6cf9652..af0bd97 100644 --- a/pyshacl/constraints/sparql/sparql_based_constraints.py +++ b/pyshacl/constraints/sparql/sparql_based_constraints.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#sparql-constraints """ + from typing import Dict, List import rdflib @@ -71,8 +72,7 @@ def __init__(self, shape: Shape) -> None: deactivated = next(iter(deactivated_node_list)) if not (isinstance(deactivated, rdflib.Literal) and isinstance(deactivated.value, bool)): raise ConstraintLoadError( - "SPARQLConstraintComponent value for sh:deactivated must be " - "a Literal with type xsd:boolean.", + "SPARQLConstraintComponent value for sh:deactivated must be a Literal with type xsd:boolean.", "https://www.w3.org/TR/shacl/#SPARQLConstraintComponent", ) deact = bool(deactivated.value) diff --git a/pyshacl/extras/js/loader.py b/pyshacl/extras/js/loader.py index 94b9742..02b4034 100644 --- a/pyshacl/extras/js/loader.py +++ b/pyshacl/extras/js/loader.py @@ -29,9 +29,7 @@ def get_js_from_web(url: str): :type url: str :return: """ - headers = { - 'Accept': 'application/javascript, text/javascript, application/ecmascript, text/ecmascript,' 'text/plain' - } + headers = {'Accept': 'application/javascript, text/javascript, application/ecmascript, text/ecmascript,text/plain'} r = request.Request(url, headers=headers) resp = request.urlopen(r) code = resp.getcode() diff --git a/pyshacl/extras/js/rules.py b/pyshacl/extras/js/rules.py index 9ae2acc..e970348 100644 --- a/pyshacl/extras/js/rules.py +++ b/pyshacl/extras/js/rules.py @@ -11,7 +11,6 @@ from .js_executable import JSExecutable if TYPE_CHECKING: - from rdflib.term import URIRef from pyshacl.pytypes import GraphLike, RDFNode, SHACLExecutor diff --git a/pyshacl/helper/sparql_query_helper.py b/pyshacl/helper/sparql_query_helper.py index 2d6d4a3..d48124c 100644 --- a/pyshacl/helper/sparql_query_helper.py +++ b/pyshacl/helper/sparql_query_helper.py @@ -2,6 +2,7 @@ """ https://www.w3.org/TR/shacl/#sparql-constraints """ + import re import rdflib diff --git a/pyshacl/rdfutil/load.py b/pyshacl/rdfutil/load.py index 90bec9d..62d3326 100644 --- a/pyshacl/rdfutil/load.py +++ b/pyshacl/rdfutil/load.py @@ -206,7 +206,7 @@ def load_from_source( g = source else: raise RuntimeError( - "Cannot pass in both source=rdflib.Graph/Dataset and g=graph." + "Cannot pass in both source=rdflib.Graph/Dataset and g=graph. " "Source and dest cannot be the same graph." ) elif isinstance(source, (BufferedIOBase, TextIOBase)): @@ -446,7 +446,7 @@ def load_from_source( except AssertionError: break # Strip line from start - while len(line) > 0 and line[0:1] in b' \t\n\r\x0B\x0C\x85\xA0': + while len(line) > 0 and line[0:1] in b' \t\n\r\x0b\x0c\x85\xa0': line = line[1:] # We reached the end of the line, check the next line if len(line) < 1: @@ -455,23 +455,23 @@ def load_from_source( if not line[0:1] == b'#': break # Strip from start again, but now removing hashes too. - while len(line) > 0 and line[0:1] in b'# \t\xA0': + while len(line) > 0 and line[0:1] in b'# \t\xa0': line = line[1:] # Strip line from end - while len(line) > 0 and line[-1:] in b' \t\n\r\x0B\x0C\x85\xA0': + while len(line) > 0 and line[-1:] in b' \t\n\r\x0b\x0c\x85\xa0': line = line[:-1] spl = line.split(b':', 1) if len(spl) < 2: continue keyword = spl[0].lower() # Strip keyword end - while len(keyword) > 0 and keyword[-1:] in b' \t\n\r\x0B\x0C\x85\xA0': + while len(keyword) > 0 and keyword[-1:] in b' \t\n\r\x0b\x0c\x85\xa0': keyword = keyword[:-1] if len(keyword) < 1: continue wordval = spl[1] # Strip wordval start - while len(wordval) > 0 and wordval[0:1] in b' \t\n\r\x0B\x0C\x85\xA0': + while len(wordval) > 0 and wordval[0:1] in b' \t\n\r\x0b\x0c\x85\xa0': wordval = wordval[1:] if len(wordval) < 1: continue diff --git a/pyshacl/shape.py b/pyshacl/shape.py index b689005..a332a59 100644 --- a/pyshacl/shape.py +++ b/pyshacl/shape.py @@ -385,7 +385,7 @@ def focus_nodes(self, data_graph, debug=False): if debug: t2 = perf_counter() elapsed = t2 - t1 - self.logger.debug(f"Milliseconds to find focus nodes: {elapsed*1000.0:.3f}ms") + self.logger.debug(f"Milliseconds to find focus nodes: {elapsed * 1000.0:.3f}ms") return found_node_targets @classmethod @@ -534,7 +534,7 @@ def focus_nodes_sparql(self, data_graph, debug=False): if debug: t2 = perf_counter() elapsed = t2 - t1 - self.logger.debug(f"Milliseconds to find focus nodes: {elapsed*1000.0:.3f}ms") + self.logger.debug(f"Milliseconds to find focus nodes: {elapsed * 1000.0:.3f}ms") return found_node_targets def value_nodes(self, target_graph, focus, sparql_mode: bool = False, debug: bool = False): @@ -571,7 +571,7 @@ def value_nodes(self, target_graph, focus, sparql_mode: bool = False, debug: boo else: prefixes = dict(target_graph.namespace_manager.namespaces()) sparql_path = shacl_path_to_sparql_path(self.sg, path_val, prefixes=prefixes) - values_query = f"SELECT {' '.join(f'?v{i}' for i,_ in enumerate(focus))} WHERE {{\n" + values_query = f"SELECT {' '.join(f'?v{i}' for i, _ in enumerate(focus))} WHERE {{\n" init_bindings = {} for i, f in enumerate(focus): focus_dict[f] = set() @@ -598,7 +598,7 @@ def value_nodes(self, target_graph, focus, sparql_mode: bool = False, debug: boo if debug: t2 = perf_counter() elapsed = t2 - t1 - self.logger.debug(f"Milliseconds to find value nodes for focus nodes: {elapsed*1000.0:.3f}ms") + self.logger.debug(f"Milliseconds to find value nodes for focus nodes: {elapsed * 1000.0:.3f}ms") return focus_dict def find_custom_constraints(self): @@ -815,6 +815,6 @@ def validate( if collect_stats: t2 = perf_counter() elapsed = t2 - t1 - self.logger.debug(f"Milliseconds to evaluate shape {str(self)}: {elapsed*1000.0:.3f}ms") + self.logger.debug(f"Milliseconds to evaluate shape {str(self)}: {elapsed * 1000.0:.3f}ms") # print(_evaluation_path, "Passes" if not non_conformant else "Fails") return (not non_conformant), reports diff --git a/pyshacl/validator_conformance.py b/pyshacl/validator_conformance.py index 370d6cd..0179e3e 100644 --- a/pyshacl/validator_conformance.py +++ b/pyshacl/validator_conformance.py @@ -171,8 +171,9 @@ def compare_validation_reports( for expected_focus, expected_value, expected_path in expected_results_dict.keys(): if (expected_focus, expected_value, expected_path) not in report_results_dict: log.error( - "Expected result not found in Validation Report.\n" - "Expected focus: {}, value: {}, path: {}.".format(expected_focus, expected_value, expected_path) + "Expected result not found in Validation Report.\nExpected focus: {}, value: {}, path: {}.".format( + expected_focus, expected_value, expected_path + ) ) not_found_results += 1 if not_found_results > 0: @@ -344,7 +345,9 @@ def check_dash_result( eargs_str_list = [a.strip() for a in sargs.split(',')] eargs = [] for e in eargs_str_list: - eargs.append(from_n3(e, None, expected_result_graph.store, expected_result_graph.namespace_manager)) # type: ignore[arg-type] + eargs.append( + from_n3(e, None, expected_result_graph.store, expected_result_graph.namespace_manager) + ) # type: ignore[arg-type] find_uri = from_n3(expression, None, expected_result_graph.store, expected_result_graph.namespace_manager) # type: ignore[arg-type] if find_uri is None or not isinstance(find_uri, (str, URIRef, Literal, BNode)): raise ReportableRuntimeError("Cannot execute function {}.\nBad declaration format.".format(find_uri))