Skip to content

Commit

Permalink
refactor: update the project
Browse files Browse the repository at this point in the history
  • Loading branch information
AiroPi committed Jan 7, 2025
1 parent 093ac00 commit 5b0777f
Show file tree
Hide file tree
Showing 16 changed files with 655 additions and 178 deletions.
33 changes: 28 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
venv/
.mypy_cache/
.vscode/

__pycache__/
# Application
data/

.DS_Store
readme.html
minesweeper.md

# Environnement
venv/
.venv/
.env

# Tools
.tox/
.ruff_cache

# IDEs
.vscode/

.fleet/

# Builds
*.egg-info/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# MacOS
**/.DS_Store

# Exceptions
37 changes: 17 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
# syntax=docker/dockerfile-upstream:master-labs

FROM python:3.12.0-alpine as build
FROM python:3.12-alpine AS build
ARG EXTRA_DEBUG=""
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY ./resources ./
RUN --mount=type=cache,target=/var/cache/apk/ \
--mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
RUN --mount=type=cache,target=/var/cache/apk \
--mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
: \
&& apk add gcc musl-dev linux-headers git \
&& pip install -U pip \
&& pip install -U -r requirements.txt \
&& apk update && apk add gcc musl-dev linux-headers git \
&& uv sync --no-dev --locked $EXTRA_DEBUG \
&& :

FROM python:3.12.0-alpine as base
COPY --parents --from=build /opt/venv /
FROM python:3.12-alpine AS base
# https://docs.docker.com/reference/dockerfile/#copy---parents
WORKDIR /app
COPY --parents --from=build /app/.venv /
COPY --parents ./resources ./
COPY ./src ./
COPY --parents ./resources ./
ENV PATH="/opt/venv/bin:$PATH"
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=0

FROM base as production
ENV GITHUB_PROFILE_URL="https://github.com/AiroPi"
FROM base AS production
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]


FROM base as debug
FROM base AS debug
COPY ./debug_pages /app/debug_pages
ENV DEBUG=1
ENV LOG_LEVEL=DEBUG
ENV GITHUB_PROFILE_URL="http://localhost/readme.md"
COPY ./readme.html ./
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--reload"]
3 changes: 0 additions & 3 deletions bin/docker-build.sh

This file was deleted.

1 change: 0 additions & 1 deletion bin/docker-start.sh

This file was deleted.

1 change: 0 additions & 1 deletion bin/start.sh

This file was deleted.

8 changes: 0 additions & 8 deletions compose.debug.yml

This file was deleted.

11 changes: 6 additions & 5 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
version: "3"

services:
readme-backend:
# image: airopi/readme-backend
build:
dockerfile: ./Dockerfile
target: production
target: debug
args:
EXTRA_DEBUG: "--extra debug"
develop:
watch:
- action: sync
Expand All @@ -19,5 +18,7 @@ services:
target: /app/readme.example.html
- action: rebuild
path: ./requirements.txt
ports:
- 80:80
environment:
- GITHUB_PROFILE_URL="https://github.com/AiroPi"
GITHUB_PROFILE_URL: "http://localhost/readme.md"
5 changes: 5 additions & 0 deletions deploy/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
readme-backend:
image: ghcr.io/airopi/readme-backend:master
environment:
GITHUB_PROFILE_URL: "https://github.com/AiroPi"
73 changes: 53 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
# https://docs.astral.sh/uv/concepts/projects/config/#configuring-projects
[project]
name = "readme-backend"
version = "1.0"
requires-python = ">=3.12"
dependencies = [
#
"fastapi",
"uvicorn",
"Pillow",
"connect4.py==1.0.3",
"minesweeper @ git+https://github.com/AiroPi/minesweeper",
]


[project.optional-dependencies]
debug = ["markdown"]

# https://docs.astral.sh/uv/concepts/projects/
[tool.uv]
dev-dependencies = [
# "uv",
"pyright",
"ruff",
"tox",
"tox-uv",
"types-Pillow",
]


# https://microsoft.github.io/pyright/#/
[tool.pyright]
typeCheckingMode = "strict"


# https://tox.wiki/en/latest/
[tool.tox]
legacy_tox_ini = """
[tox]
skipsdist = true
envlist = ["py312"]

[tool.tox.env_run_base]
runner = "uv-venv-lock-runner"
description = "run all checks on the code"
extras = ["dev"]
commands = [
#fmt
["ruff", "format", "--check", "src"],
["ruff", "check", "src"],
["pyright", "src"],
]

[testenv]
deps =
-r requirements.txt
-r requirements.dev.txt
commands =
# pytest
ruff format --check src
ruff check src
pyright src/
"""

# https://docs.astral.sh/ruff/
[tool.ruff]
line-length = 120
indent-width = 4
target-version = "py312"
src = ["src"]
exclude = ["bin"]

[tool.ruff.lint]
select = [
Expand Down Expand Up @@ -59,9 +96,9 @@ select = [
]

ignore = [
"E501", # line too long (we relate on the formater)
"N818", # Error suffix for exceptions names
"PIE796", # Enum contains duplicate value
"E501", # line too long (we relate on the formater)
"N818", # Error suffix for exceptions names
# "PIE796", # Enum contains duplicate value
"TRY003", # Avoid specifying long messages outsides the exception class
"ISC001", # To avoid conflicts with the formatter
]
Expand All @@ -74,7 +111,3 @@ skip-magic-trailing-comma = false

[tool.ruff.lint.isort]
combine-as-imports = true

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.in"] }
optional-dependencies.dev = { file = ["requirements.dev.in"] }
5 changes: 0 additions & 5 deletions requirements.dev.in

This file was deleted.

59 changes: 0 additions & 59 deletions requirements.dev.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements.in

This file was deleted.

40 changes: 0 additions & 40 deletions requirements.txt

This file was deleted.

10 changes: 8 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from fastapi import FastAPI
from fastapi.responses import FileResponse, RedirectResponse
from fastapi.responses import HTMLResponse, RedirectResponse

from routers import connect4_router, minesweeper_router

Expand All @@ -21,4 +21,10 @@ def read_root():

@app.get("/readme.md")
def get_readme():
return FileResponse("./readme.html")
from markdown import markdown

with open("./debug_pages/minesweeper.md") as f:
markdown_text = f.read()
return HTMLResponse(markdown(markdown_text))

# return FileResponse("./readme.html")
5 changes: 1 addition & 4 deletions src/routers/minesweeper_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def play(i: int, j: int):
return RedirectResponse(GITHUB_PROFILE_URL)

if flag_mode:
if (i, j) in game.flags:
game.flags.remove((i, j))
else:
game.add_flag(i, j)
game.toggle_flag(i, j)
else:
if (i, j) not in game.flags:
game.play(i, j)
Expand Down
Loading

0 comments on commit 5b0777f

Please sign in to comment.