Skip to content

Commit

Permalink
refactor: general housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Mar 8, 2024
1 parent 4361e5d commit 67ed21f
Show file tree
Hide file tree
Showing 31 changed files with 208 additions and 163 deletions.
55 changes: 31 additions & 24 deletions .github/workflows/integration_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- name: Save Cached Poetry
id: cached-poetry
uses: actions/cache@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}

- uses: actions/setup-python@v5
name: Setup Python
with:
Expand All @@ -30,15 +39,6 @@ jobs:
- name: Install dependencies
run: poetry install --extras=dev --with dev

- name: Save Cached Poetry
id: cached-poetry
uses: actions/cache/save@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('pyproject.toml', 'poetry.lock') }}

type-check:
name: Type Check
needs:
Expand All @@ -61,7 +61,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Create stub files
run: poetry run pyright --createstub kivy
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Lint
run: poetry run poe lint
Expand All @@ -102,7 +102,8 @@ jobs:
- dependencies
runs-on: ubuntu-latest
outputs:
ubo_app_version: ${{ steps.extract_version.outputs.ubo_app_version }}
version: ${{ steps.extract_version.outputs.version }}
name: ${{ steps.extract_version.outputs.name }}
steps:
- uses: actions/checkout@v4
name: Checkout
Expand All @@ -122,16 +123,16 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Build
run: poetry build

- name: Extract Version
id: extract_version
run: |
echo "ubo_app_version=$(poetry run python scripts/print_version.py)" >> "$GITHUB_OUTPUT"
echo "ubo_app_version=$(poetry run python scripts/print_version.py)"
echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT"
echo "name=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- name: Upload wheel
uses: actions/upload-artifact@v4
Expand All @@ -157,8 +158,8 @@ jobs:
- build
runs-on: ubuntu-latest
environment:
name: PyPI
url: https://pypi.org/p/ubo-app
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
permissions:
id-token: write
steps:
Expand Down Expand Up @@ -273,29 +274,35 @@ jobs:
- pypi-publish
- images
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
permissions:
contents: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Procure Lite Image
uses: actions/download-artifact@v4
with:
name: ubo_app-bookworm-lite.img.gz
name:
ubo_app-{{ needs.build.outputs.ubo_app_version
}}-bookworm-lite-arm64.img.gz
path: artifacts

- name: Procure Default Image
uses: actions/download-artifact@v4
with:
name: ubo_app-bookworm.img.gz
name:
ubo_app-{{ needs.build.outputs.ubo_app_version
}}-bookworm-arm64.img.gz
path: artifacts

# TODO
# It is larger than 2GB, so it is not possible to upload it to GitHub
# Looking for a solution to this problem
# - name: Procure Full Image
# uses: actions/download-artifact@v4
# with:
# name: ubo_app-bookworm-full.img.gz
# name: ubo_app-{{ needs.build.outputs.ubo_app_version }}-bookworm-full-arm64.img.gz
# path: artifacts

