Skip to content

Commit

Permalink
Merge branch 'master' into renovate/astral-sh-ruff-pre-commit-0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Mar 7, 2025
2 parents 60803d5 + 11cf2b4 commit ef85c71
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 190 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ jobs:
- name: Test full
env:
LOGIN_FLOW: client_credentials
COGNITE_CLIENT_SECRET: ${{ secrets.COGNITE_CLIENT_SECRET }}
COGNITE_TOKEN_URL: https://login.microsoftonline.com/dff7763f-e2f5-4ffd-9b8a-4ba4bafba5ea/oauth2/v2.0/token
COGNITE_TOKEN_SCOPES: https://greenfield.cognitedata.com/.default
COGNITE_CLIENT_ID: 14fd282e-f77a-457d-add5-928ec2bcbf04
COGNITE_PROJECT: python-sdk-test
COGNITE_BASE_URL: https://greenfield.cognitedata.com
COGNITE_CLIENT_SECRET: ${{ secrets.IDP_CLIENT_SECRET_CI }}
COGNITE_TOKEN_URL: https://login.microsoftonline.com/cognitepysdk.onmicrosoft.com/oauth2/v2.0/token
COGNITE_TOKEN_SCOPES: ${{ vars.CDF_BASE_URL_CI }}/.default
COGNITE_CLIENT_ID: ${{ vars.IDP_CLIENT_ID_CI }}
COGNITE_PROJECT: ${{ vars.CDF_PROJECT_CI }}
COGNITE_BASE_URL: ${{ vars.CDF_BASE_URL_CI }}
COGNITE_CLIENT_NAME: python-sdk-integration-tests
# Testpaths are defined in the pytest.ini file:
run: pytest --durations=10 --cov --cov-report term --cov-report xml:coverage.xml -n8 --dist loadscope --reruns 2 --maxfail 20
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/cdf_auth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: cdf_auth

on:
push:
branches: [master]

jobs:
cdf_auth:
runs-on: ubuntu-latest
environment: CD
name: Update CDF Auth
strategy:
fail-fast: false
matrix:
cdf_project: ["python-sdk-contributor", "python-sdk-test-prod"]
container:
image: cognite/toolkit:0.4.9
env:
CDF_CLUSTER: ${{ vars.CDF_CLUSTER_CD }}
CDF_PROJECT: ${{ matrix.cdf_project }}
IDP_CLIENT_ID: ${{ vars.IDP_CLIENT_ID_CD }}
IDP_CLIENT_SECRET: ${{ secrets.IDP_CLIENT_SECRET_CD }}
IDP_TENANT_ID: ${{ vars.IDP_TENANT_ID_CD }}
PROVIDER: "entra_id"
LOGIN_FLOW: "client_credentials"
steps:
- uses: actions/checkout@v4
- name: Build the CDF Groups
working-directory: scripts/toolkit
run: cdf build --env ${{ matrix.cdf_project }}
- name: Update CDF Auth
working-directory: scripts/toolkit
run: cdf deploy
12 changes: 6 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
- name: Test full
env:
LOGIN_FLOW: client_credentials
COGNITE_CLIENT_SECRET: ${{ secrets.COGNITE_CLIENT_SECRET }}
COGNITE_TOKEN_URL: https://login.microsoftonline.com/dff7763f-e2f5-4ffd-9b8a-4ba4bafba5ea/oauth2/v2.0/token
COGNITE_TOKEN_SCOPES: https://greenfield.cognitedata.com/.default
COGNITE_CLIENT_ID: 14fd282e-f77a-457d-add5-928ec2bcbf04
COGNITE_PROJECT: python-sdk-test
COGNITE_BASE_URL: https://greenfield.cognitedata.com
COGNITE_CLIENT_SECRET: ${{ secrets.IDP_CLIENT_SECRET_CD }}
COGNITE_TOKEN_URL: https://login.microsoftonline.com/cognitepysdk.onmicrosoft.com/oauth2/v2.0/token
COGNITE_TOKEN_SCOPES: ${{ vars.CDF_BASE_URL_CD }}/.default
COGNITE_CLIENT_ID: ${{ vars.IDP_CLIENT_ID_CD }}
COGNITE_PROJECT: ${{ vars.CDF_PROJECT_CD }}
COGNITE_BASE_URL: ${{ vars.CDF_BASE_URL_CD }}
COGNITE_CLIENT_NAME: python-sdk-integration-tests
# Testpaths are defined in the pytest.ini file:
run: pytest --durations=10 --cov --cov-report term --cov-report xml:coverage.xml -n8 --dist loadscope --reruns 2 --maxfail 20
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Changes are grouped as follows
- Support for the `/simulators/models` and `/simulators/models/revisions` API endpoints.
- Support for the `/simulators` and `/simulators/integration` API endpoints.

