Skip to content

Commit

Permalink
Migrate from setuptools setup.py to pyproject.toml, hatch and uv
Browse files Browse the repository at this point in the history
  • Loading branch information
daoo committed Sep 27, 2024
1 parent 74d244e commit 62c4d3e
Show file tree
Hide file tree
Showing 19 changed files with 943 additions and 155 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12.x'
- name: Install uv
run: python -m pip install --upgrade uv
- name: Create venv
run: uv venv
- name: Install requirements
run: uv pip install -r requirements.txt -r requirements-ci.txt
- name: Run ci.sh script
run: ./ci.sh
- uses: astral-sh/setup-uv@v2
- name: Set up python
run: uv python install
- name: Install the project
run: uv sync --all-extras --dev
- name: Run ruff check
run: uv run ruff check bin autodesk tests
- name: Run tests
run: uv run pytest --cov=autodesk --cov-branch --cov-report=term --cov-report=json tests
- name: Run coverage JSON report
run: uv run coverage json
- name: Upload to codecov
uses: codecov/codecov-action@v4
with:
Expand Down
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
*.egg-info/
.coverage
.eggs/
.venv/
.coverage*
__pycache__/
build/
dist/
coverage.json
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ specific scripts on session activation events.
## Installation and setup

The program can be setup on a Windows or a Linux computer using the following
instructions.
instructions. Uses [uv](https://github.com/astral-sh/uv) for project
management.

### Linux Server

Expand All @@ -130,26 +131,20 @@ on Arch Linux:

# pacman -S libusb

Use the following commands to setup the server:
Use the following commands to setup and start the server (in test mode):

$ cd ~/opt
$ git clone https://github.com/daoo/autodesk
$ cd autodesk
$ python -m venv ./.venv
$ ./.venv/bin/python -m pip install --upgrade pip setuptools
$ ./.venv/bin/pip install .

Now the autodesk server can be started in the the shell:

$ ./bin/start-autodesk.sh
$ uv run autodesk

### Linux Client

On Linux, run the `logger.py` script to listen for lock/unlock events via DBus.
Supply it with the URL to the session API endpoint like this (`autodesk` is the
host name of the computer running the server):

$ logger.py http://autodesk/api/session
$ uv run bin/logger.py http://autodesk/api/session

The host name could be localhost if using the previously mentioned FT232H.

Expand All @@ -161,18 +156,14 @@ Download [Zadig](http://zadig.akeo.ie/) and use it to change the driver to
guide](https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h/windows#plug-in-ft232h-and-fix-driver-with-zadig-3-4)
for more information.

Use the following commands to setup the server:
Use the following commands to setup and start the server (in test mode):

$ cd ~/opt
$ git clone https://github.com/daoo/autodesk
$ cd autodesk
$ python -m venv ./.venv
$ ./.venv/Scripts/python -m pip install --upgrade pip setuptools
$ ./.venv/Scripts/pip install .

Now the autodesk server can be started in the shell:
$ uv run autodesk

$ ./bin/start-autodesk.ps1
See [./bin/start-autodesk.ps1](./bin/start-autodesk.ps1) for start-up example.

### Windows Client

Expand Down
52 changes: 52 additions & 0 deletions autodesk/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from aiohttp import web
from autodesk.api import setup_app
from autodesk.application.autodeskservicefactory import AutoDeskServiceFactory
from autodesk.hardware import create_pin_factory
from contextlib import closing
from pandas import Timedelta
import logging
import os
import yaml


def main():
logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s"
)

logger = logging.getLogger("program")

config_path = os.getenv("AUTODESK_CONFIG", "config/testing.yml")
database = os.getenv("AUTODESK_DATABASE", ":memory:")
address = os.getenv("AUTODESK_ADDRESS", "127.0.0.1")
port = int(os.getenv("AUTODESK_PORT", "8080"))

logger.info('Reading config "%s"', config_path)

config = None
with open(config_path, "r") as file:
config = yaml.load(file, Loader=yaml.SafeLoader)

with closing(create_pin_factory(config["hardware"])) as pin_factory:
button_pin = pin_factory.create_input(config["button_pin"])
factory = AutoDeskServiceFactory(
database,
pin_factory,
(
Timedelta(seconds=config["limits"]["down"]),
Timedelta(seconds=config["limits"]["up"]),
),
config["delay"],
(
config["motor_pins"]["down"],
config["motor_pins"]["up"],
),
(
config["light_pins"]["desk"],
config["light_pins"]["session"],
),
)
app = setup_app(button_pin, factory)
web.run_app(app, host=address, port=port)

main()
48 changes: 0 additions & 48 deletions autodesk/program.py

This file was deleted.

8 changes: 8 additions & 0 deletions bin/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/env python
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "pydbus",
# "pygobject",
# "requests",
# ]
# ///

from datetime import datetime
from gi.repository import GLib
Expand Down
4 changes: 1 addition & 3 deletions bin/start-autodesk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ $env:AUTODESK_PORT = "8080"
$env:AUTODESK_CONFIG = ".\\config\\ft232h.yml"
$env:AUTODESK_DATABASE = "$HOME\AppData\Local\autodesk\autodesk.db"

. .\venv\Scripts\activate.ps1

python.exe -m autodesk.program
uv run autodesk
4 changes: 1 addition & 3 deletions bin/start-autodesk.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ export AUTODESK_PORT="8080"
export AUTODESK_CONFIG="./config/ft232h.yml"
export AUTODESK_DATABASE="~/.local/share/autodesk/autodesk.db"

source ./.venv/bin/activate

python -m autodesk.program
uv run autodesk
8 changes: 0 additions & 8 deletions ci.sh

This file was deleted.

38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[project]
name = "autodesk"
version = "1.0.0"
description = "Automatic standing desk controller."
readme = "README.md"
authors = [
{ name = "Daniel Oom", email = "[email protected]" },
]
classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
]
dependencies = [
"aiohttp-jinja2==1.6",
"aiohttp==3.9.5",
"matplotlib==3.9.0",
"numpy==1.26.4",
"pandas==2.2.2",
"pyftdi==0.55.4",
"pyyaml==6.0.1",
]
requires-python = ">=3.12"

[project.urls]
homepage = "https://github.com/daoo/autodesk"

[tool.uv]
dev-dependencies = [
"mock==5.1.0",
"pyright>=1.1.382.post1",
"pytest-aiohttp==1.0.5",
"pytest-asyncio==0.23.7",
"pytest-cov==5.0.0",
"pytest-mock==3.14.0",
"pytest==8.2.1",
"requests==2.32.3",
"ruff>=0.6.8",
]
14 changes: 0 additions & 14 deletions recreate-venv.sh

This file was deleted.

9 changes: 0 additions & 9 deletions requirements-ci.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements-dev.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions setup.cfg

This file was deleted.

27 changes: 0 additions & 27 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/integration/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.fixture
def process():
cmd = ["python3", "-u", "-m", "autodesk.program"]
cmd = ["python3", "-u", "-m", "autodesk"]
env = os.environ.copy()
env["AUTODESK_ADDRESS"] = "127.0.0.1"
env["AUTODESK_CONFIG"] = "config/testing.yml"
Expand Down
Loading

0 comments on commit 62c4d3e

Please sign in to comment.