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
63 changes: 63 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: on push

# yamllint disable-line rule:truthy
on:
push:
branches: [master]

pull_request:
branches: [master]

workflow_dispatch:

jobs:
monkeytype:
runs-on: ubuntu-24.04
container:
image: fedora:41 # CURRENT DEVELOPMENT ENVIRONMENT
steps:
- name: Install dependencies for Fedora
run: >
dnf install -y
bandit
black
git
make
monkeytype
pip
pylint
python3-dbus
python3-dbus-signature-pyparsing
python3-hypothesis
python3-isort
- name: Install hs-dbus-signature
run: pip install --user hs-dbus-signature
- uses: actions/checkout@v4
with:
path: into-dbus-python
- name: Run with monkeytype
run: >
MONKEYTYPE=1
PYTHONPATH=./src:/github/home/.local/lib/python3.13/site-packages
make test
# tests may fail due to timeouts, call traces should be fine
continue-on-error: true
working-directory: into-dbus-python
- name: Apply annotations
run: PYTHONPATH=./src make apply
working-directory: into-dbus-python
- name: Format result
run: make fmt
working-directory: into-dbus-python
- name: Install pyright
run: pip install --user pyright
- name: Lint result
run: >
PATH=${PATH}:/github/home/.local/bin
PYTHONPATH=./src make -f Makefile lint
working-directory: into-dbus-python
continue-on-error: true
- name: Diff the result
run: git diff --exit-code
working-directory: into-dbus-python
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ dist
# vim
*.swo
*.swp

# monkeytype output
monkeytype.sqlite3
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
ifeq ($(origin MONKEYTYPE), undefined)
PYTHON = python3
else
PYTHON = MONKEYTYPE_TRACE_MODULES=into_dbus_python monkeytype run
endif

MONKEYTYPE_MODULES = into_dbus_python._signature

.PHONY: lint
lint:
pylint setup.py
Expand All @@ -13,7 +21,7 @@ lint:

.PHONY: test
test:
python3 -m unittest discover --verbose tests
${PYTHON} -m unittest discover --verbose tests

.PHONY: coverage
coverage:
Expand Down Expand Up @@ -47,3 +55,13 @@ package:
legacy-package:
python3 setup.py build
python3 setup.py install

.PHONY: apply
apply:
@echo "Modules traced:"
@monkeytype list-modules
@echo
@echo "Annotating:"
@for module in ${MONKEYTYPE_MODULES}; do \
monkeytype --verbose apply --sample-count --ignore-existing-annotations $${module} > /dev/null; \
done
9 changes: 7 additions & 2 deletions src/into_dbus_python/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"""
Error hierarchy for xformer generator.
"""
# isort: STDLIB
from typing import Any, Union

# isort: THIRDPARTY
from dbus import Array


class IntoDPError(Exception):
Expand Down Expand Up @@ -47,7 +52,7 @@ class IntoDPUnexpectedValueError(IntoDPRuntimeError):
transformation.
"""

def __init__(self, message, value):
def __init__(self, message: str, value: Any):
"""
Initializer.

Expand Down Expand Up @@ -82,7 +87,7 @@ class IntoDPSignatureError(IntoDPError):
Exception raised when a value does not seem to have a valid signature.
"""

def __init__(self, message, value):
def __init__(self, message: str, value: Union[str, Array]):
"""
Initializer.

Expand Down
5 changes: 4 additions & 1 deletion src/into_dbus_python/_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
Definition of signature method.
"""

# isort: STDLIB
from typing import Any

# isort: THIRDPARTY
import dbus

from ._errors import IntoDPSignatureError


def signature(dbus_object, *, unpack=False):
def signature(dbus_object: Any, *, unpack=False) -> str:
"""
Get the signature of a dbus object.

Expand Down
16 changes: 8 additions & 8 deletions src/into_dbus_python/_xformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# isort: STDLIB
import functools
from collections.abc import Sequence
from typing import Any
from typing import Any, Callable, List, Tuple, Union

# isort: THIRDPARTY
import dbus
Expand All @@ -34,7 +34,7 @@
)


def _wrapper(func):
def _wrapper(func: Callable) -> Callable:
"""
Wraps a generated function so that it catches all unexpected errors and
raises IntoDPSurprisingErrors.
Expand Down Expand Up @@ -80,7 +80,7 @@ class _ToDbusXformer(Parser):

# pylint: disable=too-few-public-methods

def _handle_variant(self):
def _handle_variant(self) -> Tuple[Callable, str]:
"""
Generate the correct function for a variant signature.

Expand Down Expand Up @@ -114,7 +114,7 @@ def the_func(a_tuple, *, variant=0):
return (the_func, "v")

@staticmethod
def _handle_array(toks):
def _handle_array(toks) -> Tuple[Callable, str]:
"""
Generate the correct function for an array signature.

Expand Down Expand Up @@ -177,7 +177,7 @@ def the_array_func(a_list: Sequence[Any], *, variant=0):
) # pragma: no cover

@staticmethod
def _handle_struct(toks):
def _handle_struct(toks) -> Tuple[Callable, str]:
"""
Generate the correct function for a struct signature.

Expand Down Expand Up @@ -220,7 +220,7 @@ def the_func(a_list: Sequence[Any], *, variant=0):
return (the_func, "(" + signature + ")")

@staticmethod
def _handle_base_case(klass, symbol):
def _handle_base_case(klass: Any, symbol: str) -> Callable:
"""
Handle a base case.

Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(self):
_XFORMER = _ToDbusXformer()


def xformers(sig):
def xformers(sig: str) -> List[Union[Tuple[Callable, str], Any]]:
"""
Get the list of xformer functions for the given signature.

Expand All @@ -312,7 +312,7 @@ def xformers(sig):
]


def xformer(signature):
def xformer(signature: str) -> Callable:
"""
Returns a transformer function for the given signature.

Expand Down
Loading