Skip to content
Merged
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
18 changes: 9 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
postgresql-version: [12, 13, 14, 15, 16]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
postgresql-version: [14, 15, 16, 17, 18]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
- uses: actions/cache@v5
name: Configure pip caching
with:
path: ~/.cache/pip
Expand All @@ -34,7 +34,7 @@ jobs:
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
- name: Install dependencies
run: |
pip install -e '.[test]'
pip install -e . --group dev
- name: Run tests
env:
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
Expand All @@ -47,12 +47,12 @@ jobs:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v6
with:
python-version: "3.12"
- uses: actions/cache@v2
- uses: actions/cache@v5
name: Configure pip caching
with:
path: ~/.cache/pip
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
postgresql-version: [12, 13, 14, 15, 16]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
postgresql-version: [14, 15, 16, 17, 18]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
- uses: actions/cache@v5
name: Configure pip caching
with:
path: ~/.cache/pip
Expand All @@ -32,7 +32,7 @@ jobs:
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
- name: Install dependencies
run: |
pip install -e '.[test]'
pip install -e . --group dev
- name: Run tests
env:
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
Expand Down
11 changes: 10 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
from django_sql_dashboard.models import Dashboard


def pytest_collection_modifyitems(items):
"""Add django_db marker with databases to tests that need database access."""
for item in items:
fixturenames = getattr(item, "fixturenames", ())
# Tests using client fixtures or dashboard_db need both databases
if any(f in fixturenames for f in ("admin_client", "client", "dashboard_db")):
item.add_marker(pytest.mark.django_db(databases=["default", "dashboard"]))


@pytest.fixture
def dashboard_db(settings, db):
def dashboard_db(settings):
settings.DATABASES["dashboard"]["OPTIONS"] = {
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
}
Expand Down
6 changes: 3 additions & 3 deletions django_sql_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ def _dashboard_index(
},
json_dumps_params={
"indent": 2,
"default": lambda o: o.isoformat()
if hasattr(o, "isoformat")
else str(o),
"default": lambda o: (
o.isoformat() if hasattr(o, "isoformat") else str(o)
),
},
)

Expand Down
28 changes: 7 additions & 21 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
# Contributing

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

cd django-sql-dashboard
python -m venv venv
source venv/bin/activate

Or if you are using `pipenv`:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

## Running the tests

To run the tests:

pytest
uv run pytest

## Generating new migrations

To generate migrations for model changes:

cd test_project
./manage.py makemigrations
uv run ./manage.py makemigrations

## Code style

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.
This library uses [Black](https://github.com/psf/black) for code formatting. You can run it like this:

uv run black .

## Documentation

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

cd docs
pip install -r requirements.txt
make livehtml
uv run --with-requirements requirements.txt make livehtml

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

Expand Down
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
[project]
name = "django-sql-dashboard"
version = "1.2"
description = "Django app for building dashboards using raw SQL queries"
readme = "README.md"
license = "Apache-2.0"
authors = [
{ name = "Simon Willison" }
]
requires-python = ">=3.10"
dependencies = [
"Django>=4.2",
"markdown",
"bleach",
]

[project.urls]
Documentation = "https://django-sql-dashboard.datasette.io/"
Issues = "https://github.com/simonw/django-sql-dashboard/issues"
CI = "https://github.com/simonw/django-sql-dashboard/actions"
Changelog = "https://github.com/simonw/django-sql-dashboard/releases"
Homepage = "https://github.com/simonw/django-sql-dashboard"

[dependency-groups]
dev = [
"black>=22.3.0",
"psycopg2",
"pytest",
"pytest-django>=4.11.1",
"pytest-pythonpath",
"dj-database-url",
"testing.postgresql",
"beautifulsoup4",
"html5lib",
]

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

[tool.hatch.build.targets.wheel]
packages = ["django_sql_dashboard"]

[tool.isort]
profile = "black"
multi_line_output = 3

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.settings"
pythonpath = ["test_project", "pytest_plugins"]
addopts = "-p pytest_use_postgresql"
4 changes: 0 additions & 4 deletions pytest.ini

This file was deleted.

56 changes: 0 additions & 56 deletions setup.py

This file was deleted.