Skip to content

Commit

Permalink
Houskeeping (#7)
Browse files Browse the repository at this point in the history
* Houskeeping

 + Migrate to uv and pyproejct.toml for environment management
 + Add a docker build
 + Add github actions for basic hiegene: ruff lint, ruff format, pip-audit
 + Update README
  • Loading branch information
iokiwi authored Aug 31, 2024
1 parent f4fe025 commit 97d3147
Show file tree
Hide file tree
Showing 10 changed files with 1,014 additions and 20 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Code Check
on: [ push ]

jobs:
ruff-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: ruff check --output-format=github .

ruff-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Ruff Format Check
run: ruff format --diff

16 changes: 16 additions & 0 deletions .github/workflows/pip-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pip Audit
on: [ push ]

jobs:
pip-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: yezz123/setup-uv@v4
- name: check
run: |
uv run pip-audit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Byte-compiled / optimized / DLL files
.venv
venv/

.mypy_cache/
*pretixdata*
*.xlsx
.ruff_cache/
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://docs.astral.sh/uv/guides/integration/fastapi/#deployment

FROM python:slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

COPY . /app
WORKDIR /app

RUN uv sync --frozen --no-cache

# Run the application.
CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"]
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# pyprize

![Code Style](https://github.com/pythonnz/pyprize/actions/workflows/code-style.yml/badge.svg)
![Dependencies](https://github.com/pythonnz/pyprize/actions/workflows/pip-audit.yml/badge.svg)

Simple prize draw generator for displaying at a conference etc. Runs as a local web app.

## Installation
This project uses [`uv`](https://docs.astral.sh/uv).

```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
## Quick Start

Get data and place it in the root of the pyprize repo. See the section below for detailed information about getting data. E.g.

Expand All @@ -19,18 +18,37 @@ cp candidates.csv.example candidates.csv
Start the server

```bash
fastapi dev app/main.py
uv run fastapi dev
```

Open your browser to http://localhost:8000/

## Usage
### Usage

* Click ⚙️ to go to the admin page and then click `FRESH IMPORT` to reset set the initial state of the database with the data from the filesystem

* Click 🏠 to go back to the main screen

* Progress the prize draw by pressing `spacebar` or `enter` or clicking in the middle of the screen.

* Reset the prize draw by clicking ⚙️ then `FRESH IMPORT`. This will drop the existing database and re import from our data source into a fresh database.

Click ⚙️ to go to the admin page and then click 'Fresh Import' to reset set the initial state of the database with the data from the filesystem
### Building and Running with Docker

Click 🏠 to go back to the main screen
```bash
docker build -t pyprize .
```

Progress the prize draw by pressing `spacebar` or `enter` or clicking in the middle of the screen.
```bash
docker run -p 8000:80 pyprize
```

```bash
docker run \
-v "$(pwd)/candidates.csv.example:/app/candidates.csv" \
-p 8000:80 \
pyprize
```

## Getting data

Expand Down Expand Up @@ -103,6 +121,6 @@ pip install -r requirements-dev.txt
Check and format with ruff

```bash
ruff check .
uv run ruff check .
ruff format .
```
14 changes: 10 additions & 4 deletions candidates.csv.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
John Smith
Jane Doe
German Kaiser
Julius Caesar
Juliet Floyd
Pierce Guerrero
Margot Espinoza
Dallas Chambers
Makayla Berger
Byron Wheeler
Sydney Parker
Caleb Rowland
Mckenna Mercado
Abram Doyle
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "pyprize"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"fastapi[standard]>=0.112.2",
"sqlmodel>=0.0.21",
]

[tool.uv]
dev-dependencies = [
"pip-audit>=2.7.3",
"ruff>=0.6.3",
]
2 changes: 0 additions & 2 deletions requirements-dev.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

893 changes: 893 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 97d3147

Please sign in to comment.