## [7.73.4] - 2025-02-24
### Fixed
- An issue with `DatapointsAPI.retrieve_latest` and usage of `instance_id` when using `ignore_unknown_ids=True`
and *any type* of identifier was not found (no longer raises `TypeError`).

## [7.73.3] - 2025-02-07
### Added
- Listable property types for containers in Data Modeling now accept `max_list_size`.
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ For any code examples written directly in `docs/source` we are using the [sphinx
pytest docs
```

### Updating Integration Runner Auth

If you need to add a new capability to the integration runner, you need to create a new Pull Requests (PR) in which
you do the following:

1. Add a read-only version of the new capability to the `scripts/toolkit/acces/auth/readonly.Group.yaml`
2. Add a read-write version of the new capability to the `scripts/toolkit/acces/auth/readwrite.Group.yaml`

Get the PR reviewed by an SDK maintainer. The integration runner will be updated once the PR is merged.

For an illustration of the setup see [diagram](https://miro.com/app/board/uXjVIbOg5zw=/).

### Documentation

Build html files of documentation locally by running
Expand Down
8 changes: 6 additions & 2 deletions cognite/client/_api/datapoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,14 +2107,18 @@ def _post_fix_status_codes_and_stringified_floats(self, result: list[dict[str, A
ids_exists = (
{("id", r["id"]) for r in result}
.union({("xid", r.get("externalId")) for r in result})
.union({("inst_id", r.get("instanceId")) for r in result})
.union({("inst_id", NodeId.load_if(r.get("instanceId"))) for r in result})
.difference({("xid", None), ("inst_id", None)})
) # fmt: skip
self._all_identifiers = [
query
for query in self._all_identifiers
if ids_exists.intersection(
(("id", query.get("id")), ("xid", query.get("externalId")), ("inst_id", query.get("instanceId")))
(
("id", query.get("id")),
("xid", query.get("externalId")),
("inst_id", NodeId.load_if(query.get("instanceId"))),
)
)
]
for query, res in zip(self._all_identifiers, result):
Expand Down
11 changes: 7 additions & 4 deletions cognite/client/_api/simulators/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ def __call__(

def list(
self,
limit: int = DEFAULT_LIMIT_READ,
limit: int | None = DEFAULT_LIMIT_READ,
filter: SimulatorIntegrationFilter | None = None,
) -> SimulatorIntegrationList:
"""`Filter simulator integrations <https://developer.cognite.com/api#tag/Simulator-Integrations/operation/filter_simulator_integrations_simulators_integrations_list_post>`_
Retrieves a list of simulator integrations that match the given criteria
Args:
limit (int): The maximum number of simulator integrations to return.
limit (int | None): The maximum number of simulator integrations to return, pass None to return all.
filter (SimulatorIntegrationFilter | None): Filter to apply.
Returns:
SimulatorIntegrationList: List of simulator integrations
Examples:
List simulator integrations:
List a few simulator integrations:
>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.integrations.list()
Expand All @@ -97,7 +101,6 @@ def list(
>>> res = client.simulators.integrations.list(
... filter=SimulatorIntegrationFilter(active=True))
"""

self._warning.warn()
return self._list(
method="POST",
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

__version__ = "7.73.3"
__version__ = "7.73.4"

__api_subversion__ = "20230101"
11 changes: 6 additions & 5 deletions cognite/client/data_classes/simulators/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
from collections.abc import Sequence

from cognite.client.data_classes._base import CogniteFilter
from cognite.client.utils.useful_types import SequenceNotStr


class SimulatorIntegrationFilter(CogniteFilter):
def __init__(
self,
simulator_external_ids: SequenceNotStr[str] | None = None,
simulator_external_ids: str | Sequence[str] | None = None,
active: bool | None = None,
) -> None:
self.simulator_external_ids = simulator_external_ids
self.simulator_external_ids = (
[simulator_external_ids] if isinstance(simulator_external_ids, str) else simulator_external_ids
)
self.active = active


class SimulatorModelsFilter(CogniteFilter):
def __init__(
self,
simulator_external_ids: Sequence[str] | None = None,
simulator_external_ids: str | Sequence[str] | None = None,
) -> None:
self.simulator_external_ids = (
[simulator_external_ids] if isinstance(simulator_external_ids, str) else simulator_external_ids
Expand All @@ -29,7 +30,7 @@ def __init__(
class SimulatorModelRevisionsFilter(CogniteFilter):
def __init__(
self,
model_external_ids: Sequence[str] | None = None,
model_external_ids: str | Sequence[str] | None = None,
all_versions: bool | None = None,
) -> None:
self.model_external_ids = [model_external_ids] if isinstance(model_external_ids, str) else model_external_ids
16 changes: 16 additions & 0 deletions cognite/client/utils/_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ class InstanceId:
def dump(self, camel_case: bool = True, include_instance_type: bool = True) -> dict[str, str]:
return {"space": self.space, "externalId" if camel_case else "external_id": self.external_id}

@overload
@classmethod
def load_if(cls, data: None) -> None: ...

@overload
@classmethod
def load_if(cls, data: dict[str, str] | tuple[str, str] | Self) -> Self: ...

@classmethod
def load_if(cls, data: dict[str, str] | tuple[str, str] | Self | None) -> Self | None:
# Note: For experimentation - I'd like to add this as a universal method to all classes to avoid
# the endless spam of 'MyClass.load(foo["bar"]) if "bar" in foo else None' in the codebase!
if data is None:
return None
return cls.load(data)

@classmethod
def load(cls, data: dict[str, str] | tuple[str, str] | Self) -> Self:
if isinstance(data, cls):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "7.73.3"
version = "7.73.4"

description = "Cognite Python SDK"
readme = "README.md"
Expand Down
68 changes: 0 additions & 68 deletions scripts/add_capability.py

This file was deleted.

5 changes: 4 additions & 1 deletion scripts/toolkit/cdf.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[toolkit]
default_env = "python-sdk-contributor"

[plugins]
run = true

[modules]
# This is the version of the modules. It should not be changed manually.
# It will be updated by the 'cdf module upgrade' command.
version = "0.3.28"
version = "0.4.9"
13 changes: 13 additions & 0 deletions scripts/toolkit/config.python-sdk-contributor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
environment:
project: python-sdk-contributor
validation-type: prod
selected:
- modules/

variables:
modules:
read_write_group_source_id: 4521b63c-b914-44fe-9f86-f42b17fcb6c1
readwrite_group_name: contributor
#
readonly_group_name: viewer
readonly_group_source_id: not_used_for_now
13 changes: 13 additions & 0 deletions scripts/toolkit/config.python-sdk-test-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
environment:
project: python-sdk-test-prod
validation-type: prod
selected:
- modules/

variables:
modules:
read_write_group_source_id: 409f29f3-7e1b-461a-add1-1184d539b623
readwrite_group_name: integration-test-runner
#
readonly_group_name: contributor
readonly_group_source_id: 4521b63c-b914-44fe-9f86-f42b17fcb6c1
Loading

0 comments on commit ef85c71

Please sign in to comment.