Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yeah #39

Merged
merged 6 commits into from
Oct 1, 2024
Merged

Yeah #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Required
BOT_TOKEN=...
FB_USERNAME=... # username for the filebrowser interface
FB_PASSWORD=... # hash of the password for the filebrowser interface (bcrypt)

# Optional (read the guidelines for more informations)
LOGGER_WEBHOOK=...
CTS_TOKEN=...
OPENWEATHERMAP_API_KEY=...
OPENAI_API_KEY=...
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:

jobs:
check:
name: Execute test, check style, lint...
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: 0.4.0
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install the project
run: uv sync --all-extras --dev
- name: Execute pyright
run: |
uv run pyright src/
- name: Execute ruff
run: |
uv run ruff format --check src/
uv run ruff check

# - name: Install tox
# run: |
# python -m pip install -U pip
# pip install tox
# - name: Test application with tox
# run: |
# tox
# - name: Upload test artifacts
# uses: actions/upload-artifact@v3
# with:
# name: pytest_results
# path: junit/test-results.xml
20 changes: 14 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
resources/personal_informations/*
!resources/personal_informations/example.csv
resources/colloscopes/*
!resources/colloscopes/example.csv
external_data/personal_informations/*
!external_data/personal_informations/example.csv
external_data/colloscopes/*
!external_data/colloscopes/example.csv
data/
resources/colloscope.csv
caddy_config/
filebrowser_config/
Caddyfile
config.toml

.vscode/**
!.vscode/launch.json
!.vscode/tasks.json
.ruff_cache

.vscode/
.fleet/

**/.DS_Store

# Byte-compiled / optimized / DLL files
Expand Down
3 changes: 3 additions & 0 deletions Caddyfile.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://yourdomain.com {
reverse_proxy http://filebrowser:8080
}
36 changes: 25 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
FROM python:3.12-alpine as base
RUN apk update && apk add poppler-utils && apk add build-base
# syntax=docker/dockerfile-upstream:master-labs

FROM python:3.12-alpine AS build
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
ENV PYTHONUNBUFFERED=0
COPY ./requirements.txt /app
RUN pip install -r 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 update && apk add poppler-utils build-base \
&& uv sync --no-dev --locked \
&& :

FROM base as prod
FROM python:3.12.0-alpine AS base
# https://docs.docker.com/reference/dockerfile/#copy---parents
COPY --parents --from=build /app/.venv /
WORKDIR /app
COPY ./src ./
CMD ["python", "./main.py"]
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=0

FROM base AS production
CMD ["python", "./main.py"]

FROM base as debug
FROM base AS debug
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
ENV DEBUG=1
ENV LOG_LEVEL=DEBUG
RUN pip install debugpy
CMD ["python", "-m", "debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", "./main.py"]
# CMD ["python", "./main.py"]
RUN uv pip install debugpy
CMD ["python", "-Xfrozen_modules=off", "-m", "debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", "./main.py"]
4 changes: 4 additions & 0 deletions bin/compose-caddy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Pass all arguments to docker compose with both compose.yml and compose.caddy.yml
docker compose -f compose.yml -f compose.caddy.yml "$@"
14 changes: 14 additions & 0 deletions compose.caddy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
caddy:
image: caddy:latest
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- $PWD/data/caddy_data:/data
- $PWD/caddy_config:/config
File renamed without changes.
30 changes: 30 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
mp2i-bot:
image: airopi/mp2i-bot:latest
user: "1000:1000"
build:
context: .
dockerfile: ./Dockerfile
target: production
env_file:
- .env
init: true
tty: true
restart: no
volumes:
- ./data:/app/data
- ./resources:/app/resources
- ./external_data:/app/external_data
- ./config.toml:/app/config.toml

filebrowser:
image: hurlenko/filebrowser
user: "1000:1000"
volumes:
- ./external_data:/data
- ./filebrowser_config:/config
env_file:
- .env
restart: always
expose:
- 8080
14 changes: 14 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
guild_id = 1015136740127821885
birthday_channel_id = 1015172827650998352

loaded_extensions = [
"weather_icon",
"cts",
"restauration",
"fun",
"mp2i",
"openai_chatbot",
"colloscope_helper",
"birthday",
"admin",
]
16 changes: 0 additions & 16 deletions docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/bot-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- `docs/` : contient des divers explications.
- `readme-images/` : contient des images utilisées dans le readme.
- `resources/` : contient des informations statiques utilisées par le bot.
- `external_data/` : contient des informations gérées via filebrowser, qui sont utilisées par le bot.
- `src/` : contient le code source du bot.
- `/typings` : contient des informations de typage pour certaines dépendances qui n'en ont pas.

Expand Down
117 changes: 95 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,107 @@
[tool.tox] # A better implementation is planned. But this avoid to have an additional `tox.ini` file.
[project]
name = "MP2IBot"
version = "1.0"
dependencies = [
"discord.py",
"httpx",
"beautifulsoup4",
"typing_extensions",
"tzdata",
"Pillow",
"openai",
"fpdf2",
"pdf2image",
]
requires-python = ">=3.12"

[tool.uv]
dev-dependencies = [
# "uv",
"pyright",
"debugpy",
"ruff",
"types-beautifulsoup4",
"tox",
"tox-uv",
]

[tool.tox]
legacy_tox_ini = """
[tox]
skipsdist = true
envlist = py312

[testenv]
deps =
-r requirements.txt
-r requirements-dev.txt
runner = uv-venv-lock-runner
description = run all checks on the code
extras =
dev
commands =
# pytest
black --check src/
bandit -r src/ tests/ -c pyproject.toml
isort ./src/ --check
ruff format --check src
ruff check src
pyright src/
"""

[tool.bandit.assert_used]
skips = ["*/test_*.py", "*/test_*.py"]
[tool.ruff]
line-length = 120
indent-width = 4
target-version = "py312"
src = ["src"]
exclude = ["bin"]

[tool.pytest.ini_options]
pythonpath = ". src"
[tool.ruff.lint]
select = [
"E", # pycodestyle Error
"F", # pyflakes
"UP", # pyupgrade
"SIM", # flake8-simplify
"I", # imports
"S", # bandit (security)
"N", # pep8-naming
"ASYNC", # flake8-async
"C4", # flake8-compehensions
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PIE", # flake8-pie
"PYI", # flake8-pyi
"RSE", # flake8-raise
"SLOT", # flake8-slots
"INT", # flake8-gettext
"TRY", # tryceratops
"FLY", # flynt
"PERF", # Perflint
"FURB", # refurb
"LOG", # flake8-logging
"RUF", # Ruff-specific-rules
# "ERA", # locate commented codes
# "FIX", # locate TODOs and FIXME
# "PTH", # flake8-use-pathlib (maybe todo ?)
# "TID", # flake8-tidy-imports (maybe todo ?)
# "SLF", # flake8-self (managed by pyright)
# "RET", # flake8-return
# "Q", # flake8-quotes
# "T20", # flake8-print
# "DTZ", # flake8-datetimez (TODO)
# "B", # flake8-bugbear
]

[tool.black]
line-length = 120
ignore = [
"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
]
dummy-variable-rgx = '^\*{0,2}(_$|__$|unused_|dummy_)'

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false

[tool.isort]
profile = "black"
combine_as_imports = true
combine_star = true
line_length = 120
[tool.ruff.lint.isort]
combine-as-imports = true

[tool.pyright]
reportImportCycles = false
[tool.ruff.lint.pyflakes]
extend-generics = ["discord.app_commands.CommandTree"]
6 changes: 0 additions & 6 deletions requirements.dev.txt

This file was deleted.

9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

Loading