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

[Issue 359] Add Json writer for new data model #379

Merged
merged 55 commits into from
Jan 3, 2023

Conversation

nicoweidner
Copy link
Collaborator

Fixes #359

Signed-off-by: Nicolaus Weidner nicolaus.weidner@tngtech.com

@nicoweidner nicoweidner force-pushed the issue-359 branch 3 times, most recently from e68d842 to 9045c5b Compare December 21, 2022 22:28
Copy link
Collaborator

@meretp meretp left a comment

Choose a reason for hiding this comment

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

Overall I think it's a nice structure for the writer- eventhough I have to admit that I needed some time to get the bigger picture and to understand the functionality of the convertor and the role of the properties. Here are some comments from a first look.

src/datetime_conversions.py Outdated Show resolved Hide resolved
tests/writer/json/test_json_writer.py Outdated Show resolved Hide resolved
tests/writer/__init__.py Outdated Show resolved Hide resolved
tests/test_datetime_conversions.py Outdated Show resolved Hide resolved
tests/test_datetime_conversions.py Outdated Show resolved Hide resolved
src/jsonschema/document_properties.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Very thorough implementation that takes a while to get used to but seems very OK :)

src/datetime_conversions.py Outdated Show resolved Hide resolved
src/jsonschema/document_converter.py Outdated Show resolved Hide resolved
src/jsonschema/converter.py Show resolved Hide resolved
src/jsonschema/relationship_filters.py Outdated Show resolved Hide resolved
src/jsonschema/optional_utils.py Outdated Show resolved Hide resolved
element_ids = [file.spdx_id for file in document.files]
element_ids.extend([package.spdx_id for package in document.packages])
element_ids.extend([snippet.spdx_id for snippet in document.snippets])
document_annotations = filter(lambda annotation: annotation.spdx_id not in element_ids,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will add annotations with external spdx_ids to the document.

I don't know how to properly write them out, though, as json does not support annotations with SPDX id references. Should we just discard them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, good question. Dropping them feels bad. But I don't see any solution that avoids losing information.

@goneall : The situation is that a SPDX document contains an annotation, where the annotated element is an external element. Where should the annotation go in the serialized json? The json schema puts annotations directly on the annotated element. This works fine for packages, files, snippets and the document itself, but there is no place for annotations targeting external elements.

tests/jsonschema/test_external_document_ref_converter.py Outdated Show resolved Hide resolved
tests/fixtures.py Show resolved Hide resolved
src/writer/json/json_writer.py Outdated Show resolved Hide resolved
def algorithm_to_json_string(algorithm: ChecksumAlgorithm) -> str:
name_with_dash: str = algorithm.name.replace("_", "-")
if "BLAKE2B" in name_with_dash:
return name_with_dash.replace("BLAKE2B", "BLAKE2b")
return name_with_dash
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is needed in the tag-value writer, too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But that isn't merged yet, right? Then once this PR is merged, the other one can be rebased and can extract it

@armintaenzertng
Copy link
Collaborator

I discussed with @maxhbr that we want users to only write valid documents per default. This means that a validation step should be included in the writers that has to be explicitly toggled off if the user does not want that.

@nicoweidner
Copy link
Collaborator Author

I discussed with @maxhbr that we want users to only write valid documents per default. This means that a validation step should be included in the writers that has to be explicitly toggled off if the user does not want that.

There is now a validate parameter which defaults to True

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…rties

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…n separate converters), refactor document_properties.py to include all document properties instead of just top-level ones

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
tests/writer/json/test_json_writer.py Show resolved Hide resolved
tests/jsonschema/__init__.py Outdated Show resolved Hide resolved
src/jsonschema/converter.py Show resolved Hide resolved
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
… for (upcoming) more complex conversion cases

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
… any additional properties

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…nverter

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…rter

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…erter

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…sabling it

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…a document

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
…validator.py

Signed-off-by: Nicolaus Weidner <nicolaus.weidner@tngtech.com>
Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Thank you very much, looks very good now :)

@armintaenzertng armintaenzertng merged commit 48c4e72 into spdx:refactor-python-tools Jan 3, 2023
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.

3 participants