Skip to content

Commit f4d1e56

Browse files
IsSensor type hints allow multidimensional channels (#82)
* Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * Update _is_sensor.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * propagate to HasMeasureTrigger * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update _is_sensor.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove MeasureType * Update CHANGELOG.md * remove redundant actions * Update README.md * expand test py versions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update pyproject.toml * initiate tests again * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * try python 3.13 curious if the freze issue still persists * Update _is_daemon.py * Update _is_daemon.py * Update _is_daemon.py * Update pyproject.toml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 39733a9 commit f4d1e56

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

.github/workflows/python-pytest.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: pytest
22

33
on:
4-
push:
54
pull_request:
5+
types: [opened, reopened]
6+
push:
67

78
jobs:
89
build:
910

1011
strategy:
1112
matrix:
12-
python-version: ["3.8", "3.9", "3.10", "3.11"]
13+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1314
os: [ubuntu-latest, windows-latest]
1415
runs-on: ${{ matrix.os }}
1516

.github/workflows/run-entry-points.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: run entry points
22

33
on:
4-
push:
54
pull_request:
5+
types: [opened, reopened]
6+
push:
67

78
jobs:
89
build:
910

1011
strategy:
1112
matrix:
12-
python-version: ["3.8", "3.9", "3.10"]
13+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1314
os: [ubuntu-latest, windows-latest]
1415
runs-on: ${{ matrix.os }}
1516

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Repository for yaq core python packages:
1010

1111
Each of these projects is distributed as a separate package.
1212

13-
These core packages are kept in one repository primarily such that, when needed, changes can be made simulatiously to multiple packages whithout breaking tests.
13+
These core packages are kept in one repository primarily such that, when needed, changes can be made simultaneously to multiple packages without breaking tests.
1414

1515
Repository maintainers:
1616
- [Kyle Sunden](https://github.com/ksunden)

yaqd-core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
55

66
## [Unreleased]
77

8+
### Fixed
9+
- type hints for IsSensor attributes are appropriate for _n_-dimensional data
10+
811
## [2023.11.0]
912

1013
### Fixed

yaqd-core/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "yaqd-core"
7-
author = [{name="yaq developers"}]
7+
authors = [{name="yaq developers"}]
88
requires-python = ">=3.7"
99
dependencies = ["platformdirs", "tomli", "tomli-w", "fastavro>=1.4.0"]
1010
readme="README.md"
@@ -20,6 +20,7 @@ classifiers=[
2020
"Programming Language :: Python :: 3.9",
2121
"Programming Language :: Python :: 3.10",
2222
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
2324
"Topic :: Scientific/Engineering",
2425
]
2526

@@ -37,7 +38,7 @@ path = "yaqd_core/__version__.py"
3738

3839
[tool.black]
3940
line-length = 99
40-
target-version = ['py37', 'py38']
41+
target-version = ['py311', "py312"]
4142
include = '\.pyi?$'
4243
exclude = '''
4344
/(

yaqd-core/yaqd_core/_has_measure_trigger.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
from __future__ import annotations
2+
13
__all__ = ["HasMeasureTrigger"]
24

35

46
import asyncio
57
import pathlib
6-
from typing import Dict, Any, Optional
8+
from typing import Any
79
from abc import ABC, abstractmethod
810

911
from yaqd_core import IsSensor, IsDaemon
10-
from ._is_sensor import MeasureType
1112

1213

1314
class HasMeasureTrigger(IsSensor, IsDaemon, ABC):
1415
def __init__(
15-
self, name: str, config: Dict[str, Any], config_filepath: pathlib.Path
16+
self, name: str, config: dict[str, Any], config_filepath: pathlib.Path
1617
):
1718
super().__init__(name, config, config_filepath)
1819
self._looping = False
1920
if self._config["loop_at_startup"]:
2021
self.measure(loop=True)
2122

22-
def get_measured(self) -> MeasureType:
23+
def get_measured(self) -> dict:
2324
return super().get_measured()
2425

2526
@abstractmethod
26-
async def _measure(self) -> MeasureType:
27+
async def _measure(self) -> dict:
2728
"""Do measurement, filling _measured dictionary.
2829
2930
Returns dictionary with keys channel names, values numbers or arrays.

yaqd-core/yaqd_core/_is_daemon.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(
8787
self._busy_sig = asyncio.Event()
8888
self._not_busy_sig = asyncio.Event()
8989

90-
self._loop = asyncio.get_event_loop()
90+
self._loop = asyncio.get_running_loop()
9191

9292
try:
9393
self._state_filepath.parent.mkdir(parents=True, exist_ok=True)
@@ -297,7 +297,16 @@ async def shutdown_all(cls, sig, loop):
297297
# This is done after cancelling so that shutdown tasks which require the loop
298298
# are not themselves cancelled.
299299
[d.close() for d in cls._daemons]
300-
tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
300+
tasks = [
301+
t
302+
for t in asyncio.all_tasks()
303+
if (
304+
t is not asyncio.current_task()
305+
and "serve_forever" not in t.get_coro().__repr__()
306+
)
307+
]
308+
for task in tasks:
309+
logger.info(task.get_coro())
301310
await asyncio.gather(*tasks, return_exceptions=True)
302311
[d._save_state() for d in cls._daemons]
303312
if hasattr(signal, "SIGHUP") and sig == signal.SIGHUP:

yaqd-core/yaqd_core/_is_sensor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
from __future__ import annotations
2+
13
__all__ = ["IsSensor"]
24

35

46
import asyncio
57
import pathlib
6-
from typing import Dict, Any, Union, Tuple, List
8+
from typing import Any
79

810
import yaqd_core
911

10-
MeasureType = Dict[str, Union[float]]
11-
1212

1313
class IsSensor(yaqd_core.IsDaemon):
1414
def __init__(
15-
self, name: str, config: Dict[str, Any], config_filepath: pathlib.Path
15+
self, name: str, config: dict[str, Any], config_filepath: pathlib.Path
1616
):
1717
super().__init__(name, config, config_filepath)
18-
self._measured: MeasureType = dict() # values must be numbers or arrays
19-
self._channel_names: List[str] = []
20-
self._channel_units: Dict[str, str] = dict()
21-
self._channel_shapes: Dict[str, Tuple[int]] = dict()
18+
self._measured: dict = dict() # values must be numbers or arrays
19+
self._channel_names: list[str] = []
20+
self._channel_units: dict[str, str] = dict()
21+
self._channel_shapes: dict[str, tuple[int, ...]] = dict()
2222
self._measurement_id = 0
2323
self._measured["measurement_id"] = self._measurement_id
2424

@@ -37,7 +37,7 @@ def get_channel_units(self):
3737
"""Get channel units."""
3838
return self._channel_units
3939

40-
def get_measured(self) -> MeasureType:
40+
def get_measured(self) -> dict:
4141
assert "measurement_id" in self._measured
4242
return self._measured
4343

0 commit comments

Comments
 (0)