Skip to content

Commit c264ab9

Browse files
Merge pull request #281 from AndreWohnsland/sqlalchemy
Convert plain SQL to Sqlalchemy
2 parents 5e209c2 + 5bda8b7 commit c264ab9

34 files changed

+2127
-1184
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Linting
1+
name: Code Check
22
on: [pull_request]
33
jobs:
44
ruff:
@@ -24,3 +24,13 @@ jobs:
2424
pip install -r mypy_requirements.txt
2525
pip install pyqt5==5.15.7 pyqt5-qt5==5.15.2
2626
mypy src
27+
pytest:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: ⤵️ Check out code from GitHub
31+
uses: actions/checkout@v4
32+
- name: Install the latest version of uv
33+
uses: astral-sh/setup-uv@v5
34+
- name: 🔍 Run PyTest
35+
run: |
36+
uv run pytest
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ jobs:
3030
run: |
3131
sed -i "/^version = \".*\"$/s/version = \".*\"/version = \"${{ steps.get_version.outputs.version }}\"/" pyproject.toml
3232
33+
- name: Update version in uv.toml
34+
run: |
35+
sed -i "/^version = \".*\"$/s/version = \".*\"/version = \"${{ steps.get_version.outputs.version }}\"/" uv.lock
36+
3337
- name: Commit changes
3438
env:
3539
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-release-run.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test the setup script on the runner
1+
name: Smoke Test the setup script on the runner
22
on:
33
push:
44
branches:
@@ -15,4 +15,23 @@ jobs:
1515
- name: Run setup.sh
1616
run: |
1717
chmod +x scripts/setup.sh
18-
./scripts/setup.sh
18+
./scripts/setup.sh cicd
19+
- name: Start API
20+
run: |
21+
uv run api.py &
22+
sleep 5
23+
- name: Test API
24+
run: |
25+
for i in {1..6}; do
26+
response=$(curl -s -X 'GET' 'http://localhost:8000/api/' -H 'accept: application/json')
27+
echo "Response: $response"
28+
if echo "$response" | grep -q '{"message":"Welcome to CocktailBerry, this API works!"}'; then
29+
echo "API is working correctly"
30+
pkill -f "uv run api.py"
31+
exit 0
32+
fi
33+
sleep 5
34+
done
35+
echo "API did not respond correctly"
36+
pkill -f "uv run api.py"
37+
exit 1

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"[python]": {
2424
"editor.defaultFormatter": "charliermarsh.ruff"
2525
},
26-
"python.analysis.autoImportCompletions": true
26+
"python.analysis.autoImportCompletions": true,
27+
"python.testing.pytestArgs": ["tests"],
28+
"python.testing.unittestEnabled": false,
29+
"python.testing.pytestEnabled": true
2730
}

docs/commands.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,6 @@ The main program will then be started as usual as an full windowed app.
8282
python runme.py switch-back
8383
```
8484

85-
## Updating Local Database
86-
87-
You can use the CLI command to merge the latest recipes in your local database.
88-
To update run the command:
89-
90-
```bash
91-
python runme.py update-database [OPTIONS]
92-
93-
# Options:
94-
# --help Show help
95-
```
96-
97-
This can be useful if your CocktailBerry has been running for quite a while and you want to get more recipes.
98-
The new recipes will be added to your database, including any missing ingredients.
99-
100-
!!! warning "Made many Changes?"
101-
Please take in consideration that if you made a lot of changes, especially renaming your ingredients, this may add existing ingredients under a different name.
102-
It is best to make a backup before running the command, to have the possibility to restore the old state.
103-
The script will also create a local backup, which you can use if you did not backup your data manually.
104-
10585
## Clearing Local Database
10686

10787
There may be CocktailBerry owners, who want to create a complete new database.

docs/troubleshooting.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ In case the machine got a RTC build in and uses it, this option can usually be s
8989
## Get the LED Working
9090

9191
Getting the WS281x to work may be a little bit tricky.
92-
You MUST run the program as root/sudo (`sudo python runme.py`), so you also need to change this in `~/launcher.sh`.
92+
You can either run the program as root/sudo (`sudo python runme.py`), so you also need to change this in `~/launcher.sh`.
9393
If you are using the latest installer, there will be a virtual environment created, so you should use this as root.
94-
This also does not require to reinstall the python packages for the main program.
94+
This also does you require to reinstall the python packages for the main program.
95+
A better way would be to add the user to the gpio/other needed groups, so you can run the program as normal user.
9596

9697
```bash
9798
sudo ~/.env-cocktailberry/bin/python -E runme.py
@@ -315,23 +316,13 @@ Exec=/usr/bin/lxterminal -e /home/pi/launcher.sh
315316

316317
```bash
317318
#!/bin/bash
318-
# launcher.sh for dashboard
319-
# no need for sudo if there were no Numpy import errors
320-
cd /home/pi/CocktailBerry/dashboard/qt-app/
321-
sudo python main.py
319+
# code to start the application, see v1-launcher.sh
322320
```
323321

324-
```bash
325-
#!/bin/bash
326-
# launcher.sh for CocktailBerry
327-
cd /home/pi/CocktailBerry/
328-
python runme.py
329-
```
330-
331-
If your setup is equal to mine (Raspberry Pi, CocktailBerry GitHub cloned to the home (`/home/pi/`) folder) you can also just copy the files and comment/uncomment within the launcher.sh to save some typing:
322+
If your setup is equal to mine (Raspberry Pi, CocktailBerry GitHub cloned to the home folder) you can also just copy the files and comment/uncomment within the launcher.sh to save some typing:
332323

