From 8c3c7c0460392c8191b256ce3d7bee876caeb9f7 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sun, 15 Sep 2024 16:26:33 -0400 Subject: [PATCH] feat: convert to a uv based workflow --- .github/workflows/ci.yml | 52 +- .gitignore | 3 + .pre-commit-config.yaml | 8 +- .python-version | 1 + ci/spec.yml | 37 +- config/docker/Dockerfile | 16 +- .../migrations/0010_auto_20240918_1233.py | 28 + intranet/settings/__init__.py | 28 +- intranet/static/js/{game.js => game.min.js} | 0 intranet/templates/bus/game.html | 2 +- pyproject.toml | 95 +- requirements-dev.txt | 5 - requirements.txt | 68 - uv.lock | 2683 +++++++++++++++++ 14 files changed, 2850 insertions(+), 176 deletions(-) create mode 100644 .python-version create mode 100644 intranet/apps/oauth/migrations/0010_auto_20240918_1233.py rename intranet/static/js/{game.js => game.min.js} (100%) delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt create mode 100644 uv.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4932e11996e..4d59c98fded 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,23 +31,19 @@ "uses": "actions/checkout@v2" }, { - "name": "Set up Python ${{ matrix.python-version }}", - "uses": "actions/setup-python@v2", + "name": "Set up uv", + "uses": "astral-sh/setup-uv@v3", "with": { - "python-version": "${{ matrix.python-version }}" + "enable-cache": true } }, { - "name": "Set up pip cache", - "uses": "actions/cache@v2", - "with": { - "path": "~/.cache/pip", - "key": "pip-${{ matrix.python-version }}" - } + "name": "Set up Python ${{ matrix.python-version }}", + "run": "uv python install ${{ matrix.python-version }}" }, { "name": "Set up packages", - "run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" + "run": "set -e\nuv sync --locked\n# change path and env vars\nsource .venv/bin/activate\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" }, { "name": "Copy secret.py", @@ -78,23 +74,19 @@ } }, { - "name": "Set up Python ${{ matrix.python-version }}", - "uses": "actions/setup-python@v2", + "name": "Set up uv", + "uses": "astral-sh/setup-uv@v3", "with": { - "python-version": "${{ matrix.python-version }}" + "enable-cache": true } }, { - "name": "Set up pip cache", - "uses": "actions/cache@v2", - "with": { - "path": "~/.cache/pip", - "key": "pip-${{ matrix.python-version }}" - } + "name": "Set up Python ${{ matrix.python-version }}", + "run": "uv python install ${{ matrix.python-version }}" }, { "name": "Set up packages", - "run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" + "run": "set -e\nuv sync --locked\n# change path and env vars\nsource .venv/bin/activate\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" }, { "name": "Copy secret.py", @@ -179,23 +171,19 @@ "uses": "actions/checkout@v2" }, { - "name": "Set up Python ${{ matrix.python-version }}", - "uses": "actions/setup-python@v2", + "name": "Set up uv", + "uses": "astral-sh/setup-uv@v3", "with": { - "python-version": "${{ matrix.python-version }}" + "enable-cache": true } }, { - "name": "Set up pip cache", - "uses": "actions/cache@v2", - "with": { - "path": "~/.cache/pip", - "key": "pip-${{ matrix.python-version }}" - } + "name": "Set up Python ${{ matrix.python-version }}", + "run": "uv python install ${{ matrix.python-version }}" }, { "name": "Set up packages", - "run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" + "run": "set -e\nuv sync --locked\n# change path and env vars\nsource .venv/bin/activate\necho \"PATH=$PATH\" >> $GITHUB_ENV\n" }, { "name": "Copy secret.py", @@ -224,6 +212,10 @@ "name": "install Kerberos", "run": "sudo apt update\nsudo apt install -y krb5-user\n" }, + { + "name": "Install coverage", + "run": "uv pip install pytest-cov" + }, { "name": "Run tests (Fork)", "if": "github.repository_owner != 'tjcsl'", diff --git a/.gitignore b/.gitignore index 18e47145c08..8fb5400ebac 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ package-lock.json # Virtual environments venv/ .venv/ + +# uv produced requirements.txt (platform dependent) +requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df754f70ded..199bb34cc9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,14 +16,16 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - - id: check-ast - name: Validate Python - - id: trailing-whitespace - id: mixed-line-ending args: ["--fix=lf"] - id: check-toml - id: check-yaml - id: detect-private-key + - repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.4.10 + hooks: + # Update the uv lockfile + - id: uv-lock - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.3.5 hooks: diff --git a/.python-version b/.python-version new file mode 100644 index 00000000000..cc1923a40b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8 diff --git a/ci/spec.yml b/ci/spec.yml index ee902f34ea7..5ad32144528 100644 --- a/ci/spec.yml +++ b/ci/spec.yml @@ -27,12 +27,6 @@ env: node_versions: &node_versions - 12.x - python_setup: &python_setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - repo_setup: &repo_setup name: Set up repo uses: actions/checkout@v2 @@ -43,23 +37,23 @@ env: with: fetch-depth: 0 - setup_pip_cache: &setup_pip_cache - name: Set up pip cache - uses: actions/cache@v2 + setup_uv_cache: &setup_uv_cache + name: Set up uv + uses: astral-sh/setup-uv@v3 with: - path: ~/.cache/pip - key: pip-${{ matrix.python-version }} + enable-cache: true + + python_setup: &python_setup + name: Set up Python ${{ matrix.python-version }} + run: uv python install ${{ matrix.python-version }} setup_packages: &setup_packages name: Set up packages run: | set -e - - pip install -U pip setuptools wheel - pip install -U \ - pre-commit coveralls pyyaml pytest-django - pip install -U -r requirements.txt - + uv sync --locked + # change path and env vars + source .venv/bin/activate echo "PATH=$PATH" >> $GITHUB_ENV .copy_secret: ©_secret @@ -77,8 +71,8 @@ jobs: steps: - *repo_setup + - *setup_uv_cache - *python_setup - - *setup_pip_cache - *setup_packages - *copy_secret @@ -96,8 +90,8 @@ jobs: steps: # We need the full history so we can validate commit messages. - *repo_setup_fetch_all + - *setup_uv_cache - *python_setup - - *setup_pip_cache - *setup_packages - *copy_secret @@ -164,8 +158,8 @@ jobs: steps: - *repo_setup + - *setup_uv_cache - *python_setup - - *setup_pip_cache - *setup_packages - *copy_secret @@ -197,6 +191,9 @@ jobs: sudo apt update sudo apt install -y krb5-user + - name: Install coverage + run: uv pip install pytest-cov + # Tests - name: Run tests (Fork) if: github.repository_owner != 'tjcsl' diff --git a/config/docker/Dockerfile b/config/docker/Dockerfile index 2929ecf8aee..06de9cd4b94 100644 --- a/config/docker/Dockerfile +++ b/config/docker/Dockerfile @@ -1,18 +1,20 @@ FROM python:3.8.19-alpine3.18 -ENV TZ America/New_York -ENV C_FORCE_ROOT true +ENV TZ=America/New_York +ENV C_FORCE_ROOT=true COPY config/krb5.conf /etc/krb5.conf -COPY requirements.txt . -COPY requirements-dev.txt . +COPY pyproject.toml . + +COPY --from=ghcr.io/astral-sh/uv:0.4.10 /uv /bin/uv RUN apk update && \ apk add bash git curl build-base libpq-dev freetype-dev libffi-dev ruby-full libmagic krb5 kinit rsync nodejs npm tzdata libxml2-dev libxslt-dev && \ npm install -g sass && \ ln -s /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ - pip3 install -Ir requirements.txt && \ - pip3 install -Ir requirements-dev.txt && \ - rm requirements.txt requirements-dev.txt + # note that this also includes dev dependencies: pass --no-dev to exclude them + uv sync --no-install-project + +ENV PATH="/.venv/bin:${PATH}" WORKDIR /ion diff --git a/intranet/apps/oauth/migrations/0010_auto_20240918_1233.py b/intranet/apps/oauth/migrations/0010_auto_20240918_1233.py new file mode 100644 index 00000000000..1e88508789a --- /dev/null +++ b/intranet/apps/oauth/migrations/0010_auto_20240918_1233.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.25 on 2024-09-18 16:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('oauth', '0009_cslapplication_post_logout_redirect_uris'), + ] + + operations = [ + migrations.AddField( + model_name='cslapplication', + name='allowed_origins', + field=models.TextField(blank=True, default='', help_text='Allowed origins list to enable CORS, space separated'), + ), + migrations.AddField( + model_name='cslapplication', + name='hash_client_secret', + field=models.BooleanField(default=True), + ), + migrations.AlterField( + model_name='cslapplication', + name='post_logout_redirect_uris', + field=models.TextField(blank=True, default='', help_text='Allowed Post Logout URIs list, space separated'), + ), + ] diff --git a/intranet/settings/__init__.py b/intranet/settings/__init__.py index 3dd7ee6d7c3..e7085ddc203 100644 --- a/intranet/settings/__init__.py +++ b/intranet/settings/__init__.py @@ -3,7 +3,7 @@ import os import re import sys -from typing import Any, Dict, List, Tuple # noqa +from typing import Any, Dict, List import celery.schedules import pytz @@ -12,11 +12,7 @@ from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import LoggingIntegration -from ..utils import helpers # pylint: disable=wrong-import-position # noqa - -if sys.version_info < (3, 5): - # Require Python 3.5+ - raise Exception("Python 3.5 or higher is required.") +from ..utils import helpers # Month (1-indexed) after which a new school year begins # July = 7 @@ -38,24 +34,24 @@ # When school is scheduled to start and end SCHOOL_START_DATE = datetime.date(start_school_year, - 8, 19 # UPDATE THIS! Value when last updated: August 19, 2024 # noqa: E128 -) # noqa: E124 + 8, 19 # UPDATE THIS! Value when last updated: August 19, 2024 +) SCHOOL_END_DATE = datetime.date(end_school_year, - 6, 11 # UPDATE THIS! Value when last updated: June 11, 2025 # noqa: E128 -) # noqa: E124 + 6, 11 # UPDATE THIS! Value when last updated: June 11, 2025 +) # Dates when hoco starts and ends HOCO_START_DATE = datetime.date(start_school_year, - 9, 21 # UPDATE THIS! Value when last updated: September 21, 2024 # noqa: E128 -) # noqa: E124 + 9, 21 # UPDATE THIS! Value when last updated: September 21, 2024 +) HOCO_END_DATE = datetime.date(start_school_year, - 9, 29 # UPDATE THIS! Value when last updated: September 29, 2024 # noqa: E128 -) # noqa: E124 + 9, 29 # UPDATE THIS! Value when last updated: September 29, 2024 +) # Date of tjSTAR TJSTAR_DATE = datetime.date(end_school_year, - 5, 21 # UPDATE THIS! Value when last updated: May 21, 2024 # noqa: E128 -) # noqa: E124 + 5, 21 # UPDATE THIS! Value when last updated: May 21, 2024 +) # When to start showing the tjSTAR banner TJSTAR_BANNER_START_DATE = TJSTAR_DATE - datetime.timedelta(days=4) diff --git a/intranet/static/js/game.js b/intranet/static/js/game.min.js similarity index 100% rename from intranet/static/js/game.js rename to intranet/static/js/game.min.js diff --git a/intranet/templates/bus/game.html b/intranet/templates/bus/game.html index f082382540c..d39d0985d0f 100644 --- a/intranet/templates/bus/game.html +++ b/intranet/templates/bus/game.html @@ -177,7 +177,7 @@

Error

{% block js %} - + {% endblock %}