Skip to content

Redis asyncio migration#11

Merged
majamassarini merged 7 commits intodevfrom
redis-asyncio-migration
Mar 17, 2026
Merged

Redis asyncio migration#11
majamassarini merged 7 commits intodevfrom
redis-asyncio-migration

Conversation

@majamassarini
Copy link
Owner

No description provided.

aioredis 1.3.1 was abandoned in 2022. Replace it with redis.asyncio,
the async interface bundled in redis-py>=4.2.0 (which absorbed aioredis).

pubsub.py:
- Redis() constructor is now synchronous (no await)
- Subscriptions use redis.pubsub() objects with get_message()
  instead of wait_message()/get(); read() polls with timeout=0.1s
- disconnect() awaits aclose() on pubsub objects and connections

storage.py:
- Redis() constructor is now synchronous (no await)
- zrange() and zadd() replace raw execute() calls
- zadd() uses {member: score} mapping as required by redis-py 4.x
- disconnect() awaits aclose()

setup.py / requirements.txt:
- Replace aioredis==1.3.1 + hiredis==1.1.0 with redis[hiredis]>=4.2.0

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Avoids a hiredis compilation failure on Python 3.8 (no pre-built wheel)
from blocking the redis installation. With separate entries, redis is
installed successfully even if hiredis fails to build.
@majamassarini majamassarini force-pushed the redis-asyncio-migration branch from 77b3f58 to 84efb23 Compare March 2, 2026 18:31
Python 3.14 / APScheduler 3.10+ incompatibilities fixed:

home/event/__init__.py:
- TypeVar() first argument must be a string; add "Event" as name
  (Python 3.14 enforces this; 3.8 silently accepted a type)

home/scheduler/trigger/protocol/mean.py:
- APScheduler 3.10+ start() calls asyncio.get_running_loop() instead of
  get_event_loop(), so it must be called inside a running event loop
- Python 3.14 removed implicit event loop creation from get_event_loop()
- Update GreaterThan/LesserThan/InBetween doctests to use asyncio.run()
  and drop asyncio.get_event_loop().stop() in favour of a plain return

requirements.txt / setup.py:
- Bump APScheduler from ==3.9.0 to >=3.10.0 (drops pkg_resources usage)
- Unpin tzlocal and pytz (pinned versions conflict with APScheduler 3.10+)
- Update Python classifier to 3.14

.github/workflows/test.yml:
- Switch CI to Python 3.14 (pre-built hiredis wheels available)
- Replace deprecated "python setup.py install" with "pip install ."
- Add -t . to unittest discover to fix home/tests/redis/ shadowing the
  installed redis package on sys.path

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Migrate packaging metadata to pyproject.toml using setuptools as the
build backend. The license classifier is dropped in favour of the SPDX
license expression field (PEP 639).
Move flake8 config from .flake8 into pyproject.toml
Add flake8-pyproject plugin so flake8 reads [tool.flake8] from pyproject.toml,
then delete the separate .flake8 file.

Remove redundant quotes from type annotations
from __future__ import annotations makes all annotations lazy strings,
so explicit quotes like "home.Event" are unnecessary.

Fix mypy errors instead of suppressing them globally

Replace Event TypeVar with a proper base class to eliminate arg-type/return-value false positives
The previous Event = TypeVar("Event", int, float, str, Enum, ...) generated
one mypy error per constraint (~80 false positives) at every call site.
Replace it with class Event(pass) in home/event/base.py, make Enum and Int
inherit from it, and remove the now-unnecessary disable_error_code suppression.
Also add a targeted # type: ignore[arg-type] in mean.py where Mixin cannot
be expressed as an Intersection of Trigger and Mixin (Python limitation).

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pre-commit / CI:
- Add local behave hook (language: python, all project deps listed)
- Add behave step to GitHub Actions workflow

Bug fixes in sound player state machine:
- fade_in/callable.Forced: was calling compute_new_state(state, "base", ...)
  but "base" is not a registered output state for fade_in, causing a silent
  KeyError and leaving the state in fade_in instead of transitioning to
  forced_off. Fix: use get_new_state(state, "forced_off") for forced.Off.
- sound_player.feature: rows @1.3 and @1.45 expected off after
  sleepiness.Awake from an off-with-elapsed-On setup, but the auto-inject
  (elapsed.Event.Off injected on fade_in→off) means the off state always
  has elapsed=Off after a fade-in cycle, so sleepiness.Awake correctly
  transitions to fade_in. Update expected state to fade_in.

Fix scheduler trigger type check

- Fix scheduler trigger type comparison: change `type` from @Property to
  a class variable in Trigger, state.Trigger, and protocol.Trigger so that
  class-level comparisons (e.g. Trigger.type == "APPLIANCE STATE") work
  correctly; this fixes 5 failing unit tests where _schedule_by_trigger_fork
  was never called

Improve documentation: replace sphinx-gherkindoc, add docs target, fix English

- Replace broken sphinx-gherkindoc (incompatible with Sphinx 9) with a
  lightweight custom script docs/gherkindoc.py that converts .feature files
  to RST code-block pages using only the Python standard library
- Update docs/Makefile to use the new script via the PYTHON variable
- Fix numerous English issues across all RST documentation files and README:

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add a docs job to test.yml: installs .[doc] extras, runs make -C docs html,
  and uploads the built HTML as a GitHub Actions artifact
- Add publish.yml: triggers on GitHub release (published event), builds a
  source distribution and wheel with python -m build, then publishes to PyPI
  using pypa/gh-action-pypi-publish with OIDC trusted publishing (no API
  token secret required; configure the pypi environment in repository settings)

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@majamassarini majamassarini force-pushed the redis-asyncio-migration branch from de9a663 to 967b0fd Compare March 17, 2026 16:02
@majamassarini majamassarini merged commit 83f60a0 into dev Mar 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant