mirror of
https://github.com/tiqi-group/pydase_service_base.git
synced 2026-02-19 17:48:45 +01:00
Formatting
This commit is contained in:
@@ -35,6 +35,7 @@ else:
|
|||||||
"InfluxDBv1Session requires the 'influxdbv1' extra. "
|
"InfluxDBv1Session requires the 'influxdbv1' extra. "
|
||||||
"Please refer to https://gitlab.phys.ethz.ch/tiqi-projects/qchub/icon-services/pydase_service_base."
|
"Please refer to https://gitlab.phys.ethz.ch/tiqi-projects/qchub/icon-services/pydase_service_base."
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import influxdb_client_3 # type: ignore # noqa
|
import influxdb_client_3 # type: ignore # noqa
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ else:
|
|||||||
"InfluxDBv3Session requires the 'influxdbv3' extra. "
|
"InfluxDBv3Session requires the 'influxdbv3' extra. "
|
||||||
"Please refer to https://gitlab.phys.ethz.ch/tiqi-projects/qchub/icon-services/pydase_service_base."
|
"Please refer to https://gitlab.phys.ethz.ch/tiqi-projects/qchub/icon-services/pydase_service_base."
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlmodel # noqa
|
import sqlmodel # noqa
|
||||||
|
|
||||||
@@ -61,4 +63,9 @@ else:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["InfluxDBSession", "InfluxDBv1Session", "InfluxDBv3Session", "PostgresDatabaseSession"]
|
__all__ = [
|
||||||
|
"InfluxDBSession",
|
||||||
|
"InfluxDBv1Session",
|
||||||
|
"InfluxDBv3Session",
|
||||||
|
"PostgresDatabaseSession",
|
||||||
|
]
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class InfluxDBv1Config(BaseConfig): # type: ignore
|
|||||||
verify_ssl: bool = True
|
verify_ssl: bool = True
|
||||||
headers: dict[str, str] = {} # noqa: RUF012
|
headers: dict[str, str] = {} # noqa: RUF012
|
||||||
|
|
||||||
|
|
||||||
class InfluxDBv3Config(BaseConfig): # type: ignore
|
class InfluxDBv3Config(BaseConfig): # type: ignore
|
||||||
url: str
|
url: str
|
||||||
org: str
|
org: str
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Module for InfluxDB v3 session management."""
|
"""Module for InfluxDB v3 session management."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from influxdb_client_3 import InfluxDBClient3, Point, WritePrecision as _WritePrecision
|
from influxdb_client_3 import InfluxDBClient3, Point, WritePrecision as _WritePrecision
|
||||||
from typing import Any, NamedTuple, Iterable
|
from typing import Any, NamedTuple, Iterable
|
||||||
@@ -19,9 +20,13 @@ __all__ = [
|
|||||||
|
|
||||||
WritePrecision = _WritePrecision
|
WritePrecision = _WritePrecision
|
||||||
|
|
||||||
|
|
||||||
class InfluxDBv3Session:
|
class InfluxDBv3Session:
|
||||||
"""Context manager for InfluxDB v3 session."""
|
"""Context manager for InfluxDB v3 session."""
|
||||||
def __init__(self, host: str, org: str, bucket: str, token: str, verify_ssl: bool = True):
|
|
||||||
|
def __init__(
|
||||||
|
self, host: str, org: str, bucket: str, token: str, verify_ssl: bool = True
|
||||||
|
):
|
||||||
"""Initialize InfluxDB v3 session.
|
"""Initialize InfluxDB v3 session.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -37,22 +42,29 @@ class InfluxDBv3Session:
|
|||||||
self._host = host
|
self._host = host
|
||||||
self._token = token
|
self._token = token
|
||||||
self._verify_ssl = verify_ssl
|
self._verify_ssl = verify_ssl
|
||||||
self._client = InfluxDBClient3(self._host, self._org, self._bucket, self._token, verify_ssl=self._verify_ssl)
|
self._client = InfluxDBClient3(
|
||||||
|
self._host,
|
||||||
|
self._org,
|
||||||
|
self._bucket,
|
||||||
|
self._token,
|
||||||
|
verify_ssl=self._verify_ssl,
|
||||||
|
)
|
||||||
|
|
||||||
def __enter__(self) -> InfluxDBv3Session:
|
def __enter__(self) -> InfluxDBv3Session:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(
|
def __exit__(
|
||||||
self,
|
self,
|
||||||
exc_type: type[BaseException] | None,
|
exc_type: type[BaseException] | None,
|
||||||
exc_value: BaseException | None,
|
exc_value: BaseException | None,
|
||||||
exc_traceback: TracebackType | None,
|
exc_traceback: TracebackType | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._client.close()
|
self._client.close()
|
||||||
|
|
||||||
|
def write(
|
||||||
def write(self, bucket: str,
|
self,
|
||||||
record:str
|
bucket: str,
|
||||||
|
record: str
|
||||||
| Iterable[str]
|
| Iterable[str]
|
||||||
| Point
|
| Point
|
||||||
| Iterable[Point]
|
| Iterable[Point]
|
||||||
@@ -62,7 +74,8 @@ class InfluxDBv3Session:
|
|||||||
| Iterable[bytes]
|
| Iterable[bytes]
|
||||||
| NamedTuple
|
| NamedTuple
|
||||||
| Iterable[NamedTuple],
|
| Iterable[NamedTuple],
|
||||||
write_precision: WritePrecision | None = None)->None:
|
write_precision: WritePrecision | None = None,
|
||||||
|
) -> None:
|
||||||
"""Write records to InfluxDB v3.
|
"""Write records to InfluxDB v3.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -76,7 +89,9 @@ class InfluxDBv3Session:
|
|||||||
self._client.write(record)
|
self._client.write(record)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_config_file(cls, path: str | PathLike | None = None)->"InfluxDBv3Session":
|
def from_config_file(
|
||||||
|
cls, path: str | PathLike | None = None
|
||||||
|
) -> "InfluxDBv3Session":
|
||||||
"""Create InfluxDBv3Session from configuration file.
|
"""Create InfluxDBv3Session from configuration file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -94,9 +109,7 @@ class InfluxDBv3Session:
|
|||||||
InfluxDBv3Session: An instance of InfluxDBv3Session.
|
InfluxDBv3Session: An instance of InfluxDBv3Session.
|
||||||
"""
|
"""
|
||||||
if path is not None:
|
if path is not None:
|
||||||
_config = InfluxDBv3Config(
|
_config = InfluxDBv3Config(config_sources=FileSource(path))
|
||||||
config_sources=FileSource(path)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
_config = InfluxDBv3Config(
|
_config = InfluxDBv3Config(
|
||||||
config_sources=FileSource(
|
config_sources=FileSource(
|
||||||
@@ -108,5 +121,5 @@ class InfluxDBv3Session:
|
|||||||
org=_config.org,
|
org=_config.org,
|
||||||
bucket=_config.bucket,
|
bucket=_config.bucket,
|
||||||
token=_config.token.get_secret_value(),
|
token=_config.token.get_secret_value(),
|
||||||
verify_ssl=_config.verify_ssl
|
verify_ssl=_config.verify_ssl,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from confz import BaseConfig, FileSource
|
from confz import BaseConfig, FileSource
|
||||||
|
|
||||||
|
|||||||
@@ -136,8 +136,6 @@ def test_influxdbv3session_write(influxdb_container):
|
|||||||
assert result["value"][0].as_py() == 23.5 # type: ignore
|
assert result["value"][0].as_py() == 23.5 # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_from_config_file_initialization(influxdbv3_config_yaml):
|
def test_from_config_file_initialization(influxdbv3_config_yaml):
|
||||||
"""
|
"""
|
||||||
Test that InfluxDBv3Session.from_config_file initializes correctly from config file.
|
Test that InfluxDBv3Session.from_config_file initializes correctly from config file.
|
||||||
|
|||||||
Reference in New Issue
Block a user