Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ on:
tags: ["v*"]
pull_request:
workflow_dispatch:
schedule:
# Weekly, for the libei-floor job below: the declared 1.0.0 floor is
# otherwise a claim nothing executes, since no distro CI runs ships a
# libei that old. Monday morning, so a break is found at the start of a
# week rather than during a release.
- cron: "0 5 * * 1"

jobs:
test:
Expand Down Expand Up @@ -83,6 +89,72 @@ jobs:
print("import-safe with no native libraries")
PY

# The README declares "libei 1.0.0 or newer"; development tracks 1.6.x and
# the `test` job above runs Ubuntu's 1.2.1 -- which leaves 1.0.x and 1.1.x
# as a floor nothing has executed since it was declared. This builds those
# exact releases from source and runs the suite against them: the
# version-gated tests must *skip* (that is their whole mechanism firing for
# real), and everything else must pass. Weekly and on dispatch, not per
# push -- a from-source meson build is minutes of work and the floor only
# moves when a release changes it. Deliberately NOT in `publish`'s needs:
# a job that does not run on tag pushes would leave publish waiting on a
# skip.
libei-floor:
name: declared floor (libei ${{ matrix.libei }})
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
libei: ["1.0.0", "1.1.0"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"

# What libei's own meson build needs: jinja2/attrs generate the
# protocol code, libevdev and libsystemd (sd-bus, for liboeffis) are
# its two library dependencies. Documentation is switched off rather
# than left on auto so a runner image that happens to carry doxygen
# does not turn this into a docs build.
- name: Install the libei build dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
meson ninja-build pkg-config gcc libevdev-dev libsystemd-dev \
python3-jinja2 python3-attr

- name: Build and install libei ${{ matrix.libei }} from source
run: |
set -eu
git clone --depth 1 --branch "${{ matrix.libei }}" \
https://gitlab.freedesktop.org/libinput/libei.git /tmp/libei
cd /tmp/libei
# Options verified against 1.0.0's own meson_options.txt:
# documentation is an array (default []), tests a feature whose
# auto would pull the munit subproject this job has no use for.
meson setup build --prefix=/usr/local -Ddocumentation=[] -Dtests=disabled
ninja -C build
sudo ninja -C build install
sudo ldconfig

- run: pip install -e '.[dev]'

- name: The loader must find exactly the version just built
run: |
python - <<'PY'
from libei import ei, eis, oeffis
for mod in (ei, eis, oeffis):
print(f"{mod.__name__}: {mod.is_available()}")
assert ei.is_available() and eis.is_available(), "the built libei was not found"
PY

# -rs for the same reason as the `test` job: on a floor build the
# version-gated tests skipping is the finding, and the log should name
# every one of them.
- run: python -m pytest -q -rs

build:
runs-on: ubuntu-latest
steps:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ All notable changes to python-libei are recorded here. The format follows

## [Unreleased]

## [0.7.0] - 2026-10-16

### Added

- **A portal session closed from the compositor's side now ends a wait
instead of hanging it.** `InputCaptureSession.wait_for_activation()` and
`wait_for_deactivation()` subscribe to the session object's own
`org.freedesktop.portal.Session::Closed` signal alongside the signal they
wait for, and raise the new typed `PortalSessionClosedError` when it
fires — naming what was being waited for. Before this, a wait with
`timeout=None` on a session the compositor or portal had ended (a
compositor restart, the portal process dying, capture revoked from a
settings panel) blocked forever, indistinguishable from a pointer barrier
nobody had crossed yet. Note `Closed` really is emitted on the session's
own object path — the opposite of `Activated`/`Deactivated`, which fire
on the portal object.
- **A weekly CI job builds libei 1.0.0 and 1.1.0 from source and runs the
suite against them.** The README's "libei 1.0.0 or newer" floor was a
claim nothing executed — development tracks 1.6.x and CI's Ubuntu ships
1.2.1 — so the declared floor now runs for real, with the version-gated
tests skipping loudly as designed.

### Fixed

- **The ABI tests misread upstream's prerelease version numbers.** Debian 13
ships libei 1.3.901 — a snapshot on the way to 1.4 that already exports
the 1.4 symbols — and the "marked functions really are absent from a
library that predates them" pin read 1.3.901 as predating every 1.4
marker, failing on a library whose only sin was being packaged mid-cycle.
A micro of 900 or more is now normalized to the next minor, matching what
such a library actually contains. Found by running the suite across eight
live machines; the binding itself was never wrong, only the test's
reading of the version.

## [0.6.1] - 2026-10-01

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ and why, is in

## Status

Beta (`0.6.1`), published on [PyPI](https://pypi.org/project/python-libei/)
Beta (`0.7.0`), published on [PyPI](https://pypi.org/project/python-libei/)
since `0.1.0`, and **the API is not frozen** — expect renames before 1.0.

The injection path is exercised end to end against the real libraries by the
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/verification.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# What has actually been verified

The package is beta (`0.6.1`) and the API is not frozen — expect renames
The package is beta (`0.7.0`) and the API is not frozen — expect renames
before 1.0. This page is what that qualifier covers, concretely: which paths
have been driven against real libraries, which have only ever been driven
against fakes, and which libei versions the whole thing has met.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "python-libei"
version = "0.6.1"
version = "0.7.0"
description = "Inject, receive and capture input on Wayland from Python: ctypes bindings for libei, libeis and liboeffis, plus the RemoteDesktop and InputCapture portals"
readme = "README.md"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/libei/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
Beta: the API is not frozen.
"""

__version__ = "0.6.1"
__version__ = "0.7.0"

__all__ = ["__version__"]
58 changes: 57 additions & 1 deletion src/libei/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ def __init__(self, step: str, message: str | None = None) -> None:
self.message = message


class PortalSessionClosedError(PortalError):
"""The portal session ended while something was still waiting on it.

The ``org.freedesktop.portal.Session`` interface emits ``Closed`` when
the compositor or the portal ends a session from its side -- a
compositor restart, the portal process dying, a session revoked from a
settings panel. Distinct from :class:`PortalTimeoutError` (the session
is fine, the signal just has not come) and from
:class:`PortalDeniedError` (a request was answered, negatively): here
there is no session left to answer anything, so the wait that raised
this can never be satisfied by waiting longer.
"""

def __init__(self, step: str) -> None:
"""Name what was being waited for when the session went away."""
super().__init__(
f"the portal session was closed while waiting for {step}; "
"the compositor or portal ended it from its side"
)
self.step = step


def _gio() -> tuple[Any, Any] | None:
"""Import Gio and GLib, or return None.

Expand Down Expand Up @@ -1038,6 +1060,27 @@ def _wait_for_signal(
loop = GLib.MainLoop()
result: dict[str, Any] = {}
timed_out = False
session_closed = False

def on_closed(*_args: Any) -> None:
"""End the wait: a closed session can never deliver the signal.

``Closed`` is emitted on the **session object's own path** (unlike
``Activated``/``Deactivated``, which fire on the portal object --
see above), so the subscription below uses ``session_handle`` as
the path and needs no payload filtering: any ``Closed`` there is
this session's. Without this subscription, a wait with
``timeout=None`` on a session the compositor has ended -- a
compositor restart, the portal dying, capture revoked from a
settings panel -- blocked forever, indistinguishable from a signal
that merely had not fired yet.
"""
nonlocal session_closed
if result:
return
logger.debug("session %s closed while waiting for %s", session_handle, signal)
session_closed = True
loop.quit()

def on_signal(
_conn: Any,
Expand Down Expand Up @@ -1086,6 +1129,16 @@ def on_timeout() -> bool:
on_signal,
None,
)
closed_subscription = connection.signal_subscribe(
busname,
_SESSION_INTERFACE,
"Closed",
session_handle,
None,
Gio.DBusSignalFlags.NONE,
on_closed,
None,
)
logger.debug(
"waiting up to %s for %s.%s on %s for session %s",
"forever" if timeout is None else f"{timeout:g}s",
Expand All @@ -1095,7 +1148,7 @@ def on_timeout() -> bool:
session_handle,
)
try:
if not result:
if not result and not session_closed:
timeout_source = None
if timeout is not None:
timeout_source = GLib.timeout_add(int(timeout * 1000), on_timeout)
Expand All @@ -1115,6 +1168,9 @@ def on_timeout() -> bool:
GLib.source_remove(timeout_source)
finally:
connection.signal_unsubscribe(subscription)
connection.signal_unsubscribe(closed_subscription)
if session_closed:
raise PortalSessionClosedError(signal)
if timed_out:
# timed_out is only ever set inside on_timeout, itself only ever
# registered when timeout is not None -- so this always holds, but
Expand Down
15 changes: 13 additions & 2 deletions tests/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ def _declared(prefix: str) -> dict[str, tuple[tuple[type, ...], type | None]]:


def _installed_version(soname: str) -> tuple[int, ...] | None:
"""The version in the loaded library's file name (``libei.so.1.6.0``)."""
"""The version in the loaded library's file name (``libei.so.1.6.0``).

A micro of 900 or more is upstream's prerelease numbering for the *next*
minor -- Debian 13 ships 1.3.901, a snapshot on the way to 1.4 that
already exports the 1.4 symbols -- so it is normalized to that next
minor. Read literally, 1.3.901 "predates" every 1.4 marker while
carrying everything they mark, which failed the absent-function pin
below on a library whose only sin was being packaged mid-cycle.
"""
try:
maps = Path("/proc/self/maps").read_text()
except OSError:
Expand All @@ -106,7 +114,10 @@ def _installed_version(soname: str) -> tuple[int, ...] | None:
for line in maps.splitlines():
found = re.search(rf"/{re.escape(stem)}\.so\.(\d+\.\d+\.\d+)$", line)
if found:
return _version(found.group(1))
major, minor, micro = _version(found.group(1))
if micro >= 900:
return (major, minor + 1, 0)
return (major, minor, micro)
return None


Expand Down
Loading
Loading