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

Switch to uv for package management #1720

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
52 changes: 22 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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'",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ package-lock.json
# Virtual environments
venv/
.venv/

# uv produced requirements.txt (platform dependent)
requirements.txt
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
37 changes: 17 additions & 20 deletions ci/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: &copy_secret
Expand All @@ -77,8 +71,8 @@ jobs:

steps:
- *repo_setup
- *setup_uv_cache
- *python_setup
- *setup_pip_cache
- *setup_packages
- *copy_secret

Expand All @@ -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

Expand Down Expand Up @@ -164,8 +158,8 @@ jobs:

steps:
- *repo_setup
- *setup_uv_cache
- *python_setup
- *setup_pip_cache
- *setup_packages
- *copy_secret

Expand Down Expand Up @@ -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'
Expand Down
16 changes: 9 additions & 7 deletions config/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
93 changes: 67 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ readme = "README.rst"
authors = [
{name = "The TJHSST Computer Systems Lab", email = "[email protected]"}
]
requires-python = ">=3.8"
version = "1.0"
dynamic = ["dependencies"]
requires-python = ">=3.8,<3.13"
version = "1.0.0"
license = { text = "GPLv2+" }
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand All @@ -16,32 +15,74 @@ classifiers=[
"Programming Language :: Python :: 3.8",
"Framework :: Django :: 3.2",
]
dependencies = [
"argon2-cffi>=23.1.0",
"babel>=2.16.0",
"bcrypt>=4.2.0",
"beautifulsoup4~=4.11",
"bleach~=5.0",
"celery~=5.2",
"channels-redis~=3.4",
"django-cacheops~=7.0",
"django-cors-headers~=3.13",
"django-debug-toolbar~=3.6",
"django-extensions~=3.2",
"django-formtools~=2.3",
"django-inline-svg~=0.1",
"django-maintenance-mode~=0.16",
"django-oauth-toolkit~=2.3",
"django-pipeline~=2.0",
"django-prometheus~=2.2",
"django-redis-cache~=3.0",
"django-redis-sessions~=0.6",
"django-referrer-policy>=1.0",
"django-requestlogging-redux~=1.2",
"django-simple-history~=3.1",
"django-user-agents~=0.4",
"django-widget-tweaks~=1.4",
"djangorestframework~=3.14",
"django~=3.2",
"flower>=2.0.1",
"gunicorn~=22.0",
"hiredis~=2.0",
"lxml>=5.3.0",
"pexpect~=4.8",
"prometheus-client~=0.17",
"psycopg2~=2.9",
"pycryptodome~=3.19",
"pyrankvote~=2.0.5",
"pysftp~=0.2",
"python-dateutil~=2.8",
"python-magic~=0.4",
"python-pam~=2.0",
"reportlab~=3.6",
"requests-oauthlib~=1.3",
"requests~=2.32",
"sentry-sdk~=1.15",
"six~=1.16",
"vine>=5.1.0",
"xhtml2pdf~=0.2",
]

[project.urls]
Repository = "https://github.com/tjcsl/ion"
[tool.setuptools]

[tool.uv]
dev-dependencies = [
"pre-commit>=3.5.0",
"pytest-django>=4.9.0",
"pytest>=8.3.3",
"sphinx-bootstrap-theme>=0.8.1",
"sphinx>=7.1.2",
"whitenoise>=6.7.0",
]

[tool.hatch.build.targets.wheel]
packages = ["intranet", "migrations"]
[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}
[tool.black]
line-length = 150
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| media
| migrations
| secret.*
| stubs
)/
'''

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
extend-exclude = [
Expand Down
5 changes: 0 additions & 5 deletions requirements-dev.txt

This file was deleted.

Loading
Loading