8000 Issue 456 add rdf parser by meretp · Pull Request #469 · spdx/tools-python · GitHub
[go: up one dir, main page]

Skip to content

Issue 456 add rdf parser #469

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

Merged
merged 43 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
18e7063
delete rdflib as optional dependency as it is required
meretp Feb 1, 2023
cf5ee6a
delete installation from rdflib as the package is a required dependency
meretp Feb 1, 2023
298255e
move helper methods to also use it for the rdf parser
meretp Feb 9, 2023
9729b96
move actor_parser.py as it is format-agnostic and will be used for js…
meretp Feb 1, 2023
96498c0
[issue-456] add creation_info parser
meretp Jan 31, 2023
024fa89
[issue-456] add graph parsing functions
meretp Feb 1, 2023
b1a47f9
[issue-456] add snippet parser
meretp Feb 1, 2023
8466d2e
[issue-456] add checksum parser
meretp Feb 2, 2023
6d1e93e
[issue-456] add external document ref parser
meretp Feb 2, 2023
7087e36
[issue-456] add file parser
meretp Feb 2, 2023
1eb803b
[issue-456] add annotation parser
meretp Feb 2, 2023
6c8fdee
[issue-456] add package parser
meretp Feb 2, 2023
625e2a9
[issue-456] add package verification code parser
meretp Feb 8, 2023
198f2a6
[issue-456] add helper method in casing_tools and move the module as …
meretp Feb 8, 2023
b3e274b
[issue-456] add parser for ExternalPackageRefs
meretp Feb 8, 2023
cea02ae
[issue-456] use enum helper method for primary package purpose
meretp Feb 8, 2023
d0238be
[issue-456] use enum helper method for annotation type
meretp Feb 8, 2023
fb105dc
[issue-456] use helper method for checksum algorithm
meretp Feb 8, 2023
58783f9
[issue-456] add relationship parser
meretp Feb 8, 2023
da33b14
[issue-456] use NamespaceManager to translate external document names…
meretp Feb 9, 2023
69d16aa
[issue-456] add extracted licensing info parser
meretp Feb 9, 2023
6652e4f
[issue-456] allow no assertion in package download location
meretp Feb 8, 2023
ce17ca6
[issue-456, refactor] extract method to get a unique value, sort methods
meretp Feb 9, 2023
9737fde
[issue-456, refactor] replace str_or_no_assertion_or_none with parse …
meretp Feb 9, 2023
9df9980
[issue-456] add license expression parser
meretp Feb 9, 2023
7b61c8f
[issue-456, refactor]
meretp Feb 9, 2023
9ecc373
[issue-456] parse list of license expressions
meretp Feb 9, 2023
1b8cf82
[issue-456] also parse URIRefs with the documents namespace as prefix…
meretp Feb 9, 2023
432a39f
[issue-456] add rdf parser to cli tool
meretp Feb 9, 2023
7a27e88
[issue-456] delete RDFExample from specVersion 2.1 as the tool curren…
meretp Feb 9, 2023
03ee53c
[issue-456, refactor] use generic helper methods instead of individua…
meretp Feb 9, 2023
446757c
[issue-456] move actor_parser.py as it is format-agnostic and used fo…
meretp Feb 9, 2023
86bc68c
[issue-456, refactor] adapt type hints, delete unused imports, rename…
meretp Feb 9, 2023
47e7db0
[issue-456] add helper method to remove prefix to support Python 3.7 …
meretp Feb 9, 2023
9681339
[issue-456] allow multiple members in ConjunctiveLicenseSet and Disju…
meretp Feb 10, 2023
8f9259b
[issue-456] strip parsed values by default to prevent new lines and l…
meretp Feb 10, 2023
9eb1206
[issue-456] fix parsing of externalPackageRef
meretp Feb 10, 2023
4ec5b3c
fix helper method
meretp Feb 15, 2023
c4d04d4
[review] use helper method for enums also for FileType
meretp Feb 20, 2023
c787280
[review, refactor] strip copyright texts, delete trailing comma
meretp Feb 20, 2023
6b70dda
[review] rewrite parse_ranges
meretp Feb 20, 2023
1d728b7
[review, refactor] let Constructor handle None values and use the mor…
meretp Feb 20, 2023
1cbe629
[review] refactor helper methods
meretp Feb 20, 2023
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
Prev Previous commit
Next Next commit
[issue-456] add helper method in casing_tools and move the module as …
…it is used in the parser and writer layer

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Feb 22, 2023
commit 198f2a61b13bc02c2d8b6127593a3d4e0828cb3b
5 changes: 5 additions & 0 deletions src/spdx/writer/casing_tools.py → src/spdx/casing_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
def snake_case_to_camel_case(snake_case_string: str) -> str:
each_word_capitalized = sub(r"[_\-]+", " ", snake_case_string).title().replace(" ", "")
return each_word_capitalized[0].lower() + each_word_capitalized[1:]


