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

Ruff linting/formatting #543

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ab5328e
fix deprecation warnings
glbert-does Nov 17, 2023
86345bd
fix deprecated rexgexp
glbert-does Nov 17, 2023
57d4fd1
fix one test, temporarily turn failing test off
glbert-does Nov 21, 2023
a852a92
providing_args are documentational and are deprecated
glbert-does Nov 21, 2023
70d208e
add migration that was not done for 3rd alt option
glbert-does Nov 21, 2023
548ba3c
remove install_cacheops()
glbert-does Nov 21, 2023
d9cd10c
default_app_config in __init__.py is deprecated
glbert-does Nov 21, 2023
361460a
migrate deprecated fields
glbert-does Nov 22, 2023
4f8aa65
conf.urls.url() is deprecated in favour of urls.re_path()
glbert-does Nov 22, 2023
5c5e931
change some urls to paths
glbert-does Nov 22, 2023
0b49e75
change re_path to more readable path
glbert-does Nov 23, 2023
13f282c
ifequals is deprecated
glbert-does Nov 23, 2023
2b14357
update recaptcha to version 4
glbert-does Nov 23, 2023
a02c11a
update removed django.utils.http functions
glbert-does Nov 23, 2023
9ce14d4
re-enable cacheops, move to django 4.2
glbert-does Nov 23, 2023
f006834
the app is called tournament, not heltour
glbert-does Nov 23, 2023
89598e3
disable cacheops for testing
glbert-does Nov 23, 2023
5787737
add ad-hoc replacement for deactivated test
glbert-does Nov 23, 2023
f3a368d
enable cacheops in default settings
glbert-does Nov 23, 2023
5a5b9b0
fix django 5 deprecation warnings
glbert-does Nov 24, 2023
ae22207
fix broken url for webcal
glbert-does Nov 24, 2023
70a1edc
upgrade to python 3.9
glbert-does Jan 12, 2024
baafb7a
update gitignore
nicwest Jun 23, 2024
b7a2acc
update some out of date dependencies
nicwest Jun 23, 2024
5246a61
simple docker file
nicwest Jun 23, 2024
0cd6cdd
remove loading of local settings based on hostname
nicwest Jun 24, 2024
76cc77e
add static files as it's own image
nicwest Jun 24, 2024
6474bb6
fix static docker things
nicwest Jul 8, 2024
0d2e829
add simple docker compose
nicwest Jul 8, 2024
6ce444f
rationalise settings
nicwest Jul 29, 2024
3d0f3a9
get to the point where it's failing on django 2.2/postrgres issue
nicwest Dec 1, 2024
5f878a0
Merge branch 'django_update' into docker
nicwest Dec 1, 2024
9f67518
fix settings
nicwest Dec 1, 2024
0eef847
add missing CSS files
nicwest Dec 1, 2024
3c575c1
add some makefile stuff
nicwest Dec 2, 2024
9cb5506
set up celery
nicwest Dec 2, 2024
ee61405
wip
nicwest Dec 5, 2024
e888216
api worker
nicwest Dec 15, 2024
c0f70f2
add workflows
nicwest Dec 15, 2024
dbdebf5
fix actions
nicwest Dec 15, 2024
81894f4
fix workflow for testing purposes
nicwest Dec 15, 2024
59bd730
build tag push
nicwest Dec 15, 2024
8efbfa5
log into registry?!
nicwest Dec 15, 2024
f349d22
add test thing
nicwest Dec 15, 2024
38b630e
rename stuff
nicwest Dec 15, 2024
c878e44
apparently we need to install poetry before python setup
nicwest Dec 15, 2024
7557c2d
everything runs in poetry now...
nicwest Dec 15, 2024
ae07e4f
probability of this working is low!
nicwest Dec 15, 2024
67e77c6
fix tagging
nicwest Dec 15, 2024
3f51f1e
fix build
nicwest Dec 15, 2024
ffcf990
add postgres to test services
nicwest Dec 15, 2024
18179e6
fix buildyboi
nicwest Dec 15, 2024
c2a9346
fix build
nicwest Dec 15, 2024
647ad8d
does this fix it? if it does I'm sadge
nicwest Dec 15, 2024
9e57feb
ah it's localhost
nicwest Dec 15, 2024
af7f718
is this nonsense
nicwest Dec 15, 2024
cf59932
map ports
nicwest Dec 15, 2024
8ad7102
apparently we need redis as well!
nicwest Dec 15, 2024
9f53172
update ready for PR
nicwest Dec 15, 2024
17281b7
ruffly working
nicwest Dec 15, 2024
a085b7b
fix circular import
nicwest Dec 15, 2024
4c01c0f
reenable ruff in CI
nicwest Dec 15, 2024
f815117
fix lint workflow
nicwest Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and Push
on:
push:
branch:
- master

