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

split read/write schema validation #697

Merged
merged 5 commits into from
Feb 10, 2022

Conversation

marscher
Copy link
Contributor

@marscher marscher commented Feb 7, 2022

Changes

WeldxFile now supports two custom_schema sub-arguments. The first argument will be used upon reading, the second upon writing. That way we can use separate schema for both operations. It turned out, that this is useful during schema development.

Related Issues

Closes #690

Checks

  • updated CHANGELOG.rst
  • updated tests
  • updated doc/
  • update example/tutorial notebooks
  • update manifest file

@marscher marscher added ASDF everything ASDF related (python + schemas) file weldx file handling (WeldxFile) labels Feb 7, 2022
@github-actions
Copy link

github-actions bot commented Feb 7, 2022

Unit Test Results

       1 files  ±0         1 suites  ±0   1m 40s ⏱️ +18s
2 108 tests +7  2 108 ✔️ +7  0 💤 ±0  0 ±0 

Results for commit 96abb03. ± Comparison against base commit ae2dff5.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Feb 7, 2022

Codecov Report

Merging #697 (96abb03) into master (ae2dff5) will decrease coverage by 0.01%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #697      +/-   ##
==========================================
- Coverage   96.08%   96.06%   -0.02%     
==========================================
  Files          92       92              
  Lines        6330     6350      +20     
==========================================
+ Hits         6082     6100      +18     
- Misses        248      250       +2     
Impacted Files Coverage Δ
weldx/asdf/file.py 96.59% <93.75%> (-0.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae2dff5...96abb03. Read the comment docs.

@marscher
Copy link
Contributor Author

marscher commented Feb 7, 2022

The sphinx warnings are due to the intersphinx mapping to Scipy is currently broken.

@marscher marscher requested a review from vhirtham February 7, 2022 17:17
Comment on lines 377 to 379
with open(fname, "w+") as fh:
fh.write(schema.format(shape=shape_s))
result[1] = fname
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for adding a testcase for this !

I think there is a way with asdf to provide a schema without saving an actual file but I am not sure if it works with our WeldxFile wrapper

Here is an example:
https://github.com/asdf-format/asdf/blob/66abc5e4599db381850dddcb293a90c4a9afd999/asdf/tests/test_schema.py#L196-L204

I will look into if we can apply this somehow in our test cases, it should make a lot of things much easier

but this solution is good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for providing the file-free version of schema validation! This looks very useful. Since WeldxFile respects outer Config contexts, I think it would be possible to use this pattern. I will try it out quickly.

Copy link
Member

Choose a reason for hiding this comment

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

I think what might be an issue is that we only look for schemas as files in our current implementation

weldx/weldx/asdf/file.py

Lines 221 to 230 in ae2dff5

if custom_schema is not None:
_custom_schema_path = pathlib.Path(custom_schema)
if not _custom_schema_path.exists():
try:
custom_schema = get_schema_path(custom_schema)
except ValueError:
raise ValueError(
f"provided custom_schema {custom_schema} " "does not exist."
)
asdffile_kwargs["custom_schema"] = custom_schema

what we might need is another 'fallback' into asdf.schema.load_schema() in the place where we 'resolve' the schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although it is a nice pattern, the custom_schema argument routing (e.g. tuple unpacking) is only possible within the wrapper. Also AsdfFile expects user schemas to be a file or URI: https://github.com/asdf-format/asdf/blob/66abc5e4599db381850dddcb293a90c4a9afd999/asdf/tests/test_schema.py#L899

Copy link
Member

Choose a reason for hiding this comment

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

So we cant use it here?

Copy link
Member

@CagtayFabry CagtayFabry left a comment

Choose a reason for hiding this comment

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

I like this solution 👍

CagtayFabry and others added 2 commits February 10, 2022 09:12
use tmp_path fixture to remove tmp dirs after test run.
remove duplicated code.
@marscher marscher merged commit 15ad366 into BAMWelDX:master Feb 10, 2022
@marscher marscher deleted the wxfile_schema_validation_timing branch February 10, 2022 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASDF everything ASDF related (python + schemas) file weldx file handling (WeldxFile)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional write modes for WeldxFile
2 participants