Skip to content

Commit ef5ac04

Browse files
authored
chore: move v8 to master branch (#2549)
v8 of the SDK has lived on `pysdk-release-v8` for some time. We now move it back to master, while separately, moving v7 (ex-master) to `pysdk-release-v7`.
2 parents 767818d + 4b99868 commit ef5ac04

518 files changed

Lines changed: 54609 additions & 25834 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[run]
2-
source=cognite
2+
source =
3+
cognite
4+
tests
35
omit =
46
cognite/client/_proto/*
57

.gemini/styleguide.md

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@
55
- **Strong Typing**: Use type hints extensively with MyPy. Avoid `Any` when possible
66
- **Type Safety**: Use dataclasses models for complex data
77
structures instead of untyped dictionaries
8-
- **CogniteResource**: Use `CogniteResource` for DTO (Data Transfer Object) that are request or response
9-
objects to/from the Cognite API
10-
- **CogniteObject**: Use `CogniteObject` for objects that are within `CogniteResource` objects.
8+
- **CogniteResource**: Use `CogniteResource` for DTO (Data Transfer Object) that are request or
9+
response objects to/from the Cognite API
1110
- **IO Safety**: Always use typed data structures for file operations and data parsing
1211
- **Readability**: Code should be immediately understandable
1312
- **Maintainability**: Write code that is easy to modify and extend
1413
- **Consistency**: Follow established patterns across the codebase
14+
- **Code Comments**: Use comments sparingly. They should always add necessary context, or
15+
explain unintuitive code and never feel like a repeat of the code.
1516

1617
## Principles on doing pull request reviews
1718

18-
- **Main point first.** Start with the key feedback or required action.
19-
- **Be concise.** Use short, direct comments. Avoid unnecessary explanations.
20-
- **Actionable suggestions.** If something needs fixing, state exactly what and how.
21-
- **One issue per comment.** Separate unrelated feedback for clarity.
22-
- **Code, not prose.** Prefer code snippets or examples over long text.
23-
- **Background only if needed.** Add context only if the main point isn't obvious.
19+
- **Main point first** Start with the key feedback or required action.
20+
- **Be concise** Use short, direct comments. Avoid unnecessary explanations.
21+
- **Actionable suggestions** If something needs fixing, state exactly what and how.
22+
- **One issue per comment** Separate unrelated feedback for clarity.
23+
- **Code, not prose** Prefer code snippets or examples over long text.
24+
- **Background only if needed** Add context only if the main point isn't obvious.
2425

2526
## How to do pull request summaries
2627

27-
- **Short recap.** Summarize the main point of the PR in one or two sentences.
28-
- **Don't repeat the PR description.** Only add new or clarifying information.
29-
- **Be brief unless needed.** Only write a longer summary if the PR description
28+
- **Short recap** Summarize the main point of the PR in one or two sentences.
29+
- **Don't repeat the PR description** Only add new or clarifying information.
30+
- **Be brief unless needed** Only write a longer summary if the PR description
3031
is missing crucial details.
31-
- **Extend, don't duplicate.** If more detail is needed, clearly state what is
32+
- **Extend, don't duplicate** If more detail is needed, clearly state what is
3233
missing from the PR description and add only the necessary context.
3334

3435
## Line Length and Formatting
@@ -73,7 +74,7 @@ import logging
7374
from pathlib import Path
7475
from typing import TYPE_CHECKING
7576

76-
from requests import Response
77+
from httpx import Response
7778

7879
from cognite.client.data_classes import Asset
7980

@@ -91,7 +92,8 @@ if TYPE_CHECKING:
9192

9293
## Docstrings
9394

94-
Use concise docstrings with Args/Returns in google-style format. Based on repository patterns:
95+
Use concise docstrings with Args/Returns in google-style format. 'Raises' can be used, but is not
96+
required. Based on repository patterns:
9597

9698
```python
9799
def render_header(header: str) -> str:
@@ -123,7 +125,8 @@ def walk_sdk_documentation(content: Tag, parser: Parser[T]) -> Iterable[T]:
123125
## Error Handling
124126

125127
- **Specific exceptions**: Avoid broad `Exception` catches
126-
- **Graceful handling**: Provide meaningful error messages
128+
- **Graceful handling**: Provide meaningful error messages, for example "got type foo,
129+
expected type bar".
127130
- **Type safety**: Return `None` or use Union types for fallible operations
128131

129132
```python
@@ -138,27 +141,6 @@ def validate_data_modeling_identifier(space: str | None, external_id: str | None
138141

139142
- **Pre-commit**: `pre-commit run --all-files` for comprehensive checks
140143

141-
142-
## Data Structures
143-
144-
**Prefer typed structures**:
145-
146-
```python
147-
# Good
148-
@dataclass
149-
class FunctionError:
150-
function_name: str
151-
message: str
152-
153-
# Good
154-
class QueryCompletion(BaseModel):
155-
query: str
156-
variables: dict[str, Any]
157-
158-
# Avoid
159-
error_data = {"function_name": "foo", "message": "bar"}
160-
```
161-
162144
## Logging
163145

164146
- Use the `logging` module with appropriate levels
@@ -192,6 +174,4 @@ error_data = {"function_name": "foo", "message": "bar"}
192174
guarantee against regression.
193175
- Counter-intuitively, for data classes in the SDK, testing their load/dump
194176
methods should not be done as this is done automatically
195-
(see `tests/tests_unit/test_base.py`). This rule applies to any subclass of
196-
`CogniteObject`, `CogniteResource`, `CogniteUpdate`,
197-
`WriteableCogniteResource` or `WriteableCogniteResourceList`.
177+
(see `tests/tests_unit/test_base.py`). This rule applies to any subclass of `CogniteResource` or `CogniteUpdate`.

.github/workflows/build.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ name: build
44
on:
55
merge_group:
66
pull_request:
7-
branches: [master]
87

98
concurrency:
109
group: pr-${{ github.workflow }}-${{ github.head_ref }}
@@ -21,6 +20,16 @@ jobs:
2120
- name: Linting and static code checks
2221
run: pre-commit run --all-files --show-diff-on-failure
2322

23+
verify-sync-codegen:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v5
27+
- uses: ./.github/actions/setup
28+
with:
29+
extras: "-E pandas"
30+
- name: Ensures sync code is up-to-date, with no stale files
31+
run: python scripts/sync_client_codegen/main.py verify
32+
2433
build_docs:
2534
runs-on: ubuntu-latest
2635
steps:
@@ -43,15 +52,15 @@ jobs:
4352
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
4453
- uses: ./.github/actions/setup
4554
- name: Test core
46-
run: pytest tests/tests_unit -n8 --dist loadscope --maxfail 10 -m 'not dsl' --test-deps-only-core
55+
run: pytest tests/tests_unit -n6 --dist loadscope --maxfail 10 -m 'not dsl' --test-deps-only-core
4756

4857
test_full:
4958
runs-on: ${{ matrix.os }}
5059
strategy:
5160
fail-fast: false
5261
matrix:
5362
os: [ubuntu-latest, windows-latest]
54-
python-version: ["3.10", "3.11", "3.12", "3.13"]
63+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
5564
steps:
5665
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
5766
- uses: ./.github/actions/setup
@@ -73,6 +82,7 @@ jobs:
7382
run: pytest --durations=10 --cov --cov-report term --cov-report xml:coverage.xml -n8 --dist loadscope --reruns 2 --maxfail 20
7483

7584
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5
85+
# Report code coverage from windows runner; xdist + ubuntu gives incorrect results
7686
if: matrix.os == 'windows-latest' && matrix.python-version == '3.10'
7787
with:
7888
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/manual-pre-release.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'pysdk-release-v8'
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test_full_build_and_release:
13+
runs-on: ubuntu-latest
14+
environment: CD
15+
steps:
16+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
17+
18+
- uses: ./.github/actions/setup
19+
20+
- name: Ensure version is a v8-release
21+
run: |
22+
VERSION=$(poetry version --short)
23+
echo "Detected version: $VERSION"
24+
if [[ "$VERSION" =~ ^8\.[0-9]+\.[0-9]+$ ]]; then
25+
echo "✅ Version format is valid for a v8-release."
26+
else
27+
echo "❌ Error: Version '$VERSION' is not a valid v8-release (must be 8.x.y format)."
28+
exit 1
29+
fi
30+
31+
- name: Build package
32+
run: poetry build
33+
34+
- name: Release to PyPI
35+
env:
36+
TWINE_USERNAME: __token__
37+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
38+
run: twine upload --skip-existing --disable-progress-bar --verbose dist/*

.github/workflows/verify-jupyter.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: build
33

44
on:
55
pull_request:
6-
branches: [master]
6+
branches: [master, pysdk-release-v8]
77

88
jobs:
99
build_and_test_jupyter_pyodide:
@@ -23,11 +23,11 @@ jobs:
2323
with:
2424
node-version: "22"
2525
- name: Install dependencies
26-
run: npm install pyodide@0.27.6 # JupyterLite currently using pyodide 0.27.6
26+
run: npm install pyodide@0.29.0 # JupyterLite currently using pyodide 0.29.0
2727
- name: Install cognite-sdk in pyodide environment
2828
run: |
2929
whl_file=$(find dist -name "*.whl" | sed 's|^dist/||') # Find the built wheel file, remove dist/ prefix
3030
echo "Found built wheel file: $whl_file"
3131
SDK_FILE_PATH=$whl_file \
32-
PACKAGES="[\"pyodide-http\", \"http://localhost:3000/dist/$whl_file\"]" \
32+
PACKAGES="[\"anyio\", \"http://localhost:3000/dist/$whl_file\"]" \
3333
node scripts/test-pyodide.js

.github/workflows/verify-streamlit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: build
33

44
on:
55
pull_request:
6-
branches: [master]
6+
branches: [master, pysdk-release-v8]
77

88
jobs:
99
build_and_test_streamlit_pyodide:
@@ -29,5 +29,5 @@ jobs:
2929
whl_file=$(find dist -name "*.whl" | sed 's|^dist/||') # Find the built wheel file, remove dist/ prefix
3030
echo "Found built wheel file: $whl_file"
3131
SDK_FILE_PATH=$whl_file \
32-
PACKAGES="[\"pyodide-http\", \"http://localhost:3000/dist/$whl_file\"]" \
32+
PACKAGES="[\"ssl\", \"anyio\", \"http://localhost:3000/dist/$whl_file\"]" \
3333
node scripts/test-pyodide.js

.pre-commit-config.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ repos:
1313
- --fix
1414
- --exit-non-zero-on-fix
1515
- --force-exclude
16+
1617
- id: ruff-format
1718
name: ruff format
1819
language: python
@@ -32,22 +33,11 @@ repos:
3233
hooks:
3334
- id: mypy
3435
name: mypy
35-
# Eventually we want to run mypy on the whole test code base. But for now we only enable it for data modeling, simulators and datapoints
36-
entry: |
37-
poetry run dmypy run -- cognite tests/tests_integration/test_api/test_data_modeling
38-
tests/tests_unit/test_data_classes/test_data_models
39-
tests/tests_unit/test_utils/test_time.py
40-
tests/tests_integration/test_api/test_datapoints.py
41-
tests/tests_integration/test_api/test_simulators
42-
tests/tests_integration/test_api/test_principals.py
43-
tests/tests_unit/test_api/test_simulators
44-
tests/tests_unit/test_data_classes/test_simulators.py
36+
entry: poetry run dmypy run -- cognite tests
4537
files: ^.*.(py|pyi)$
4638
language: system
4739
pass_filenames: false
4840

49-
- repo: local
50-
hooks:
5141
- id: custom-checks
5242
name: custom repo checks
5343
entry: poetry run python scripts/run_checks.py
@@ -56,6 +46,14 @@ repos:
5646
pass_filenames: true
5747
require_serial: true # avoid possible race conditions
5848

49+
- id: sync-client-codegen
50+
name: run sync codegen on changed files
51+
entry: poetry run python scripts/sync_client_codegen/main.py run --files
52+
files: ^cognite/.*.(py|pyi)$
53+
language: system
54+
pass_filenames: true
55+
require_serial: true
56+
5957
- repo: https://github.com/jsh9/pydoclint # Run after 'custom-checks' as these may auto-fix
6058
rev: 0.8.3
6159
hooks:

0 commit comments

Comments
 (0)