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

Data Source factory upgrade #20

Closed
wants to merge 36 commits into from
Closed

Conversation

CasperWA
Copy link
Collaborator

@CasperWA CasperWA commented Oct 19, 2023

DO NOT MERGE until #16 has been merged and this has been updated accordingly, since this PR branch is based on the HEAD of the #16 PR branch.

One-sentence overview

This PR does a few different things, all centered around the s7.factories.datasource_factory module.

Detailed overview

Similarly to #17 (it even cherry-picks a commit from this PR branch) it introduces testing through the pytest framework.
The tests are mainly for the create_entity() factory function (now renamed to create_datasource()) and the SOFT7 data source instance it returns.
Note, some negative-outcome tests are still missing (i.e., testing exceptions are raised correctly when expected).

A few liberties have been taken with regards to the resulting scheme of the data source instance. The s7.pydantic_models.soft module has been updated to accommodate and represent the result of these.

The point of upgrading this particular module is to implement validators and serializers (using the new features of pydantic v2) to ensure a data source instance respects the derived logic from its SOFT7 Entity. The most important logic not respected/validated was the property.shape to dimensions relation.

Summary

Essentially, the result of this PR is that at this point, the SOFT7 Data Source can be considered the archetypal SOFT7 "instance", i.e., a data structure described by a SOFT7 Entity.

PR Status

The main upgrade has been implemented.

There are still tests missing, especially for testing expected failures, but also for testing more intricate data models, e.g., properties with a multi-dimensional shape.

Finally, a restructuring of the code should be performed to more easily read the code (and the important bits like create_datasource() and _get_data()).
Especially for this last part, _get_data() still needs some upgrading according to how we intend to retrieve properties within a DataSpace. It needs flexibility and possibly "levels of laziness". In other words, currently _get_data() uses OTEAPI to retrieve and cache the data for a model locally, which is then inspected lazily when requested. I suspect the whole OTEAPI Services call workflow should be part of the lazy functionality, and not cached - but it might be desirable to indeed cache it sometimes...

  • Upgrade data source factory
  • Extend tests for intricate data models
  • Restructure data source factory module
  • Update _get_data() function (possibly in a separate PR)

@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2023

Codecov Report

Attention: Patch coverage is 73.31606% with 206 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@0238cf1). Learn more about missing BASE report.

Files Patch % Lines
s7/pydantic_models/soft7_instance.py 63.40% 71 Missing ⚠️
s7/oteapi_plugin/soft7_function.py 70.87% 60 Missing ⚠️
s7/pydantic_models/soft7_entity.py 73.00% 44 Missing ⚠️
s7/factories/datasource_factory.py 84.21% 9 Missing ⚠️
s7/factories/graph_factory.py 28.57% 5 Missing ⚠️
s7/factories/dataspace_factory.py 33.33% 4 Missing ⚠️
s7/pydantic_models/oteapi.py 80.00% 3 Missing ⚠️
s7/graph.py 66.66% 2 Missing ⚠️
s7/oteapi_plugin/models.py 93.54% 2 Missing ⚠️
s7/dataspace/database.py 0.00% 1 Missing ⚠️
... and 5 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #20   +/-   ##
=======================================
  Coverage        ?   57.84%           
=======================================
  Files           ?       20           
  Lines           ?     1051           
  Branches        ?        0           
=======================================
  Hits            ?      608           
  Misses          ?      443           
  Partials        ?        0           
Flag Coverage Δ
pytest 57.84% <73.31%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Update the DataSource factory - should be a SOFT7Instance factory
instead with proper validation of property metadata and more.
Add pytest and pytest-cov dependencies, along with a new `testing`
installable extra.
Remove tests for the now re-written SOFT7EntityPropertyType (previously
an Enum, now just a Literal collection with an associated mapping).
Also, rename create_entity() to create_datasource().

Ensure the create_datasource() function returns an instantiated model.
This can now be used in both the SOFT7DataSource model as well as the
new DataSourceDimensions model.

Add `requests-mock` dependency. Consider using "python" backend for
OTELib instead to avoid mocking requests.

Remove all filterwarnings from pytest config.
New test using python otelib backend.
Added test for serializing
All the serialization tests (including JSON Schema) must be extended to
ensure not just that it _can_ be serialized, but that the content is
also what would be expected.
Implemented as a pydantic model_serializer in "wrap" mode.

Temporarily changed the otelib dependency to point to a git branch on
GitHub that implements migration to pydantic v2.
Make the namespace an AnyUrl.
Quick (but proper) solutions to ever so slightly decrease the number of
uncovered lines.
@CasperWA CasperWA changed the title [DO NOT MERGE] Data Source factory upgrade Data Source factory upgrade Oct 27, 2023
Specifically, move all the "helper"/utility functionalities from
`datasource_factory.py` to a new `soft7_instance.py` under
pydantic_models.
Run hooks on all files, upgrading them accordingly.
Make factory functions importable from `s7.factories` as `create_*`,
where * matches the name of any `*_factory.py` file in the folder.
Split ruff hook for core code base code and non-core.
Started to flesh out an OTEAPI function strategy plugin for converting
between a parsed data source to a SOFT7 Entity instance.
Missing finalizing example in notebook.
There is a design issue here with nested entities that should be fixable
in a more elegant way
Need to fix setting ClassVar on EntityInstance and the validator for the
same.
Add a YAML parse strategy for OTEAPI.
See issue #395 in oteapi-core to follow up on when this ignore statement
can be removed.
@CasperWA
Copy link
Collaborator Author

CasperWA commented Jul 5, 2024

Closed in favor of #36

@CasperWA CasperWA closed this Jul 5, 2024
@CasperWA CasperWA deleted the cwa/soft7-instance-factory branch July 11, 2024 14:27
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