Skip to content
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

The long-await standalone SHACL Rule Expander mode #260

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Python PEP 440 Versioning](https://www.python.org/d
## [Unreleased]

### Added
- SHACL Rules Expander Mode
- A new alternative Run Mode for PySHACL
- PySHACL will not validate the DataGraph against Shapes and Constraints, instead it will simply run all SHACL-AF Rules to expand the DataGraph.
- By default it will output a new graph containing the existing DataGraph Triples plus the expanded triples
- Run with inplace mode to expand the new triples directly into the input DataGraph
- Focus Node Filtering
- You can now pass in a list of focus nodes to the validator, and it will only validate those focus nodes.
- Note, you still need to pass in a SHACL Shapes Graph, and the shapes still need to target the focus nodes.
Expand All @@ -19,6 +24,9 @@ and this project adheres to [Python PEP 440 Versioning](https://www.python.org/d
- If you give the validator a list of Shapes to use, and a list of focus nodes, the validator will operate in
a highly-targeted mode, it feeds those focus nodes directly into those given Shapes for validation.
- In this mode, the selected SHACL Shape does not need to specify any focus-targeting mechanisms of its own.
- Combined Rules Expander Mode with Shape Selection
- The combination of SHACL Rules Expander Mode and Shape Selection will allow specialised workflows.
- For example, you can run specific expansion rules from a SHACL Shapes File, based on the new triples required.

### Changed
- Don't make a clone of the DataGraph if the input data graph is ephemeral.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY . .
RUN chown -R pyshacl:pyshacl /home/pyshacl /app && chmod -R 775 /home/pyshacl /app
USER pyshacl
ENV PATH="/home/pyshacl/.local/bin:$PATH"
RUN pip3 install "poetry>=1.5.0,<2.0"
RUN pip3 install "poetry>=1.8.3,<2.0"
RUN poetry install --no-dev --extras "js http"
USER root
RUN apk del build-dependencies
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ dev-coverage = ["pytest-cov", "coverage", "platformdirs"]

[tool.poetry.scripts]
pyshacl = "pyshacl.cli:main"
pyshacl_rules = "pyshacl.cli_rules:main"
pyshacl_validate = "pyshacl.cli:main"
pyshacl_server = "pyshacl.http:cli"

Expand Down
6 changes: 4 additions & 2 deletions pyshacl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: latin-1 -*-
#
from .entrypoints import shacl_rules, validate
from .rule_expand_runner import RuleExpandRunner
from .shape import Shape
from .shapes_graph import ShapesGraph
from .validate import Validator, validate
from .validator import Validator

# version compliant with https://www.python.org/dev/peps/pep-0440/
__version__ = '0.26.0'
# Don't forget to change the version number in pyproject.toml, Dockerfile, and CITATION.cff along with this one

__all__ = ['validate', 'Validator', '__version__', 'Shape', 'ShapesGraph']
__all__ = ['validate', 'shacl_rules', 'Validator', 'RuleExpandRunner', '__version__', 'Shape', 'ShapesGraph']
13 changes: 9 additions & 4 deletions pyshacl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os
import sys

from pyshacl.cli import main
from pyshacl.cli import main as validate_main
from pyshacl.cli_rules import main as rules_main


def str_is_true(s_var: str):
Expand All @@ -16,11 +17,15 @@ def str_is_true(s_var: str):
do_server = os.getenv("PYSHACL_HTTP", "")
do_server = os.getenv("PYSHACL_SERVER", do_server)

if (len(sys.argv) > 1 and str(sys.argv[1]).lower() in ('serve', 'server', '--server')) or (
first_arg = None if len(sys.argv) < 2 else sys.argv[1]

if first_arg is not None and str(first_arg).lower() in ('rules', '--rules'):
rules_main(prog="python3 -m pyshacl")
elif (first_arg is not None and str(first_arg).lower() in ('serve', 'server', '--server')) or (
do_server and str_is_true(do_server)
):
from pyshacl.sh_http import main as http_main

http_main()

main(prog="python3 -m pyshacl")
else:
validate_main(prog="python3 -m pyshacl")
12 changes: 12 additions & 0 deletions pyshacl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def str_is_true(s_var: str):
help='Send output to a file (defaults to stdout).',
default=sys.stdout,
)
parser.add_argument(
'--rules',
help='Ignore validation options, run PySHACL in Rules Expansion mode. Same as `pyshacl_rules`.',
action='store_true',
dest='do_rules',
default=False,
)
parser.add_argument(
'--server',
help='Ignore all the rest of the options, start the HTTP Server. Same as `pyshacl_server`.',
Expand All @@ -240,6 +247,11 @@ def main(prog: Union[str, None] = None) -> None:

# http_main calls sys.exit(0) and never returns
http_main()
if args.do_rules:
from pyshacl.cli_rules import main as rules_main

# rules_main calls sys.exit(0) and never returns
rules_main()
if not args.data:
# No datafile give, and not starting in server mode.
sys.stderr.write('Input Error. No DataGraph file or endpoint supplied.\n')
Expand Down
Loading