jobs:
Build-And-Push:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Get app version
run:
echo "heltour_version=$(grep "^version = \"\(.*\)\"" pyproject.toml | sed 's/^.*"\(.*\)"/\1/')" >> "$GITHUB_ENV"
- name: Build
run: |
docker build --target app -t heltour:latest .
docker build --target static -t heltour-static:latest .
- name: Tag
run: |
docker tag heltour:latest ghcr.io/Lichess4545/heltour:latest
docker tag heltour-static:latest ghcr.io/Lichess4545/heltour-static:latest
docker tag heltour:latest ghcr.io/nicwest/Lichess4545:$heltour_version
docker tag heltour-static:latest ghcr.io/nicwest/Lichess4545-static:$heltour_version
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push
run: |
docker push ghcr.io/Lichess4545/heltour:latest
docker push ghcr.io/Lichess4545/heltour-static:latest
docker push ghcr.io/Lichess4545/heltour:$heltour_version
docker push ghcr.io/Lichess4545/heltour-static:$heltour_version
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Lint and Test
on: [push]
jobs:
Lint-And-Test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ci
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: 'poetry'
- name: Install dependencies
run:
poetry install --with dev
- name: Lint
run: |
poetry run ruff format --check heltour/
poetry run ruff check heltour/
- name: Test
run:
poetry run python manage.py test --settings=heltour.settings_test
env:
DJANGO_DB_HOST: 127.0.0.1
DJANGO_DB_PORT: 5432
DJANGO_DB_NAME: postgres
DJANGO_DB_USER: postgres
DJANGO_DB_PASS: ci
DJANGO_CACHE_URL: redis://127.0.0.1:6379/1
DJANGO_CACHEOPS_URL: redis://127.0.0.1:6379/1
CELERY_BROKER_URL: redis://127.0.0.1:6379/2
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
*.pyc
env
venv
.project
.pydevproject
/static
/media
certs
celerybeat-schedule
celerybeat-schedule.db
*eclipse*
data
.idea
.sass-cache
/heltour/tournament/static/tournament/css/*.css
/heltour/tournament/static/tournament/css/*.css.map
javafo.jar
heltour/local/
.DS_Store
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.11-slim AS build
ENV HELTOUR_APP=tournament
WORKDIR /usr/src/heltour

RUN apt-get update && \
apt-get install -y gcc libpq-dev libffi-dev && \
apt-get clean

RUN pip install poetry
RUN poetry config virtualenvs.create false

COPY pyproject.toml poetry.lock ./

RUN poetry install --with server

COPY manage.py .
COPY heltour/ ./heltour

RUN poetry install
RUN python manage.py collectstatic

FROM nginx AS static
COPY --from=build /usr/src/heltour/static /usr/share/nginx/html

FROM build AS app
CMD ["gunicorn", "-t", "300", "-w", "4", "-b", "0.0.0.0:8000", "heltour.wsgi:application"]

57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.PHONY: docker-build server migrate collectstatic init docker-run up up-deps celery loaddata dbshell shell

export DJANGO_DB_HOST=127.0.0.1
export DJANGO_DB_PORT=5432
export DJANGO_DB_NAME=local
export DJANGO_DB_USER=local
export DJANGO_DB_PASS=password
export DJANGO_SETTINGS_MODULE=heltour.settings_development
export DJANGO_CACHE_URL=redis://127.0.0.1:6379/1
export DJANGO_CACHEOPS_URL=redis://127.0.0.1:6379/1
export CELERY_BROKER_URL=redis://127.0.0.1:6379/2

test:
python manage.py test

server:
python manage.py runserver

celery:
celery -A heltour worker -B -c 1 --loglevel INFO -O fair

migrate:
python manage.py migrate

dbshell:
python manage.py dbshell

shell:
python manage.py shell

collectstatic:
python manage.py collectstatic

createsuperuser:
python manage.py createsuperuser

loaddata:
python manage.py loaddata users leagues

init: collectstatic migrate createsuperuser

docker-build:
docker build --target app -t lichess4545/heltour:latest .
docker build --target static -t lichess4545/heltour-static:latest .

docker-run:
docker run -p 8000:8000 lichess4545/heltour:latest
docker run -p 8001:80 lichess4545/heltour-static:latest

up:
docker compose up

up-deps:
docker compose up redis postgres

up-deps-d:
docker compose up -d redis postgres
66 changes: 42 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
# heltour
League management software for the Lichess4545 league.

# requirements
* Python
* Pip
* poetry
* Postgres (Ubuntu packages postgresql and postgresql-server-dev-9.5)
* Fabric (pip install fabric)
* Virtualenv (Ubuntu package virtualenv)
* [Sass](https://sass-lang.com/install)
## Setup

# install
These install instructions have been test on Arch and Ubuntu linux. Other OSes should work, but the install may vary slightly.
* [Install docker](https://docs.docker.com/get-started/get-docker/)
* in a terminal run the following command:
```shell
docker compose up -d redis postges
docker compose run web python manage.py migrate --settings=heltour.settings_development
docker compose run web python manage.py createsuperuser --settings=heltour.settings_development
Username (leave blank to use 'root'): admin
Email address: admin@example.com
Password: <put whatever here>
Password (again): <if it complains just ignore it!>
Superuser created successfully.
docker compose up web
```

1. Create a local settings file. In the heltour/local folder, copy one of the existing modules and name it "host_name.py" where "host_name" is your machine's hostname (with non-alphanumeric characters replaced by underscores).
2. `./start.sh`
3. `source env/bin/activate`
4. `fab up`
5. `fab createdb`
6. `fab -R dev latestdb`
8. `fab runserver`
### Optional Components
- To generate pairings, download [JaVaFo](http://www.rrweb.org/javafo/current/javafo.jar) and set JAVAFO_COMMAND to 'java -jar /path/to/javafo.jar'

# development
Use [4545vagrant](https://github.com/lakinwecker/4545vagrant) as development environment.

Ensure that your editor has an [EditorConfig plugin](https://editorconfig.org/#download) enabled.
## Environmental variables

# create admin account
Run `python manage.py createsuperuser` to create a new admin account.
| Name | Default | Description |
|-|-|-|
| `DJANGO_SECRET_KEY` | `abc123` | a super secret key that django needs you to keep safe |
| `DJANGO_DEBUG` | `FALSE` | puts django into debug mode, useful for local developement but definately needs to be off in production |
| `DJANGO_TESTING` | `FALSE` | tells the code we are running tests. |
| `DJANGO_LOGGING_CONFIG` | | django logging config in JSON format. if no config is provided will default to sensible norms |
| `DJANGO_LOGGING_LEVEL` | `DEBUG` | assuming that no logging config is provided, this variable controls the log level of django's logging |
| `DJANGO_DATABASE_CONFIG` | | django database config in JSON format. if no config is provided the application will assume a single postgres database, and look for additional configuration information from the environment |
| `DJANGO_DB_HOST` | `localhost` | the database host |
| `DJANGO_DB_PORT` | `5432` | the database port |
| `DJANGO_DB_NAME` | | the database name |
| `DJANGO_DB_USER` | | the database user |
| `DJANGO_DB_PASS` | | the database password |
| `DJANGO_CACHE_URL` | `redis://localhost:6379/1` | the redis URL for django's caching |
| `DJANGO_CACHEOPS_URL` | `redis://localhost:6379/1` | the redis URL for cacheops |
| `CELERY_BROKER_URL` | `redis://localhost:6379/1` | the redis URL for the celery broker |
| `HELTOUR_LINK_PROTOCOL` | `https` | the protocol to use when making requests to other parts of the application, set to `http` for local development |
| `HELTOUR_APP` | | set to `API_WORKER` to enable the api worker instead of the main web app |
| `HELTOUR_API_WORKER_HOST` | `https://localhost:8800` | the host for the API worker app |
| `HELTOUR_GOOGLE_SERVICE_ACCOUNT_KEYFILE_PATH` | | path to service account key for accessing google services |
| `HELTOUR_SLACK_API_TOKEN_FILE_PATH` | | path to file containing the slack API token |
| `HELTOUR_SLACK_WEBHOOK_FILE_PATH` | | ??? |
| `HELTOUR_LICHESS_API_TOKEN_FILE_PATH` | | path to file containing the lichess API token |
| `HELTOUR_FCM_API_KEY_FILE_PATH` | | ??? |
| `HELTOUR_STAGING` | `False`| indicates that we are in the staging environment (or not!)|

### Optional Components
- To generate pairings, download [JaVaFo](http://www.rrweb.org/javafo/current/javafo.jar) and set JAVAFO_COMMAND to 'java -jar /path/to/javafo.jar'
71 changes: 71 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
services:
web:
build: .
ports:
- "8000:8000"
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
environment:
DJANGO_DB_HOST: postgres
DJANGO_DB_PORT: 5432
DJANGO_DB_USER: local
DJANGO_DB_PASS: password
DJANGO_SETTINGS_MODULE: heltour.settings_development
DJANGO_CACHE_URL: redis://redis:6379/1
DJANGO_CACHEOPS_URL: redis://redis:6379/1
CELERY_BROKER_URL: redis://redis:6379/2
HELTOUR_API_WORKER_HOST: http://apiworker:8000

develop:
watch:
- action: sync
path: .
target: /usr/src/heltour
celery:
build: .
command: ["celery", "-A", "heltour", "worker", "-B", "-c", "1", "--loglevel", "INFO", "-O", "fair"]
environment:
DJANGO_DB_HOST: postgres
DJANGO_DB_PORT: 5432
DJANGO_DB_USER: local
DJANGO_DB_PASS: password
DJANGO_SETTINGS_MODULE: heltour.settings_development
DJANGO_CACHE_URL: redis://redis:6379/1
DJANGO_CACHEOPS_URL: redis://redis:6379/1
CELERY_BROKER_URL: redis://redis:6379/2

develop:
watch:
- action: sync
path: .
target: /usr/src/heltour

apiworker:
build: .
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
environment:
DJANGO_DB_HOST: postgres
DJANGO_DB_PORT: 5432
DJANGO_DB_USER: local
DJANGO_DB_PASS: password
DJANGO_SETTINGS_MODULE: heltour.settings_development
DJANGO_CACHE_URL: redis://redis:6379/1
DJANGO_CACHEOPS_URL: redis://redis:6379/1
CELERY_BROKER_URL: redis://redis:6379/2
HELTOUR_APP: API_WORKER
develop:
watch:
- action: sync
path: .
target: /usr/src/heltour

redis:
image: "redis:alpine"
ports:
- 6379:6379
postgres:
image: "postgres:alpine"
ports:
- 5432:5432
environment:
POSTGRES_USER: local
POSTGRES_PASSWORD: password
9 changes: 5 additions & 4 deletions heltour/api_worker/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf.urls import url
from django.urls import path

from . import views

urlpatterns = [
url(r'^lichessapi/(?P<path>.+)$', views.lichess_api_call, name='lichess_api_call'),
url(r'^watch/$', views.watch, name='watch'),
url(r'^watch/add/$', views.watch_add, name='watch_add'),
path("lichessapi/<path:path>", views.lichess_api_call, name="lichess_api_call"),
path("watch/", views.watch, name="watch"),
path("watch/add/", views.watch_add, name="watch_add"),
]
Loading