diff --git a/.github/workflows/python-pytest.yml b/.github/workflows/python-pytest.yml index e4d7945..7cc9631 100644 --- a/.github/workflows/python-pytest.yml +++ b/.github/workflows/python-pytest.yml @@ -1,15 +1,16 @@ name: pytest on: - push: pull_request: + types: [opened, reopened] + push: jobs: build: strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/run-entry-points.yml b/.github/workflows/run-entry-points.yml index f25ba88..2ef96e8 100644 --- a/.github/workflows/run-entry-points.yml +++ b/.github/workflows/run-entry-points.yml @@ -1,15 +1,16 @@ name: run entry points on: - push: pull_request: + types: [opened, reopened] + push: jobs: build: strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 0795ef9..04a55c5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Repository for yaq core python packages: Each of these projects is distributed as a separate package. -These core packages are kept in one repository primarily such that, when needed, changes can be made simulatiously to multiple packages whithout breaking tests. +These core packages are kept in one repository primarily such that, when needed, changes can be made simultaneously to multiple packages without breaking tests. Repository maintainers: - [Kyle Sunden](https://github.com/ksunden) diff --git a/yaqd-core/CHANGELOG.md b/yaqd-core/CHANGELOG.md index ea5dabb..5f8d640 100644 --- a/yaqd-core/CHANGELOG.md +++ b/yaqd-core/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] +### Fixed +- type hints for IsSensor attributes are appropriate for _n_-dimensional data + ## [2023.11.0] ### Fixed diff --git a/yaqd-core/pyproject.toml b/yaqd-core/pyproject.toml index 4d2fac2..8bdd546 100644 --- a/yaqd-core/pyproject.toml +++ b/yaqd-core/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "yaqd-core" -author = [{name="yaq developers"}] +authors = [{name="yaq developers"}] requires-python = ">=3.7" dependencies = ["platformdirs", "tomli", "tomli-w", "fastavro>=1.4.0"] readme="README.md" @@ -20,6 +20,7 @@ classifiers=[ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", ] @@ -37,7 +38,7 @@ path = "yaqd_core/__version__.py" [tool.black] line-length = 99 -target-version = ['py37', 'py38'] +target-version = ['py311', "py312"] include = '\.pyi?$' exclude = ''' /( diff --git a/yaqd-core/yaqd_core/_has_measure_trigger.py b/yaqd-core/yaqd_core/_has_measure_trigger.py index a3f3447..ed25962 100644 --- a/yaqd-core/yaqd_core/_has_measure_trigger.py +++ b/yaqd-core/yaqd_core/_has_measure_trigger.py @@ -1,29 +1,30 @@ +from __future__ import annotations + __all__ = ["HasMeasureTrigger"] import asyncio import pathlib -from typing import Dict, Any, Optional +from typing import Any from abc import ABC, abstractmethod from yaqd_core import IsSensor, IsDaemon -from ._is_sensor import MeasureType class HasMeasureTrigger(IsSensor, IsDaemon, ABC): def __init__( - self, name: str, config: Dict[str, Any], config_filepath: pathlib.Path + self, name: str, config: dict[str, Any], config_filepath: pathlib.Path ): super().__init__(name, config, config_filepath) self._looping = False if self._config["loop_at_startup"]: self.measure(loop=True) - def get_measured(self) -> MeasureType: + def get_measured(self) -> dict: return super().get_measured() @abstractmethod - async def _measure(self) -> MeasureType: + async def _measure(self) -> dict: """Do measurement, filling _measured dictionary. Returns dictionary with keys channel names, values numbers or arrays. diff --git a/yaqd-core/yaqd_core/_is_daemon.py b/yaqd-core/yaqd_core/_is_daemon.py index c6f03e1..c2940fe 100755 --- a/yaqd-core/yaqd_core/_is_daemon.py +++ b/yaqd-core/yaqd_core/_is_daemon.py @@ -87,7 +87,7 @@ def __init__( self._busy_sig = asyncio.Event() self._not_busy_sig = asyncio.Event() - self._loop = asyncio.get_event_loop() + self._loop = asyncio.get_running_loop() try: self._state_filepath.parent.mkdir(parents=True, exist_ok=True) @@ -297,7 +297,16 @@ async def shutdown_all(cls, sig, loop): # This is done after cancelling so that shutdown tasks which require the loop # are not themselves cancelled. [d.close() for d in cls._daemons] - tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()] + tasks = [ + t + for t in asyncio.all_tasks() + if ( + t is not asyncio.current_task() + and "serve_forever" not in t.get_coro().__repr__() + ) + ] + for task in tasks: + logger.info(task.get_coro()) await asyncio.gather(*tasks, return_exceptions=True) [d._save_state() for d in cls._daemons] if hasattr(signal, "SIGHUP") and sig == signal.SIGHUP: diff --git a/yaqd-core/yaqd_core/_is_sensor.py b/yaqd-core/yaqd_core/_is_sensor.py index 735269b..1e050f9 100644 --- a/yaqd-core/yaqd_core/_is_sensor.py +++ b/yaqd-core/yaqd_core/_is_sensor.py @@ -1,24 +1,24 @@ +from __future__ import annotations + __all__ = ["IsSensor"] import asyncio import pathlib -from typing import Dict, Any, Union, Tuple, List +from typing import Any import yaqd_core -MeasureType = Dict[str, Union[float]] - class IsSensor(yaqd_core.IsDaemon): def __init__( - self, name: str, config: Dict[str, Any], config_filepath: pathlib.Path + self, name: str, config: dict[str, Any], config_filepath: pathlib.Path ): super().__init__(name, config, config_filepath) - self._measured: MeasureType = dict() # values must be numbers or arrays - self._channel_names: List[str] = [] - self._channel_units: Dict[str, str] = dict() - self._channel_shapes: Dict[str, Tuple[int]] = dict() + self._measured: dict = dict() # values must be numbers or arrays + self._channel_names: list[str] = [] + self._channel_units: dict[str, str] = dict() + self._channel_shapes: dict[str, tuple[int, ...]] = dict() self._measurement_id = 0 self._measured["measurement_id"] = self._measurement_id @@ -37,7 +37,7 @@ def get_channel_units(self): """Get channel units.""" return self._channel_units - def get_measured(self) -> MeasureType: + def get_measured(self) -> dict: assert "measurement_id" in self._measured return self._measured