def camel_case_to_snake_case(camel_case_string: str) -> str:
snake_case_string = sub("(?!^)([A-Z]+)", r"_\1", camel_case_string).lower()
return snake_case_string
2 changes: 1 addition & 1 deletion src/spdx/jsonschema/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from spdx.jsonschema.json_property import JsonProperty
from spdx.model.document import Document
from spdx.writer.casing_tools import snake_case_to_camel_case
from spdx.casing_tools import snake_case_to_camel_case

MISSING_IMPLEMENTATION_MESSAGE = "Must be implemented"

Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/rdf/annotation_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from spdx.datetime_conversions import datetime_to_iso_string
from spdx.model.annotation import Annotation
from spdx.writer.casing_tools import snake_case_to_camel_case
from spdx.casing_tools import snake_case_to_camel_case
from spdx.writer.rdf.writer_utils import add_namespace_to_spdx_id
from spdx.rdfschema.namespace import SPDX_NAMESPACE

Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/rdf/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rdflib import Graph, URIRef, Literal, RDF, RDFS

from spdx.model.file import File
from spdx.writer.casing_tools import snake_case_to_camel_case
from spdx.casing_tools import snake_case_to_camel_case
from spdx.writer.rdf.checksum_writer import add_checksum_to_graph
from spdx.writer.rdf.license_expression_writer import add_license_expression_or_none_or_no_assertion
from spdx.writer.rdf.writer_utils import add_optional_literal, add_namespace_to_spdx_id
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/rdf/package_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rdflib import Graph, URIRef, RDF, Literal, XSD, BNode, DOAP, RDFS
from spdx.writer.rdf.license_expression_writer import add_license_expression_or_none_or_no_assertion

from spdx.writer.casing_tools import snake_case_to_camel_case
from spdx.casing_tools import snake_case_to_camel_case
from spdx.writer.rdf.checksum_writer import add_checksum_to_graph

from spdx.model.package import Package, PackageVerificationCode, ExternalPackageRef, \
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/rdf/relationship_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from spdx.model.relationship import Relationship
from spdx.model.spdx_no_assertion import SpdxNoAssertion
from spdx.model.spdx_none import SpdxNone
from spdx.writer.casing_tools import snake_case_to_camel_case
from spdx.casing_tools import snake_case_to_camel_case
from spdx.writer.rdf.writer_utils import add_namespace_to_spdx_id
from spdx.rdfschema.namespace import SPDX_NAMESPACE

Expand Down
29 changes: 29 additions & 0 deletions tests/spdx/test_casing_tools.py
6D40
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2023 spdx contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

from spdx.casing_tools import snake_case_to_camel_case, camel_case_to_snake_case


@pytest.mark.parametrize("snake_case_str,camel_case_str", [("snake_case", "snakeCase")])
def test_snake_case_to_camel_case(snake_case_str, camel_case_str):
camel_case = snake_case_to_camel_case(snake_case_str)

assert camel_case == camel_case_str


@pytest.mark.parametrize("camel_case_str,snake_case_str",
[("camelCase", "camel_case"), ("camelCaseMore", "camel_case_more"),
("CamelCase", "camel_case")])
def test_camel_case_to_snake_case(camel_case_str, snake_case_str):
snake_case = camel_case_to_snake_case(camel_case_str)

assert snake_case == snake_case_str
0