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

add support for the simulators endpoint #2066

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

abdullah-cognite
Copy link

@abdullah-cognite abdullah-cognite commented Dec 17, 2024

Description

Added the /simulators endpoint to the SDK. This is the first PR coming from the split of this big PR: https://github.com/cognitedata/cognite-sdk-python/pull/2006/files

Adds support for the following Resource:

  • Simulator resource
  • Simulator integration resource

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

simulators = cognite_client.simulators.list()
simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0
if not simulator_exists:
cognite_client.post(
Copy link
Author

Choose a reason for hiding this comment

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

We won't have a simulator.create function in the sdk

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 99.18699% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.59%. Comparing base (458fe0f) to head (1f694cc).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...gnite/client/data_classes/simulators/simulators.py 98.96% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2066      +/-   ##
==========================================
+ Coverage   90.50%   90.59%   +0.09%     
==========================================
  Files         141      145       +4     
  Lines       22533    22802     +269     
==========================================
+ Hits        20393    20657     +264     
- Misses       2140     2145       +5     
Files with missing lines Coverage Δ
cognite/client/_api/simulators/__init__.py 100.00% <100.00%> (ø)
cognite/client/_api/simulators/integrations.py 100.00% <100.00%> (ø)
cognite/client/_api_client.py 90.34% <ø> (ø)
cognite/client/_cognite_client.py 93.81% <100.00%> (+0.13%) ⬆️
cognite/client/data_classes/simulators/__init__.py 100.00% <100.00%> (ø)
cognite/client/data_classes/simulators/filters.py 100.00% <100.00%> (ø)
cognite/client/testing.py 100.00% <100.00%> (ø)
...gnite/client/data_classes/simulators/simulators.py 98.96% <98.96%> (ø)

... and 2 files with indirect coverage changes

@abdullah-cognite abdullah-cognite marked this pull request as ready for review December 17, 2024 10:35
@abdullah-cognite abdullah-cognite requested review from a team as code owners December 17, 2024 10:35
@abdullah-cognite abdullah-cognite mentioned this pull request Dec 17, 2024
5 tasks
@abdullah-cognite abdullah-cognite requested a review from a team December 17, 2024 11:46
@@ -0,0 +1,216 @@
# This file contains the data used to seed the test environment for the simulator tests

data_set_id = 1521375514069
Copy link
Author

Choose a reason for hiding this comment

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

There was a comment about having this in a fixture. The reason we have it here as a common variable is that we need it as part of the resources being seeded in this file (simulator integration) and models and routines in the other pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this, but feel free to leave it as is - but, please add a comment on why it is necessary - or why it is just temporarily needed.

Can you change it to a data set external id? Then do lookup in a fixture? (That would make running the test suite against different CDF projects much simpler. Note also that we are going to change the test project next year, as using a staging cluster is not ideal for test flakyness 😅 )

Copy link
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

Clean and easily readable code!

Here's a few comments to get this over the finish line

cognite/client/_api/simulators/__init__.py Show resolved Hide resolved
cognite/client/_api/simulators/__init__.py Show resolved Hide resolved
Comment on lines +39 to +43
List simulators:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to add __call__ & __iter__? I do think almost all our APIs support the "iterative" approach.

return super().dump(camel_case=camel_case)


class SimulatorIntegrationWrite(SimulatorIntegrationCore):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding a write-class if the API only exposes filter and delete endpoints?

Comment on lines +402 to +406
license_status: str | None = None,
simulator_version: str | None = None,
license_last_checked_time: int | None = None,
connector_status: str | None = None,
connector_status_updated_time: int | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all these valid for the write-version?

return self


class SimulatorIntegration(SimulatorIntegrationCore):
Copy link
Contributor

Choose a reason for hiding this comment

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

Check out my comments on class Simulator

@@ -0,0 +1,216 @@
# This file contains the data used to seed the test environment for the simulator tests

data_set_id = 1521375514069
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this should no be hardcoded as an internal id. it should be an external id + lookup

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