Skip to content

Commit

Permalink
Remove Black, switch to Ruff Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysommer committed Jan 24, 2025
1 parent 93d9f7b commit ca92802
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 152 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 3 additions & 77 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 7 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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}
Expand All @@ -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",
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions pyshacl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
Expand All @@ -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'),
)
Expand All @@ -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'),
)
Expand All @@ -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'),
)
Expand Down
8 changes: 4 additions & 4 deletions pyshacl/cli_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
Expand All @@ -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'),
)
Expand All @@ -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'),
)
Expand All @@ -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'),
)
Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/advanced/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SHACL-AF Advanced Constraints
https://www.w3.org/TR/shacl-af/#ExpressionConstraintComponent
"""

import typing
from typing import Dict, List

Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/constraint_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
https://www.w3.org/TR/shacl/#core-components-value-type
"""

import abc
import re
import typing
Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/core/cardinality_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
https://www.w3.org/TR/shacl/#core-components-count
"""

from typing import Dict, List, Optional

from rdflib.namespace import XSD
Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/core/logical_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
https://www.w3.org/TR/shacl/#core-components-logical
"""

from typing import Dict, List
from warnings import warn

Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/core/other_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
https://www.w3.org/TR/shacl/#core-components-others
"""

import logging
from typing import Dict, List, Set, Union, cast

Expand Down
9 changes: 5 additions & 4 deletions pyshacl/constraints/core/property_pair_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
https://www.w3.org/TR/shacl/#core-components-property-pairs
"""

from typing import Dict, List

import rdflib
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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()):
Expand Down
1 change: 1 addition & 0 deletions pyshacl/constraints/core/shape_based_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ca92802

Please sign in to comment.