Skip to content

Commit

Permalink
Switch to zhinst.comms 3.0
Browse files Browse the repository at this point in the history
This commit adapts the labone api to work with the latest zhinst.comms
version 3.0. The biggest changes are the autogenerated capnp struct stubs
and the server side parsing of the shf vectors
  • Loading branch information
tobiasah committed Sep 19, 2024
1 parent ec2c500 commit 93ea3d7
Show file tree
Hide file tree
Showing 31 changed files with 2,767 additions and 2,743 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
hatch build dist
- name: Store artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: source-dist
path: dist
Expand All @@ -40,7 +40,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: source-dist
path: dist
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Labone Python API Changelog


## Version 3.0.0

* Enable server side parsing of the shf vectors. This is a breaking change since
the structure of the shf vector structs are now unified with the capnp schema.
* Replace the following `labone.core.Value` types with their capnp equivalent:
`ShfDemodulatorVectorData`,`ShfResultLoggerVectorData`,`ShfScopeVectorData`,
`ShfPidVectorData`,`CntSample`,`TriggerSample`
* Move the `extra_header` from the annotated value into the value field. This only affects
shf vectors
* Adapt the `session.set` and `session.set_with_expression` functions to take either
an `AnnotatedValue` or `Value` and a path. This prevents unnecessary copies.
* Add support for `zhinst.comms` 3.0
* Update the `hpk_schema` to the latest version. This included stubs for all structs
defined in the capnp schema.

## Version 2.3.2
* Pump version of `zhinst.comms` to 2.1

Expand Down
27 changes: 6 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"numpy>=1.20",
"packaging",
"typing_extensions>=4.8.0",
"zhinst-comms~=2.1",
"zhinst-comms~=3.0",
]

[project.urls]
Expand All @@ -54,13 +54,7 @@ packages = ["src/labone"]
python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.test]
dependencies = [
"coverage[toml]>=6.5",
"hypothesis",
"munch==4.0.0",
"pytest",
"pytest-asyncio",
]
dependencies = ["coverage[toml]>=6.5", "hypothesis", "pytest", "pytest-asyncio"]

[tool.pytest.ini_options]
markers = [
Expand All @@ -85,11 +79,11 @@ python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.lint]
dependencies = [
"black>=23.1.0",
"mypy>=1.0.0",
"ruff>=0.4.0",
"black>=24.8.0",
"mypy>=1.11.2",
"ruff>=0.6.4",
"numpy>=1.20",
"zhinst-comms~=2.1",
"zhinst-comms~=3.0",
]

[tool.hatch.envs.lint.scripts]
Expand Down Expand Up @@ -171,12 +165,3 @@ exclude_lines = [
"if t.TYPE_CHECKING:",
"\\.\\.\\.",
]

# [[tool.mypy.overrides]]
# module = "zhinst.*"
# ignore_missing_imports = true
# follow_imports = "skip"

# [[tool.mypy.overrides]]
# module = "deprecation"
# ignore_missing_imports = true
5 changes: 4 additions & 1 deletion src/labone/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
ListNodesInfoFlags,
Session,
)
from labone.core.shf_vector_data import ShfGeneratorWaveformVectorData
from labone.core.subscription import (
CircularDataQueue,
DataQueue,
DistinctConsecutiveDataQueue,
)
from labone.core.value import AnnotatedValue
from labone.core.value import AnnotatedValue, Value

__all__ = [
"AnnotatedValue",
Expand All @@ -35,4 +36,6 @@
"ServerInfo",
"KernelInfo",
"ZIContext",
"Value",
"ShfGeneratorWaveformVectorData",
]
28 changes: 15 additions & 13 deletions src/labone/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import zhinst.comms

from labone.core import hpk_schema
from labone.errors import LabOneError


Expand Down Expand Up @@ -143,27 +144,28 @@ class EmptyDisconnectedDataQueueError(StreamingError, QueueEmpty):


_ZI_ERROR_MAP = {
1: CancelledError,
3: NotFoundError,
4: OverwhelmedError,
5: BadRequestError,
6: UnimplementedError,
7: InternalError,
8: UnavailableError,
9: LabOneTimeoutError,
hpk_schema.ErrorKind.cancelled: CancelledError,
hpk_schema.ErrorKind.unknown: LabOneCoreError,
hpk_schema.ErrorKind.notFound: NotFoundError,
hpk_schema.ErrorKind.overwhelmed: OverwhelmedError,
hpk_schema.ErrorKind.badRequest: BadRequestError,
hpk_schema.ErrorKind.unimplemented: UnimplementedError,
hpk_schema.ErrorKind.internal: InternalError,
hpk_schema.ErrorKind.unavailable: UnavailableError,
hpk_schema.ErrorKind.timeout: LabOneTimeoutError,
}


def get_streaming_error(err: zhinst.comms.DynamicStruct) -> LabOneCoreError:
"""Create labone error from a labone error struct.
def raise_streaming_error(err: hpk_schema.Error) -> None:
"""Raise labone error from a labone error struct.
Args:
err: The streaming error to be converted.
Returns:
The corresponding error.
Raises:
The converted error.
"""
return _ZI_ERROR_MAP.get(err.kind, LabOneCoreError)(
raise _ZI_ERROR_MAP.get(err.kind, LabOneCoreError)( # type: ignore[call-overload]
err.message,
code=err.code,
category=err.category,
Expand Down
Loading

0 comments on commit 93ea3d7

Please sign in to comment.