From ae64069066bd85339505d23ae530d106ccdc338a Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Wed, 21 Feb 2024 21:01:43 -0700 Subject: [PATCH] Enable flake8 Enables checking the code using flake8 --- .github/workflows/test.yaml | 5 ++ pyproject.toml | 1 + src/shacl2code/__init__.py | 6 +-- src/shacl2code/lang/__init__.py | 8 +-- src/shacl2code/lang/common.py | 5 +- src/shacl2code/lang/jinja.py | 2 +- src/shacl2code/lang/templates/python.j2 | 9 ++-- src/shacl2code/model.py | 6 +-- tests/expect/jsonschema/spdx3.json | 2 +- tests/expect/python/spdx3.py | 68 +++++++++++++++++++++++-- tests/expect/raw/spdx3.txt | 2 +- tests/test_jsonschema.py | 1 - tests/test_model_source.py | 4 +- 13 files changed, 89 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 32e863c..fa68d95 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,4 +39,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" - uses: psf/black@stable + - uses: py-actions/flake8@v2 diff --git a/pyproject.toml b/pyproject.toml index e46ff35..f2c4841 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ dev = [ "pytest >= 7.4", "pytest-server-fixtures >= 1.7", "pytest-cov >= 4.1", + "flake8 >= 7.0.0", ] [project.urls] diff --git a/src/shacl2code/__init__.py b/src/shacl2code/__init__.py index d3a6eda..6c18424 100644 --- a/src/shacl2code/__init__.py +++ b/src/shacl2code/__init__.py @@ -1,3 +1,3 @@ -from .model import Model, ContextMap -from .main import main -from .version import VERSION +from .model import Model, ContextMap # noqa: F401 +from .main import main # noqa: F401 +from .version import VERSION # noqa: F401 diff --git a/src/shacl2code/lang/__init__.py b/src/shacl2code/lang/__init__.py index 7ab929a..20d916e 100644 --- a/src/shacl2code/lang/__init__.py +++ b/src/shacl2code/lang/__init__.py @@ -3,9 +3,9 @@ # # SPDX-License-Identifier: MIT -from .lang import LANGUAGES +from .lang import LANGUAGES # noqa: F401 # All renderers must be imported here to be registered -from .jinja import JinjaRender -from .python import PythonRender -from .jsonschema import JsonSchemaRender +from .jinja import JinjaRender # noqa: F401 +from .python import PythonRender # noqa: F401 +from .jsonschema import JsonSchemaRender # noqa: F401 diff --git a/src/shacl2code/lang/common.py b/src/shacl2code/lang/common.py index ba2a40d..2de67cd 100644 --- a/src/shacl2code/lang/common.py +++ b/src/shacl2code/lang/common.py @@ -6,11 +6,8 @@ import sys import os from contextlib import contextmanager -from pathlib import Path from jinja2 import Environment, FileSystemLoader, TemplateRuntimeError -from .lang import TEMPLATE_DIR - class OutputFile(object): def __init__(self, path): @@ -88,3 +85,5 @@ def get(self, _id): with self.__output.open() as f: f.write(render) + if not render[-1] == "\n": + f.write("\n") diff --git a/src/shacl2code/lang/jinja.py b/src/shacl2code/lang/jinja.py index 6396d4f..2906a21 100644 --- a/src/shacl2code/lang/jinja.py +++ b/src/shacl2code/lang/jinja.py @@ -6,7 +6,7 @@ from pathlib import Path from .common import BasicJinjaRender -from .lang import language, TEMPLATE_DIR +from .lang import language @language("jinja") diff --git a/src/shacl2code/lang/templates/python.j2 b/src/shacl2code/lang/templates/python.j2 index d9c6b7a..a2e2f7b 100644 --- a/src/shacl2code/lang/templates/python.j2 +++ b/src/shacl2code/lang/templates/python.j2 @@ -89,7 +89,7 @@ class StringProp(Property): def set(self, value): return str(value) - def set(self, value): + def get(self, value): return str(value) def validate(self, value): @@ -538,7 +538,7 @@ class SHACLObject(object): @classmethod def deserialize(cls, data, *, object_ids=None, context=None): for t in ("@type", compact("@type")): - if not t in data: + if t not in data: continue typ = data[t] @@ -743,7 +743,7 @@ def read_jsonld(f): """ data = json.load(f) object_ids = {} - if not "@graph" in data: + if "@graph" not in data: objects = [SHACLObject.deserialize(data, object_ids)] else: objects = [SHACLObject.deserialize(o, object_ids) for o in data["@graph"]] @@ -825,6 +825,7 @@ CONTEXT = { {%- endfor %} } + # ENUMERATIONS {%- for enum in enums %} {%- if enum.comment %} @@ -849,7 +850,6 @@ class {{ enum.clsname }}(EnumProp): {%- endfor %} {% endfor %} - # CLASSES {%- for class in classes %} {%- if class.comment %} @@ -903,6 +903,7 @@ class {{ class.clsname }}( {%- endfor %} self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["{{ class._id }}"] = {{ class.clsname }} {% endfor %} diff --git a/src/shacl2code/model.py b/src/shacl2code/model.py index ce49921..332df6e 100644 --- a/src/shacl2code/model.py +++ b/src/shacl2code/model.py @@ -7,8 +7,7 @@ import keyword import re import typing -from pathlib import Path -from dataclasses import dataclass, field +from dataclasses import dataclass from pyld import jsonld @@ -42,7 +41,7 @@ def __expand(self, _id): if not ctx: return _id - if not ":" in _id: + if ":" not in _id: if _id in ctx: if isinstance(ctx[_id], dict): return self.__expand(ctx[_id]["@id"]) @@ -278,7 +277,6 @@ def __init__(self, model_data, context=None): tmp_classes = self.classes done_ids = set() - seen_ids = set() self.classes = [] while tmp_classes: diff --git a/tests/expect/jsonschema/spdx3.json b/tests/expect/jsonschema/spdx3.json index a370b1a..3af0694 100644 --- a/tests/expect/jsonschema/spdx3.json +++ b/tests/expect/jsonschema/spdx3.json @@ -2580,4 +2580,4 @@ "type": "string" } } -} \ No newline at end of file +} diff --git a/tests/expect/python/spdx3.py b/tests/expect/python/spdx3.py index fb36a25..cd47843 100644 --- a/tests/expect/python/spdx3.py +++ b/tests/expect/python/spdx3.py @@ -89,7 +89,7 @@ class StringProp(Property): def set(self, value): return str(value) - def set(self, value): + def get(self, value): return str(value) def validate(self, value): @@ -538,7 +538,7 @@ def to_jsonld(self, f, *args, **kwargs): @classmethod def deserialize(cls, data, *, object_ids=None, context=None): for t in ("@type", compact("@type")): - if not t in data: + if t not in data: continue typ = data[t] @@ -741,7 +741,7 @@ def read_jsonld(f): """ data = json.load(f) object_ids = {} - if not "@graph" in data: + if "@graph" not in data: objects = [SHACLObject.deserialize(data, object_ids)] else: objects = [SHACLObject.deserialize(o, object_ids) for o in data["@graph"]] @@ -803,6 +803,7 @@ def callback(value, path): CONTEXT = { } + # ENUMERATIONS # Lists the different safety risk type values that can be used to describe the safety risk of AI software # according to [Article 20 of Regulation 765/2008/EC](https://ec.europa.eu/docsroom/documents/17107/attachments/1/translations/en/renditions/pdf). @@ -1437,7 +1438,6 @@ class software_SoftwarePurpose(EnumProp): test = "https://spdx.org/rdf/v3/Software/SoftwarePurpose/test" - # CLASSES # The CreationInfo provides information about who created the Element, and when and how it was created. # @@ -1495,6 +1495,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/CreationInfo"] = core_CreationInfo @@ -1521,6 +1522,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/DictionaryEntry"] = core_DictionaryEntry @@ -1600,6 +1602,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Element"] = core_Element @@ -1644,6 +1647,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/ElementCollection"] = core_ElementCollection @@ -1691,6 +1695,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/ExternalIdentifier"] = core_ExternalIdentifier @@ -1730,6 +1735,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/ExternalMap"] = core_ExternalMap @@ -1767,6 +1773,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/ExternalRef"] = core_ExternalRef @@ -1788,6 +1795,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/IntegrityMethod"] = core_IntegrityMethod @@ -1827,6 +1835,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/NamespaceMap"] = core_NamespaceMap @@ -1853,6 +1862,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/PositiveIntegerRange"] = core_PositiveIntegerRange @@ -1906,6 +1916,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Relationship"] = core_Relationship @@ -1964,6 +1975,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/SpdxDocument"] = core_SpdxDocument @@ -1975,6 +1987,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Tool"] = core_Tool @@ -2073,6 +2086,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/LicenseAddition"] = expandedlicensing_LicenseAddition @@ -2103,6 +2117,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/ListedLicenseException"] = expandedlicensing_ListedLicenseException @@ -2148,6 +2163,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VulnAssessmentRelationship"] = security_VulnAssessmentRelationship @@ -2164,6 +2180,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/SimpleLicensing/AnyLicenseInfo"] = simplelicensing_AnyLicenseInfo @@ -2203,6 +2220,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/SimpleLicensing/LicenseExpression"] = simplelicensing_LicenseExpression @@ -2227,6 +2245,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/SimpleLicensing/SimpleLicensingText"] = simplelicensing_SimpleLicensingText @@ -2317,6 +2336,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Build/Build"] = build_Build @@ -2328,6 +2348,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Agent"] = core_Agent @@ -2365,6 +2386,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Annotation"] = core_Annotation @@ -2414,6 +2436,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Artifact"] = core_Artifact @@ -2432,6 +2455,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Bundle"] = core_Bundle @@ -2462,6 +2486,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Hash"] = core_Hash @@ -2479,6 +2504,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/LifecycleScopedRelationship"] = core_LifecycleScopedRelationship @@ -2490,6 +2516,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Organization"] = core_Organization @@ -2501,6 +2528,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Person"] = core_Person @@ -2512,6 +2540,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/SoftwareAgent"] = core_SoftwareAgent @@ -2542,6 +2571,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/ConjunctiveLicenseSet"] = expandedlicensing_ConjunctiveLicenseSet @@ -2558,6 +2588,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/CustomLicenseAddition"] = expandedlicensing_CustomLicenseAddition @@ -2585,6 +2616,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/DisjunctiveLicenseSet"] = expandedlicensing_DisjunctiveLicenseSet @@ -2596,6 +2628,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/ExtendableLicense"] = expandedlicensing_ExtendableLicense @@ -2728,6 +2761,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/License"] = expandedlicensing_License @@ -2756,6 +2790,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/ListedLicense"] = expandedlicensing_ListedLicense @@ -2784,6 +2819,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/OrLaterOperator"] = expandedlicensing_OrLaterOperator @@ -2815,6 +2851,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/WithAdditionOperator"] = expandedlicensing_WithAdditionOperator @@ -2891,6 +2928,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/CvssV2VulnAssessmentRelationship"] = security_CvssV2VulnAssessmentRelationship @@ -2978,6 +3016,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/CvssV3VulnAssessmentRelationship"] = security_CvssV3VulnAssessmentRelationship @@ -3063,6 +3102,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/CvssV4VulnAssessmentRelationship"] = security_CvssV4VulnAssessmentRelationship @@ -3117,6 +3157,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/EpssVulnAssessmentRelationship"] = security_EpssVulnAssessmentRelationship @@ -3173,6 +3214,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/ExploitCatalogVulnAssessmentRelationship"] = security_ExploitCatalogVulnAssessmentRelationship @@ -3214,6 +3256,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/SsvcVulnAssessmentRelationship"] = security_SsvcVulnAssessmentRelationship @@ -3257,6 +3300,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VexVulnAssessmentRelationship"] = security_VexVulnAssessmentRelationship @@ -3361,6 +3405,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/Vulnerability"] = security_Vulnerability @@ -3444,6 +3489,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Software/SoftwareArtifact"] = software_SoftwareArtifact @@ -3459,6 +3505,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Core/Bom"] = core_Bom @@ -3472,6 +3519,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/ExpandedLicensing/CustomLicense"] = expandedlicensing_CustomLicense @@ -3526,6 +3574,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VexAffectedVulnAssessmentRelationship"] = security_VexAffectedVulnAssessmentRelationship @@ -3564,6 +3613,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VexFixedVulnAssessmentRelationship"] = security_VexFixedVulnAssessmentRelationship @@ -3634,6 +3684,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VexNotAffectedVulnAssessmentRelationship"] = security_VexNotAffectedVulnAssessmentRelationship @@ -3672,6 +3723,7 @@ def __init__(self, **kwargs): super().__init__() self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Security/VexUnderInvestigationVulnAssessmentRelationship"] = security_VexUnderInvestigationVulnAssessmentRelationship @@ -3692,6 +3744,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Software/File"] = software_File @@ -3765,6 +3818,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Software/Package"] = software_Package @@ -3787,6 +3841,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Software/Sbom"] = software_Sbom @@ -3825,6 +3880,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Software/Snippet"] = software_Snippet @@ -3954,6 +4010,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/AI/AIPackage"] = ai_AIPackage @@ -4063,6 +4120,7 @@ def __init__(self, **kwargs): ) self._set_init_props(**kwargs) + SHACLObject.DESERIALIZERS["https://spdx.org/rdf/v3/Dataset/Dataset"] = dataset_Dataset @@ -4097,4 +4155,4 @@ def main(): if __name__ == "__main__": import sys - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/tests/expect/raw/spdx3.txt b/tests/expect/raw/spdx3.txt index d5861cb..a7583d5 100644 --- a/tests/expect/raw/spdx3.txt +++ b/tests/expect/raw/spdx3.txt @@ -76,4 +76,4 @@ Class(_id='https://spdx.org/rdf/v3/Software/Package', clsname='software_Package' Class(_id='https://spdx.org/rdf/v3/Software/Sbom', clsname='software_Sbom', parent_ids=['https://spdx.org/rdf/v3/Core/Bom'], properties=[Property(path='https://spdx.org/rdf/v3/Software/sbomType', varname='sbomType', comment='This field is a reasonable estimation of the type of SBOM created from a creator perspective.\nIt is intended to be used to give guidance on the elements that may be contained within it.\nAligning with the guidance produced in [Types of Software Bill of Material (SBOM) Documents](https://www.cisa.gov/sites/default/files/2023-04/sbom-types-document-508c.pdf).', max_count=None, min_count=None, enum_id='https://spdx.org/rdf/v3/Software/SbomType', class_id='', datatype='')], comment='A Software Bill of Materials (SBOM) is a collection of SPDX Elements describing a single package.\nThis could include details of the content and composition of the product,\nprovenance details of the product and/or\nits composition, licensing information, known quality or security issues, etc.') Class(_id='https://spdx.org/rdf/v3/Software/Snippet', clsname='software_Snippet', parent_ids=['https://spdx.org/rdf/v3/Software/SoftwareArtifact'], properties=[Property(path='https://spdx.org/rdf/v3/Software/byteRange', varname='byteRange', comment='This field defines the byte range in the original host file that the snippet information applies to.\nA range of bytes is independent of various formatting concerns, and the most accurate way \nof referring to the differences. The choice was made to start the numbering of \nthe byte range at 1 to be consistent with the W3C pointer method vocabulary.', max_count=1, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/PositiveIntegerRange', datatype=''), Property(path='https://spdx.org/rdf/v3/Software/lineRange', varname='lineRange', comment='This field defines the line range in the original host file that the snippet information applies to.\nIf there is a disagreement between the byte range and line range, the byte range values will take precedence.\nA range of lines is a convenient reference for those files where there is a known line delimiter. \nThe choice was made to start the numbering of the lines at 1 to be consistent with the W3C pointer method vocabulary.', max_count=1, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/PositiveIntegerRange', datatype=''), Property(path='https://spdx.org/rdf/v3/Software/snippetFromFile', varname='snippetFromFile', comment='The field identifies the file which contains the snippet.', max_count=1, min_count=1, enum_id='', class_id='https://spdx.org/rdf/v3/Software/File', datatype='')], comment='A Snippet describes a certain part of a file and can be used when the file is known to have some content\nthat has been included from another original source. Snippets are useful for denoting when part of a file\nmay have been originally created under another license or copied from a place with a known vulnerability.') Class(_id='https://spdx.org/rdf/v3/AI/AIPackage', clsname='ai_AIPackage', parent_ids=['https://spdx.org/rdf/v3/Software/Package'], properties=[Property(path='https://spdx.org/rdf/v3/AI/energyConsumption', varname='energyConsumption', comment='EnergyConsumption captures the amount of energy needed to train and operate the AI model. \nThis value is also known as training energy consumption or inference energy consumption.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/standardCompliance', varname='standardCompliance', comment='StandardCompliance captures a standard that the AI software complies with. \nThis includes both published and unpublished standards, for example ISO, IEEE, ETSI etc. \nThe standard could (but not necessarily have to) be used to satisfy a legal or regulatory requirement.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/limitation', varname='limitation', comment='Limitation captures a limitation of the AI Package (or of the AI models present in the AI package),\nexpressed as free form text. Note that this is not guaranteed to be exhaustive.\nFor instance, a limitation might be that the AI package cannot be used on datasets from a certain demography.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/typeOfModel', varname='typeOfModel', comment='TypeOfModel records the type of the AI model(s) used in the software. \nFor instance, if it is a supervised model, unsupervised model, reinforcement learning model or a combination of those.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/informationAboutTraining', varname='informationAboutTraining', comment='InformationAboutTraining describes the specific steps involved in the training of the AI model.\nFor example, it can be specified whether supervised fine-tuning \nor active learning is used as part of training the model.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/informationAboutApplication', varname='informationAboutApplication', comment='InformationAboutApplication describes any relevant information in free form text about \nhow the AI model is used inside the software, as well as any relevant pre-processing steps, third party APIs etc.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/hyperparameter', varname='hyperparameter', comment='This field records a hyperparameter value.\nHyperparameters are parameters of the machine learning model that are used to control the learning process,\nfor example the optimization and learning rate used during the training of the model.', max_count=None, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/DictionaryEntry', datatype=''), Property(path='https://spdx.org/rdf/v3/AI/modelDataPreprocessing', varname='modelDataPreprocessing', comment='ModelDataPreprocessing is a free form text that describes the preprocessing steps\napplied to the training data before training of the model(s) contained in the AI software.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/modelExplainability', varname='modelExplainability', comment='ModelExplainability is a free form text that lists the different explainability mechanisms\n(such as SHAP, or other model specific explainability mechanisms) that can be used to explain the model.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/sensitivePersonalInformation', varname='sensitivePersonalInformation', comment="SensitivePersonalInformation notes if sensitive personal information\nis used in the training or inference of the AI models.\nThis might include biometric data, addresses or other data that can be used to infer a person's identity.", max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Core/PresenceType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/AI/metricDecisionThreshold', varname='metricDecisionThreshold', comment='Each metric might be computed based on a decision threshold. \nFor instance, precision or recall is typically computed by checking\nif the probability of the outcome is larger than 0.5.\nEach decision threshold should match with a metric field defined in the AI Package.', max_count=None, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/DictionaryEntry', datatype=''), Property(path='https://spdx.org/rdf/v3/AI/metric', varname='metric', comment='Metric records the measurement with which the AI model was evaluated. \nThis makes statements about the prediction quality including uncertainty,\naccuracy, characteristics of the tested population, quality, fairness, explainability, robustness etc.', max_count=None, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/DictionaryEntry', datatype=''), Property(path='https://spdx.org/rdf/v3/AI/domain', varname='domain', comment='Domain describes the domain in which the AI model contained in the AI software\ncan be expected to operate successfully. Examples include computer vision, natural language etc.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/AI/autonomyType', varname='autonomyType', comment='AutonomyType indicates if a human is involved in any of the decisions of the AI software\nor if that software is fully automatic.', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Core/PresenceType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/AI/safetyRiskAssessment', varname='safetyRiskAssessment', comment='SafetyRiskAssessment categorizes the safety risk impact of the AI software\nin accordance with Article 20 of [EC Regulation No 765/2008](https://ec.europa.eu/docsroom/documents/17107/attachments/1/translations/en/renditions/pdf).', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/AI/SafetyRiskAssessmentType', class_id='', datatype='')], comment='Metadata information that can be added to a package to describe an AI application or trained AI model.\nExternal property restriction on /Core/Artifact/suppliedBy: minCount: 1\nExternal property restriction on /Software/Package/downloadLocation: minCount: 1\nExternal property restriction on /Software/Package/packageVersion: minCount: 1\nExternal property restriction on /Software/SoftwareArtifact/primaryPurpose: minCount: 1\nExternal property restriction on /Core/Artifact/releaseTime: minCount: 1') -Class(_id='https://spdx.org/rdf/v3/Dataset/Dataset', clsname='dataset_Dataset', parent_ids=['https://spdx.org/rdf/v3/Software/Package'], properties=[Property(path='https://spdx.org/rdf/v3/Dataset/datasetType', varname='datasetType', comment='Type describes the datatype contained in the dataset. For example a dataset can be an image dataset for computer vision applications, a text dataset such as the contents of a book or Wikipedia article, or sometimes a multimodal dataset that contains multiple types of data.', max_count=None, min_count=1, enum_id='https://spdx.org/rdf/v3/Dataset/DatasetType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/dataCollectionProcess', varname='dataCollectionProcess', comment='DataCollectionProcess describes how a dataset was collected.\nExamples include the sources from which a dataset was scrapped or\nthe interview protocol that was used for data collection.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/intendedUse', varname='intendedUse', comment='IntendedUse describes what the given dataset should be used for.\nSome datasets are collected to be used only for particular purposes. \nFor example, medical data collected from a specific demography might only be applicable\nfor training machine learning models to make predictions for that demography.\nIn such a case, the intendedUse field would capture this information.\nSimilarly, if a dataset is collected for building a facial recognition model,\nthe intendedUse field would specify that.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetSize', varname='datasetSize', comment='DatasetSize Captures how large a dataset is.\nThe size is to be measured in bytes.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#nonNegativeInteger'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetNoise', varname='datasetNoise', comment='DatasetNoise describes what kinds of noises a dataset might encompass.\nThe field uses free form text to specify the fields or the samples that might be noisy.\nAlternatively, it can also be used to describe various noises that could impact the whole dataset.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/dataPreprocessing', varname='dataPreprocessing', comment='DataPreprocessing describes the various preprocessing steps\nthat were applied to the raw data to create the dataset.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/sensor', varname='sensor', comment='Sensor describes a sensor that was used for collecting the data\nand its calibration value as a key-value pair.', max_count=None, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/DictionaryEntry', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/knownBias', varname='knownBias', comment='KnownBias is a free form text field that describes the different biases that the dataset encompasses.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/sensitivePersonalInformation', varname='sensitivePersonalInformation', comment="SensitivePersonalInformation indicates the presence of sensitive personal data\nor information that allows drawing conclusions about a person's identity.", max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Core/PresenceType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/anonymizationMethodUsed', varname='anonymizationMethodUsed', comment='AnonymizationMethodUsed describes the methods used to anonymize the dataset (of fields in the dataset).', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/confidentialityLevel', varname='confidentialityLevel', comment='ConfidentialityLevel describes the levels of confidentiality of the data points contained in the dataset.', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Dataset/ConfidentialityLevelType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/datasetUpdateMechanism', varname='datasetUpdateMechanism', comment='DatasetUpdateMechanism describes a mechanism to update the dataset.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetAvailability', varname='datasetAvailability', comment='Some datasets are publicly available and can be downloaded directly. Others are only accessible behind a clickthrough, or after filling a registration form. This field will describe the dataset availability from that perspective.', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Dataset/DatasetAvailabilityType', class_id='', datatype='')], comment='Metadata information that can be added to a dataset that may be used in a software or to train/test an AI package.\nExternal property restriction on /Core/Artifact/originatedBy: minCount: 1\nExternal property restriction on /Software/Package/downloadLocation: minCount: 1\nExternal property restriction on /Software/SoftwareArtifact/primaryPurpose: minCount: 1\nExternal property restriction on /Core/Artifact/releaseTime: minCount: 1\nExternal property restriction on /Core/Artifact/builtTime: minCount: 1') \ No newline at end of file +Class(_id='https://spdx.org/rdf/v3/Dataset/Dataset', clsname='dataset_Dataset', parent_ids=['https://spdx.org/rdf/v3/Software/Package'], properties=[Property(path='https://spdx.org/rdf/v3/Dataset/datasetType', varname='datasetType', comment='Type describes the datatype contained in the dataset. For example a dataset can be an image dataset for computer vision applications, a text dataset such as the contents of a book or Wikipedia article, or sometimes a multimodal dataset that contains multiple types of data.', max_count=None, min_count=1, enum_id='https://spdx.org/rdf/v3/Dataset/DatasetType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/dataCollectionProcess', varname='dataCollectionProcess', comment='DataCollectionProcess describes how a dataset was collected.\nExamples include the sources from which a dataset was scrapped or\nthe interview protocol that was used for data collection.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/intendedUse', varname='intendedUse', comment='IntendedUse describes what the given dataset should be used for.\nSome datasets are collected to be used only for particular purposes. \nFor example, medical data collected from a specific demography might only be applicable\nfor training machine learning models to make predictions for that demography.\nIn such a case, the intendedUse field would capture this information.\nSimilarly, if a dataset is collected for building a facial recognition model,\nthe intendedUse field would specify that.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetSize', varname='datasetSize', comment='DatasetSize Captures how large a dataset is.\nThe size is to be measured in bytes.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#nonNegativeInteger'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetNoise', varname='datasetNoise', comment='DatasetNoise describes what kinds of noises a dataset might encompass.\nThe field uses free form text to specify the fields or the samples that might be noisy.\nAlternatively, it can also be used to describe various noises that could impact the whole dataset.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/dataPreprocessing', varname='dataPreprocessing', comment='DataPreprocessing describes the various preprocessing steps\nthat were applied to the raw data to create the dataset.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/sensor', varname='sensor', comment='Sensor describes a sensor that was used for collecting the data\nand its calibration value as a key-value pair.', max_count=None, min_count=None, enum_id='', class_id='https://spdx.org/rdf/v3/Core/DictionaryEntry', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/knownBias', varname='knownBias', comment='KnownBias is a free form text field that describes the different biases that the dataset encompasses.', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/sensitivePersonalInformation', varname='sensitivePersonalInformation', comment="SensitivePersonalInformation indicates the presence of sensitive personal data\nor information that allows drawing conclusions about a person's identity.", max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Core/PresenceType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/anonymizationMethodUsed', varname='anonymizationMethodUsed', comment='AnonymizationMethodUsed describes the methods used to anonymize the dataset (of fields in the dataset).', max_count=None, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/confidentialityLevel', varname='confidentialityLevel', comment='ConfidentialityLevel describes the levels of confidentiality of the data points contained in the dataset.', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Dataset/ConfidentialityLevelType', class_id='', datatype=''), Property(path='https://spdx.org/rdf/v3/Dataset/datasetUpdateMechanism', varname='datasetUpdateMechanism', comment='DatasetUpdateMechanism describes a mechanism to update the dataset.', max_count=1, min_count=None, enum_id='', class_id='', datatype='http://www.w3.org/2001/XMLSchema#string'), Property(path='https://spdx.org/rdf/v3/Dataset/datasetAvailability', varname='datasetAvailability', comment='Some datasets are publicly available and can be downloaded directly. Others are only accessible behind a clickthrough, or after filling a registration form. This field will describe the dataset availability from that perspective.', max_count=1, min_count=None, enum_id='https://spdx.org/rdf/v3/Dataset/DatasetAvailabilityType', class_id='', datatype='')], comment='Metadata information that can be added to a dataset that may be used in a software or to train/test an AI package.\nExternal property restriction on /Core/Artifact/originatedBy: minCount: 1\nExternal property restriction on /Software/Package/downloadLocation: minCount: 1\nExternal property restriction on /Software/SoftwareArtifact/primaryPurpose: minCount: 1\nExternal property restriction on /Core/Artifact/releaseTime: minCount: 1\nExternal property restriction on /Core/Artifact/builtTime: minCount: 1') diff --git a/tests/test_jsonschema.py b/tests/test_jsonschema.py index d6d0085..722adef 100644 --- a/tests/test_jsonschema.py +++ b/tests/test_jsonschema.py @@ -5,7 +5,6 @@ import re import subprocess -import sys import json from pathlib import Path diff --git a/tests/test_model_source.py b/tests/test_model_source.py index 485443f..2fecb66 100644 --- a/tests/test_model_source.py +++ b/tests/test_model_source.py @@ -4,10 +4,8 @@ # SPDX-License-Identifier: MIT import os -import re import shutil import subprocess -import sys from pathlib import Path @@ -29,7 +27,7 @@ def test_generation_file(tmpdir): Tests that shacl2code generates output to a file when requested """ outfile = tmpdir.join("spdx3.txt") - p = subprocess.run( + subprocess.run( [ "shacl2code", "generate",