- name: Procure Wheel
Expand All @@ -314,9 +321,9 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: artifacts/*
tag_name: ${{ needs.build.outputs.ubo_app_version }}
tag_name: ${{ needs.build.outputs.version }}
body: |
Release of version ${{ needs.build.outputs.ubo_app_version }}
PyPI package: https://pypi.org/project/ubo-app/${{ needs.build.outputs.ubo_app_version }}
Release of version ${{ needs.build.outputs.version }}
PyPI package: https://pypi.org/project/${{ needs.build.outputs.name }}/${{ needs.build.outputs.version }}
prerelease: false
draft: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.10.7

- refactor: general housekeeping

## Version 0.10.6

- fix: wireless module now has sufficient privileges
Expand Down
68 changes: 41 additions & 27 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ubo-gui = [
'dev',
] },
]
python-redux = "^0.9.24"
python-redux = "==0.10.4"
pyzbar = "^0.1.9"
sdbus-networkmanager = { version = "^2.0.0", markers = "platform_machine=='aarch64'" }
rpi_ws281x = { version = "^5.0.0", markers = "platform_machine=='aarch64'" }
Expand All @@ -45,6 +45,7 @@ optional = true
pyright = "^1.1.349"
ruff = "^0.2.1"
toml = "^0.10.2"
python-dotenv = "^1.0.1"

[tool.poetry.extras]
default = ['ubo-gui', 'headless-kivy-pi']
Expand Down
24 changes: 12 additions & 12 deletions ubo_app/load_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ def get_filename(self: UboServiceModuleLoader, name: str | None = None) -> str:


class UboServiceLoopLoader(importlib.abc.Loader):
def __init__(self: UboServiceLoopLoader, thread: UboServiceThread) -> None:
self.thread = thread
def __init__(self: UboServiceLoopLoader, service: UboServiceThread) -> None:
self.service = service

def exec_module(self: UboServiceLoopLoader, module: ModuleType) -> None:
cast(Any, module)._create_task = ( # noqa: SLF001
lambda task: self.thread.loop.call_soon_threadsafe(
self.thread.loop.create_task,
lambda task: self.service.loop.call_soon_threadsafe(
self.service.loop.create_task,
task,
)
)
cast(Any, module)._run_in_executor = ( # noqa: SLF001
lambda executor, task, *args: self.thread.loop.run_in_executor(
lambda executor, task, *args: self.service.loop.run_in_executor(
executor,
task,
*args,
)
)

def __repr__(self: UboServiceLoopLoader) -> str:
return f'{self.thread.path}'
return f'{self.service.path}'


class UboServiceFinder(importlib.abc.MetaPathFinder):
Expand All @@ -98,13 +98,13 @@ def find_spec(
)

if matching_path in REGISTERED_PATHS:
thread = REGISTERED_PATHS[matching_path]
module_name = f'{thread.service_uid}:{fullname}'
service = REGISTERED_PATHS[matching_path]
module_name = f'{service.service_uid}:{fullname}'

if fullname == 'ubo_app.utils.loop':
return importlib.util.spec_from_loader(
module_name,
UboServiceLoopLoader(thread),
UboServiceLoopLoader(service),
)

spec = PathFinder.find_spec(
Expand Down Expand Up @@ -232,11 +232,11 @@ def load_services() -> None:
current_path = Path().absolute()
os.chdir(service_path.as_posix())

thread = UboServiceThread(
service = UboServiceThread(
service_path,
service_uid,
)
REGISTERED_PATHS[service_path] = thread
thread.start()
REGISTERED_PATHS[service_path] = service
service.start()

os.chdir(current_path)
4 changes: 2 additions & 2 deletions ubo_app/menu_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
self.ids.right_column.add_widget(volume_widget)

@autorun(lambda state: state.sound.playback_volume)
def sync_output_volume(selector_result: float) -> None:
def _(selector_result: float) -> None:
volume_widget.value = selector_result * 100

@cached_property
Expand Down Expand Up @@ -134,7 +134,7 @@ def handle_title_change(_: MenuWidget, title: str) -> None:
subscribe_event(
KeypadKeyPressEvent,
self.handle_key_press_event,
options=EventSubscriptionOptions(run_async=False),
options=EventSubscriptionOptions(run_async=True),
)

subscribe_event(
Expand Down
3 changes: 1 addition & 2 deletions ubo_app/services/000-sound/audio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import time
import wave

from headless_kivy_pi import IS_RPI

from ubo_app.logging import logger
from ubo_app.utils import IS_RPI

if not IS_RPI:
import sys
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/010-ip/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_ip_addresses(interfaces: Sequence[IpNetworkInterface]) -> list[SubMenuIt
]


def load_ip_addresses(_: IpUpdateRequestEvent | None = None) -> None:
def load_ip_addresses() -> None:
ip_addresses_by_interface = defaultdict(list)
for interface_name, ip_addresses in psutil.net_if_addrs().items():
for address in ip_addresses:
Expand Down
Loading

0 comments on commit 67ed21f

Please sign in to comment.