Skip to content

Commit cbfba6c

Browse files
authored
Update Python and PostgreSQL versions run in matrix tests (#166)
* Update Python and PostgreSQL versions run in matrix tests https://www.postgresql.org/support/versioning/ says that 12 and 13 are no longer supported, 17 and 18 are out. * Bump pytest-django * Use python_paths not site_dirs * Port setup.py to pyproject.toml, switch to uv https://gistpreview.github.io/?354b66dab89c47d7e190b424665ca944/index.html
1 parent 422fce1 commit cbfba6c

8 files changed

Lines changed: 83 additions & 100 deletions

File tree

.github/workflows/publish.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
13-
postgresql-version: [12, 13, 14, 15, 16]
12+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
13+
postgresql-version: [14, 15, 16, 17, 18]
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v6
1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v2
17+
uses: actions/setup-python@v6
1818
with:
1919
python-version: ${{ matrix.python-version }}
20-
- uses: actions/cache@v2
20+
- uses: actions/cache@v5
2121
name: Configure pip caching
2222
with:
2323
path: ~/.cache/pip
@@ -34,7 +34,7 @@ jobs:
3434
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
3535
- name: Install dependencies
3636
run: |
37-
pip install -e '.[test]'
37+
pip install -e . --group dev
3838
- name: Run tests
3939
env:
4040
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
@@ -47,12 +47,12 @@ jobs:
4747
runs-on: ubuntu-latest
4848
needs: [test]
4949
steps:
50-
- uses: actions/checkout@v2
50+
- uses: actions/checkout@v6
5151
- name: Set up Python
52-
uses: actions/setup-python@v2
52+
uses: actions/setup-python@v6
5353
with:
5454
python-version: "3.12"
55-
- uses: actions/cache@v2
55+
- uses: actions/cache@v5
5656
name: Configure pip caching
5757
with:
5858
path: ~/.cache/pip

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
11-
postgresql-version: [12, 13, 14, 15, 16]
10+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
11+
postgresql-version: [14, 15, 16, 17, 18]
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v6
1414
- name: Set up Python ${{ matrix.python-version }}
15-
uses: actions/setup-python@v2
15+
uses: actions/setup-python@v6
1616
with:
1717
python-version: ${{ matrix.python-version }}
18-
- uses: actions/cache@v2
18+
- uses: actions/cache@v5
1919
name: Configure pip caching
2020
with:
2121
path: ~/.cache/pip
@@ -32,7 +32,7 @@ jobs:
3232
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
3333
- name: Install dependencies
3434
run: |
35-
pip install -e '.[test]'
35+
pip install -e . --group dev
3636
- name: Run tests
3737
env:
3838
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}

conftest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
from django_sql_dashboard.models import Dashboard
55

66

7+
def pytest_collection_modifyitems(items):
8+
"""Add django_db marker with databases to tests that need database access."""
9+
for item in items:
10+
fixturenames = getattr(item, "fixturenames", ())
11+
# Tests using client fixtures or dashboard_db need both databases
12+
if any(f in fixturenames for f in ("admin_client", "client", "dashboard_db")):
13+
item.add_marker(pytest.mark.django_db(databases=["default", "dashboard"]))
14+
15+
716
@pytest.fixture
8-
def dashboard_db(settings, db):
17+
def dashboard_db(settings):
918
settings.DATABASES["dashboard"]["OPTIONS"] = {
1019
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
1120
}

django_sql_dashboard/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ def _dashboard_index(
341341
},
342342
json_dumps_params={
343343
"indent": 2,
344-
"default": lambda o: o.isoformat()
345-
if hasattr(o, "isoformat")
346-
else str(o),
344+
"default": lambda o: (
345+
o.isoformat() if hasattr(o, "isoformat") else str(o)
346+
),
347347
},
348348
)
349349

docs/contributing.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
# Contributing
22

3-
To contribute to this library, first checkout the code. Then create a new virtual environment:
3+
To contribute to this library, first checkout the code. Use [uv](https://github.com/astral-sh/uv) to run the tests:
44

55
cd django-sql-dashboard
6-
python -m venv venv
7-
source venv/bin/activate
8-
9-
Or if you are using `pipenv`:
10-
11-
pipenv shell
12-
13-
Now install the dependencies and tests:
14-
15-
pip install -e '.[test]'
16-
17-
## Running the tests
18-
19-
To run the tests:
20-
21-
pytest
6+
uv run pytest
227

238
## Generating new migrations
249

2510
To generate migrations for model changes:
2611

2712
cd test_project
28-
./manage.py makemigrations
13+
uv run ./manage.py makemigrations
2914

3015
## Code style
3116

32-
This library uses [Black](https://github.com/psf/black) for code formatting. The correct version of Black will be installed by `pip install -e '.[test]'` - you can run `black .` in the root directory to apply those formatting rules.
17+
This library uses [Black](https://github.com/psf/black) for code formatting. You can run it like this:
18+
19+
uv run black .
3320

3421
## Documentation
3522

@@ -38,8 +25,7 @@ Documentation for this project uses [MyST](https://myst-parser.readthedocs.io/)
3825
To build the documentation locally, run the following:
3926

4027
cd docs
41-
pip install -r requirements.txt
42-
make livehtml
28+
uv run --with-requirements requirements.txt make livehtml
4329

4430
This will start a live preview server, using [sphinx-autobuild](https://pypi.org/project/sphinx-autobuild/).
4531

pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
[project]
2+
name = "django-sql-dashboard"
3+
version = "1.2"
4+
description = "Django app for building dashboards using raw SQL queries"
5+
readme = "README.md"
6+
license = "Apache-2.0"
7+
authors = [
8+
{ name = "Simon Willison" }
9+
]
10+
requires-python = ">=3.10"
11+
dependencies = [
12+
"Django>=4.2",
13+
"markdown",
14+
"bleach",
15+
]
16+
17+
[project.urls]
18+
Documentation = "https://django-sql-dashboard.datasette.io/"
19+
Issues = "https://github.com/simonw/django-sql-dashboard/issues"
20+
CI = "https://github.com/simonw/django-sql-dashboard/actions"
21+
Changelog = "https://github.com/simonw/django-sql-dashboard/releases"
22+
Homepage = "https://github.com/simonw/django-sql-dashboard"
23+
24+
[dependency-groups]
25+
dev = [
26+
"black>=22.3.0",
27+
"psycopg2",
28+
"pytest",
29+
"pytest-django>=4.11.1",
30+
"pytest-pythonpath",
31+
"dj-database-url",
32+
"testing.postgresql",
33+
"beautifulsoup4",
34+
"html5lib",
35+
]
36+
37+
[build-system]
38+
requires = ["hatchling"]
39+
build-backend = "hatchling.build"
40+
41+
[tool.hatch.build.targets.wheel]
42+
packages = ["django_sql_dashboard"]
43+
144
[tool.isort]
245
profile = "black"
346
multi_line_output = 3
47+
48+
[tool.pytest.ini_options]
49+
DJANGO_SETTINGS_MODULE = "config.settings"
50+
pythonpath = ["test_project", "pytest_plugins"]
51+
addopts = "-p pytest_use_postgresql"

pytest.ini

Lines changed: 0 additions & 4 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)