333324
```bash
334-
cp ~/CocktailBerry/scripts/launcher.sh ~/
325+
cp ~/CocktailBerry/scripts/v1-launcher.sh ~/
335326
cp ~/CocktailBerry/scripts/cocktail.desktop /etc/xdg/autostart/
336327
```
337328

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "CocktailBerry"
3-
version = "2.1.1"
3+
version = "2.2.0"
44
description = "A Python and Qt based App for a Cocktail Machine on a Raspberry Pi. Easily serve Cocktails with Raspberry Pi and Python"
55
authors = [{ name= "Andre Wohnsland" , email = "cocktailmakeraw@gmail.com" }]
66
readme = "readme.md"
@@ -22,6 +22,8 @@ dependencies = [
2222
"rpi-ws281x>=5.0.0 ; sys_platform == 'linux'",
2323
"gpiozero>=2.0.1 ; sys_platform == 'linux'",
2424
"python-periphery>=2.4.1",
25+
"sqlalchemy>=2.0.38",
26+
"alembic>=1.14.1",
2527
]
2628
requires-python = ">= 3.9"
2729

@@ -41,6 +43,8 @@ dev-dependencies = [
4143
"mkdocs>=1.6.1",
4244
"mypy>=1.14.1",
4345
"ipykernel>=6.29.5",
46+
"pytest>=8.3.4",
47+
"pytest-cov>=6.0.0",
4448
]
4549
# This is a workaround for the missing support of aarch64 in pyqt5, need to install this over apt +
4650
# include this with system site packages

scripts/setup.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Usage: bash setup.sh [options]
44
# Options:
55
# dashboard: set up dashboard, otherwise will set up CocktailBerry
6-
6+
# cicd: skip some things for cicd
77
is_raspberry_pi() {
88
if grep -q "Raspberry Pi" /proc/device-tree/model 2>/dev/null; then
99
return 0
@@ -21,8 +21,12 @@ is_raspberry_pi5() {
2121
fi
2222
}
2323

24-
echo "> Installing updates, this may take a while..."
25-
sudo apt update && sudo sudo apt -y full-upgrade
24+
if [ "$1" = "cicd" ]; then
25+
echo "> Skipping update process"
26+
else
27+
echo "> Updating system, this may take a while..."
28+
sudo apt update && sudo sudo apt -y full-upgrade
29+
fi
2630

2731
echo "> Installing nmcli, this is needed for wifi setup"
2832
sudo apt install network-manager
@@ -52,10 +56,11 @@ sudo chmod +x /usr/share/applications/cocktail.desktop
5256
echo "> Giving write permission to /etc/wpa_supplicant/wpa_supplicant.conf"
5357
sudo chmod a+w /etc/wpa_supplicant/wpa_supplicant.conf
5458

55-
cd ~/CocktailBerry/ || exit
59+
if [ "$1" != "cicd" ]; then
60+
cd ~/CocktailBerry/ || exit
61+
fi
5662
# creating project venv with uv
5763
echo "> Creating project venv with uv"
58-
# set uv env variable "" to extra index piwheels if rpi
5964
uv venv --system-site-packages --python "$(python -V | awk '{print $2}')" || echo "ERROR: Could not create venv with uv, is uv installed?"
6065

6166
# Making necessary steps for the according program
@@ -86,7 +91,7 @@ if [ "$1" = "dashboard" ]; then
8691
fi
8792
else
8893
echo "> Setting up CocktailBerry"
89-
sudo cp ~/CocktailBerry/scripts/launcher.sh ~/launcher.sh
94+
sudo cp ~/CocktailBerry/scripts/v1-launcher.sh ~/launcher.sh
9095
sudo chmod +x ~/launcher.sh
9196
echo "> Installing PyQt"
9297
sudo apt-get -y install qt5-default pyqt5-dev pyqt5-dev-tools || sudo apt-get -y install python3-pyqt5 || echo "ERROR: Could not install PyQt5"
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#!/bin/bash
2-
# launcher.sh for both, machine and dashboard
3-
# uncomment / comment the according lines
4-
5-
# launcher.sh for dashboard
6-
# This for qt-app (recommended way)
7-
# cd ~/CocktailBerry/dashboard/qt-app/
8-
# python main.py
9-
# This for Dash (WebApp, advanced way)
10-
# cd ~/CocktailBerry/dashboard/frontend/
11-
# gunicorn --workers=5 --threads=1 -b :8050 index:server
12-
132
# Function to create or update the virtual environment if necessary
143
create_or_update_venv() {
154
system_python_version=$(python -V | awk '{print $2}')
@@ -27,7 +16,6 @@ create_or_update_venv() {
2716
fi
2817
}
2918

30-
# launcher.sh for CocktailBerry
3119
export QT_SCALE_FACTOR=1
3220
cd ~/CocktailBerry/ || echo "Did not find ~/CocktailBerry/"
3321
create_or_update_venv

src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal
22

3-
__version__ = "2.1.1"
3+
__version__ = "2.2.0"
44
PROJECT_NAME = "CocktailBerry"
55
MAX_SUPPORTED_BOTTLES = 24
66
SupportedLanguagesType = Literal["en", "de"]

0 commit comments

Comments
 (0)