Skip to content

Library Usage - #118

Merged
kchason merged 21 commits into
developfrom
library-usage
Aug 24, 2023
Merged

Library Usage#118
kchason merged 21 commits into
developfrom
library-usage

Conversation

@kchason

@kchason kchason commented Jul 25, 2023

Copy link
Copy Markdown
Member

Example usage of the programmatic usage of the CASE utilities.

import os

from case_utils.case_validate import validate, ValidationResult

# Validate a case file
result: ValidationResult = validate(os.path.abspath("location.json"), 'case-1.2.0')

print("Valid" if result.conforms else "Invalid")

@kchason
kchason requested a review from a team as a code owner July 25, 2023 00:37

@ajnelson-nist ajnelson-nist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are at least three can't-pass-as-is issues. It looks like a few parts of this PR can be filed on their own while we work those out.

Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
ajnelson-nist added a commit that referenced this pull request Jul 25, 2023
This patch partially implements a small piece of PR 118.

References:
* #118

Requested-by: kchason <keith.chason@gmail.com>
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
ajnelson-nist pushed a commit that referenced this pull request Aug 9, 2023
AJN: This is a partial application of @kchason 's work in PR 118, and is
being pulled into its own patch series to focus review.

References:
* #118

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
@ajnelson-nist ajnelson-nist added this to the 0.12.0 milestone Aug 14, 2023
No effects were observed on Make-managed files.

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
It seems to me like `--disallow-untyped-defs`, enabled in
`mypy --strict`, should have flagged this as an error.  However, from
documentation on `no-untyped-def`, `mypy` only requires
`__init__(...) -> None` when there is any argument aside from the first
`self`.  This patch follows the parenthetical recommendation from PEP
484 that `-> None` be given anyways.

References:
* https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-disallow-untyped-defs
* https://mypy.readthedocs.io/en/stable/error_code_list2.html#check-that-every-function-has-an-annotation-no-untyped-def
* https://peps.python.org/pep-0484/#the-meaning-of-annotations

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
… type

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Comment thread case_utils/case_validate/__init__.py Outdated
Comment thread case_utils/case_validate/__init__.py Outdated
validate_result = pyshacl.validate(
validate_result: Tuple[
bool, Union[Exception, bytes, str, rdflib.Graph], str
] = pyshacl.validate(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this call needs to be replaced with the validate() method this PR is adding to this file, but only after logistics related to #123 are settled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is addressed in 15f00c9.

Comment thread case_utils/case_validate/__init__.py Outdated

class NonExistentCDOConceptWarning(UserWarning):
def validate(
input_file: str,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our awareness, this is a narrower argument than the first argument of pyshacl.validate; here's today's definition:

https://github.com/RDFLib/pySHACL/blob/v0.23.0/pyshacl/validate.py#L369-L370

pyshacl.validate's first argument seems to permit a string to be a file path or URL, OR a full string dump of a graph. See these lines for heuristics in pyshacl.rdfutil.load.load_from_graph:

https://github.com/RDFLib/pySHACL/blob/v0.23.0/pyshacl/rdfutil/load.py#L222-L227

Should we implement "str means path" now, or just adopt the load_from_graph usage now from these lines:

https://github.com/RDFLib/pySHACL/blob/v0.23.0/pyshacl/validate.py#L424-L428

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp, I found an issue pushing us towards expanding input_file from str. case_validate is written to take multiple input files as data graphs (as well as multiple input files as ontology graphs). I believe this behavior should be preserved, because otherwise a user that needs to read two data graphs at once needs to do some intermediary graph compilation before calling case_validate.

So, I think the first argument needs to become at least either Union[str, List[str]] or Union[str, Graph]. The current code path from the CLI entry point I think favors Union[str, List[str]].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is addressed in 15f00c9.

…idate

This patch separates implementation points between functionality
distinct to `case_utils.validate` and `pyshacl.validate`.  The
`allow_warnings` and `inference` parameters provide CASE-specific
documentation as an augmentation to `pyshacl.validate`'s documentation,
but otherwise other documentation on `pyshacl.validate`'s keyword
arguments is delegated to their upstream function.

This patch removes some hardcoded parameter values in
`pyshacl.validate`, letting the `case_validate` CLI or caller provide
any runtime-requested values.

Also, without functional impact, this patch sorts keyword parameters
alphabetically.

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>

@ajnelson-nist ajnelson-nist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this merging once CI passes. Also open to discussing any of the last revisions I made.

@kchason
kchason merged commit bded343 into develop Aug 24, 2023
@kchason
kchason deleted the library-usage branch August 24, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants