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

Simplify schema handling and fix several bugs #35

Merged
merged 10 commits into from
Jan 26, 2024
Merged

Conversation

Pennycook
Copy link
Contributor

This is more or less the same fix as was applied in intel/p3-analysis-library#26, but with some quirks specific to Code Base Investigator's packaging. Using the schema as written in the *.schema files uncovered a few bugs that were hidden by using preconfigured Python objects, so I fixed those too.

One thing I want to call attention to is my handling of the util.validate_coverage_json function and its replacements. I've kept it around (but deprecated it) because I don't want this refactor to be what pushes us to 2.0.0. The replacements are all declared as private functions, though, because I think 2.0.0 should be more intentional in what we expose as part of the package -- there's no reason to expose our utility functions directly.

Signed-off-by: John Pennycook <[email protected]>
Signed-off-by: John Pennycook <[email protected]>
- Loads schema files from within the package.
- Uses utility functions instead of duplicating validation code.
- Deprecates old utility functions.

Signed-off-by: John Pennycook <[email protected]>
Loading from file highlighted that we had extra commas.

Signed-off-by: John Pennycook <[email protected]>
Validating the JSON object directly (without first dumping and reloading a JSON
string) requires us to follow the schema more strictly. Previously, the call to
json.dumps() was converting tuples to lists for us.

Signed-off-by: John Pennycook <[email protected]>
codebasin/schema/compilation-database.schema Show resolved Hide resolved
codebasin/util.py Show resolved Hide resolved
@@ -141,6 +113,90 @@ def valid_path(path):
return valid


def _validate_json(json_object: str, schema_name: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is overly pedantic and doesn't matter because it's not so public facing, but this function is JSON centric but it's not actually; config.py feeds the output of a YAML file into this, so you might want to rename the function more generically to be like _validate_config, and pass a config: dict[str, Any]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see where you're coming from.

I'm hoping that we'll be able to remove the YAML configuration files completely in 2.0.0... Do you think we should rename the function for now (to reflect that it's occasionally used for JSON and YAML), but change the name back when we remove the YAML?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I decided to split the difference: see 7256a84.

We can keep the existing _validate_json function, and remove the new _validate_yaml function when we no longer need it.

setup.py Outdated Show resolved Hide resolved
Signed-off-by: John Pennycook <[email protected]>
@Pennycook Pennycook merged commit 5fd6b8f into intel:main Jan 26, 2024
1 check passed
@Pennycook Pennycook deleted the schema branch January 26, 2024 19:31
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