From 4916604332edee95b4318854224b3e4a6624718f Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Fri, 2 Feb 2024 19:59:29 +0000 Subject: [PATCH] feat: Format code with ruff and check JS with prettier (#580) --- .pre-commit-config.yaml | 28 +++++++++++++++++----------- docs/features.rst | 24 ++++++++++++------------ docs/history.rst | 2 +- docs/index.rst | 1 + docs/install.rst | 12 ++++-------- docs/settings.rst | 2 +- ruff.toml | 7 +++++++ 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c28e1f0..a7b5b9af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ ci: - autofix_commit_msg: | - ci: auto fixes from pre-commit hooks + autofix_commit_msg: | + ci: auto fixes from pre-commit hooks - for more information, see https://pre-commit.ci - autofix_prs: false - autoupdate_commit_msg: 'ci: pre-commit autoupdate' - autoupdate_schedule: monthly + for more information, see https://pre-commit.ci + autofix_prs: false + autoupdate_commit_msg: "ci: pre-commit autoupdate" + autoupdate_schedule: monthly default_language_version: python: python3.12 @@ -18,7 +18,7 @@ repos: args: ["--py38-plus"] - repo: https://github.com/adamchainz/django-upgrade - rev: '1.15.0' + rev: "1.15.0" hooks: - id: django-upgrade args: [--target-version, "3.2"] @@ -39,6 +39,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/remastr/pre-commit-django-check-migrations rev: v0.1.0 @@ -50,7 +51,12 @@ repos: - repo: https://github.com/rstcheck/rstcheck rev: v6.2.0 hooks: - - id: rstcheck - additional_dependencies: - - sphinx==6.1.3 - - tomli==2.0.1 + - id: rstcheck + additional_dependencies: + - sphinx==6.1.3 + - tomli==2.0.1 + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0 + hooks: + - id: prettier diff --git a/docs/features.rst b/docs/features.rst index ef02bfb4..be6bedb0 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -40,10 +40,12 @@ Snapshots .. code-block:: python - 'explorer.tasks.snapshot_queries': { - 'task': 'explorer.tasks.snapshot_queries', - 'schedule': crontab(hour=1, minute=0) - } + app.conf.beat_schedule = { + 'explorer.tasks.snapshot_queries': { + 'task': 'explorer.tasks.snapshot_queries', + 'schedule': crontab(hour=1, minute=0) + } + } - Requires celery, obviously. Also uses boto3. All of these deps are optional and can be installed with @@ -94,8 +96,6 @@ Schema Helper set ``EXPLORER_ENABLE_TASKS`` and ``EXPLORER_ASYNC_SCHEMA`` to ``True``. -.. _Template Columns: - Template Columns ---------------- - Let's say you have a query like ``SELECT id, email FROM user`` and @@ -162,10 +162,12 @@ Query Logs .. code-block:: python - 'explorer.tasks.truncate_querylogs': { - 'task': 'explorer.tasks.truncate_querylogs', - 'schedule': crontab(hour=1, minute=0), - 'kwargs': {'days': 30} + app.conf.beat_schedule = { + 'explorer.tasks.truncate_querylogs': { + 'task': 'explorer.tasks.truncate_querylogs', + 'schedule': crontab(hour=1, minute=0), + 'kwargs': {'days': 30} + } } Multiple Connections @@ -179,8 +181,6 @@ Multiple Connections way. See connections.py for more documentation on multi-connection setup. -.. _Power tips: - Power tips ---------- - On the query listing page, focus gets set to a search box so you diff --git a/docs/history.rst b/docs/history.rst index bec23d82..25064996 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1 +1 @@ -.. include:: ../HISTORY.rst \ No newline at end of file +.. include:: ../HISTORY.rst diff --git a/docs/index.rst b/docs/index.rst index 0ae42fd5..59a05877 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,3 +1,4 @@ +.. rstcheck: ignore-next-code-block .. Django SQL Explorer documentation master file, created by sphinx-quickstart on Thu Oct 15 17:39:19 2020. You can adapt this file completely to your liking, but it should at least diff --git a/docs/install.rst b/docs/install.rst index b535b7e1..62b77446 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -27,13 +27,11 @@ If you would also like to support downloading Excel files install with the depen Add to your ``INSTALLED_APPS``, located in the ``settings.py`` file in your project folder: -.. code-block:: python - :emphasize-lines: 3 +.. code-block:: python + :emphasize-lines: 3 INSTALLED_APPS = ( - ..., 'explorer', - ... ) Configure your settings to something like: @@ -54,15 +52,13 @@ Add the following to your urls.py (all Explorer URLs are restricted via the ``EXPLORER_PERMISSION_VIEW`` and ``EXPLORER_PERMISSION_CHANGE`` settings. See Settings section below for further documentation.): -.. code-block:: python - :emphasize-lines: 5 +.. code-block:: python + :emphasize-lines: 5 from django.urls import path, include urlpatterns = [ - ... path('explorer/', include('explorer.urls')), - ... ] If you want to quickly use django-sql-explorer with the existing default diff --git a/docs/settings.rst b/docs/settings.rst index a76e5379..56a480b9 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -159,7 +159,7 @@ A dict granting view permissions on specific queries of the form .. code-block:: python - EXPLORER_GET_USER_QUERY_VIEWS = {userId:[queryId, ...], ...} + EXPLORER_GET_USER_QUERY_VIEWS = {userId: [queryId, ], } **Default Value:** diff --git a/ruff.toml b/ruff.toml index 6ba6e47b..c31d99f2 100644 --- a/ruff.toml +++ b/ruff.toml @@ -55,7 +55,14 @@ combine-as-imports = true known-first-party = [ "explorer", ] +extra-standard-library = ["dataclasses"] [lint.pyupgrade] # Preserve types, even if a file imports `from __future__ import annotations`. keep-runtime-typing = true + +[format] +quote-style = "double" +indent-style = "space" +docstring-code-format = true +docstring-code-line-length = 80