Skip to content
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
83 changes: 83 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: CI

on:
pull_request:
workflow_dispatch:

jobs:
pre_commit_checks:
name: Pre-commit checks
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@main

- uses: actions/setup-python@v5
with:
python-version-file: '.python-version'

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Setup uv python environment
run: uv venv

- name: uv lock check
run: uv lock --locked --offline

- name: uv sync
run: uv sync --all-groups --all-extras

- uses: pre-commit/action@main

test:
name: Test (py${{ matrix.python-version }} / dj${{ matrix.django-version }})
runs-on: ubuntu-latest
needs: pre_commit_checks
permissions:
contents: read

strategy:
fail-fast: false
matrix:
include:
- python-version: "3.8"
django-version: "3.2"

- python-version: "3.11"
django-version: "4.2"

- python-version: "3.12"
django-version: "5.2"

- python-version: "3.13"
django-version: "6.0"

env:
TEST_PYTHON_VERSION: ${{ matrix.python-version }}
TEST_DJANGO_VERSION: ${{ matrix.django-version }}

steps:
- uses: actions/checkout@main

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Install package and test deps
run: |
uv sync --all-groups --all-extras

- name: Install Django ${{ matrix.django-version }}
run: uv pip install "django~=${{ matrix.django-version }}"

- name: Run tests
run: uv run pytest tests/ -v --tb=short
11 changes: 11 additions & 0 deletions .github/workflows/git.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint commits

on: [pull_request]

jobs:
lint:
name: Commit Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: toggle-corp/commit-lint@main
58 changes: 58 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Generate release

on:
push:
tags:
- "v*.*.*"

permissions:
contents: write

jobs:
generate-release:
name: Generate release
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set the release version
id: release
shell: bash
run: |
RELEASE_VERSION=${GITHUB_REF:11}

IS_PRERELEASE=false
if [[ "$RELEASE_VERSION" == *dev* ]]; then
IS_PRERELEASE=true
fi

{
echo "release_version=${RELEASE_VERSION}"
echo "is_prerelease=${IS_PRERELEASE}"
} >> "$GITHUB_OUTPUT"

echo "::notice::Release version: ${RELEASE_VERSION}"
echo "::notice::Is prerelease: ${IS_PRERELEASE}"

- name: Generate a changelog
uses: orhun/git-cliff-action@main
id: git-cliff
with:
config: fugit/configs/cliff.toml
args: -vv --latest --no-exec --github-repo ${{ github.repository }} --strip all
env:
GIT_CLIFF__REMOTE__GITHUB__OWNER: toggle-corp
GIT_CLIFF__REMOTE__GITHUB__REPO: toggle-django-utils

- name: Create Github Release
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag'
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: "v${{ steps.release.outputs.release_version }}"
prerelease: ${{ steps.release.outputs.is_prerelease }}
body: ${{ steps.git-cliff.outputs.content }}
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "fugit"]
path = fugit
url = https://github.com/toggle-corp/fugit.git
branch = v0.1.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
]

[tool.uv.sources]
toggle-django-utils = { git = "ssh://git@github.com/toggle-corp/toggle-django-utils", branch = "main" }
toggle-django-utils = { git = "https://github.com/toggle-corp/toggle-django-utils", branch = "main" }
```

---
Expand Down
1 change: 1 addition & 0 deletions fugit
Submodule fugit added at 1460a2
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ name = "toggle-django-utils"
version = "0.1.0"
description = "Shared Django utilities for Toggle projects"
readme = "README.md"
requires-python = ">=3.11,<4"
requires-python = ">=3.8,<4"
license = { text = "Apache-2.0" }
authors = [
{ name = "Toggle developer", email = "dev@togglecorp.com" }
]

dependencies = [
"Django>=4",
"Django>=3.2",
"httpx>=0.28.1",
"redis>=4.0",
"django-redis>=5.3.0,<6"
]

[dependency-groups]
dev = [
"django-stubs",
"colorlog",
"djangorestframework-stubs>=3.15.3",
"types-factory-boy>=0.4.1",
]
test = [
Expand Down
6 changes: 5 additions & 1 deletion tests/test_retry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations

import time
import typing

from pytest_mock import MockerFixture
if typing.TYPE_CHECKING:
from pytest_mock import MockerFixture

from toggle_django_utils.utils.retry import RetryHelper

Expand Down
8 changes: 7 additions & 1 deletion tests/test_wait_for_resources.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from __future__ import annotations

import typing

if typing.TYPE_CHECKING:
from django.conf import LazySettings

from io import StringIO
from typing import Any
from unittest.mock import MagicMock, patch

from django.conf import LazySettings
from django.core.management import call_command
from django.db.utils import OperationalError

Expand Down
Loading
Loading