From 755a28859a4ad890ca9719bda4c44a6f9d647d51 Mon Sep 17 00:00:00 2001 From: Oleh Paduchak Date: Tue, 7 Jan 2025 16:34:20 +0200 Subject: [PATCH] added django-silk as dev dependency --- app/settings.py | 17 ++++++++++------- app/urls.py | 5 ++++- poetry.lock | 44 +++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/settings.py b/app/settings.py index 063e92b2..eec43218 100644 --- a/app/settings.py +++ b/app/settings.py @@ -83,7 +83,6 @@ # Application definition INSTALLED_APPS = [ - "silk", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", @@ -96,13 +95,7 @@ "addon_service", ] -if DEBUG: - # run under ASGI locally: - INSTALLED_APPS.insert(0, "daphne") # django's reference asgi server - ASGI_APPLICATION = "app.asgi.application" - MIDDLEWARE = [ - "silk.middleware.SilkyMiddleware", "corsheaders.middleware.CorsMiddleware", "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", @@ -113,6 +106,16 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] + +if DEBUG: + # add django-silk to enable profiling + INSTALLED_APPS.append("silk") + MIDDLEWARE.insert(0, "silk.middleware.SilkyMiddleware") + # run under ASGI locally: + INSTALLED_APPS.insert(0, "daphne") # django's reference asgi server + ASGI_APPLICATION = "app.asgi.application" + + ROOT_URLCONF = "app.urls" TEMPLATES = [ diff --git a/app/urls.py b/app/urls.py index f97bacad..1e307e51 100644 --- a/app/urls.py +++ b/app/urls.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib import admin from django.urls import ( include, @@ -14,5 +15,7 @@ RedirectView.as_view(url="/static/gravyvalet_code_docs/index.html"), name="docs-root", ), - path("silk/", include("silk.urls", namespace="silk")), ] + +if "silk" in settings.INSTALLED_APPS: + urlpatterns.append(path("silk/", include("silk.urls", namespace="silk"))) diff --git a/poetry.lock b/poetry.lock index d195bc8f..dc30143b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -199,6 +199,20 @@ files = [ [package.extras] visualize = ["Twisted (>=16.1.1)", "graphviz (>0.5.1)"] +[[package]] +name = "autopep8" +version = "2.3.1" +description = "A tool that automatically formats Python code to conform to the PEP 8 style guide" +optional = false +python-versions = ">=3.8" +files = [ + {file = "autopep8-2.3.1-py2.py3-none-any.whl", hash = "sha256:a203fe0fcad7939987422140ab17a930f684763bf7335bdb6709991dd7ef6c2d"}, + {file = "autopep8-2.3.1.tar.gz", hash = "sha256:8d6c87eba648fdcfc83e29b788910b8643171c395d9c4bcf115ece035b9c9dda"}, +] + +[package.dependencies] +pycodestyle = ">=2.12.0" + [[package]] name = "billiard" version = "4.2.0" @@ -733,6 +747,23 @@ files = [ [package.dependencies] Django = ">=4.2" +[[package]] +name = "django-silk" +version = "5.3.2" +description = "Silky smooth profiling for the Django Framework" +optional = false +python-versions = ">=3.9" +files = [ + {file = "django_silk-5.3.2-py3-none-any.whl", hash = "sha256:49f1caebfda28b1707f0cfef524e0476beb82b8c5e40f5ccff7f73a6b4f6d3ac"}, + {file = "django_silk-5.3.2.tar.gz", hash = "sha256:b0db54eebedb8d16f572321bd6daccac0bd3f547ae2618bb45d96fe8fc02229d"}, +] + +[package.dependencies] +autopep8 = "*" +Django = ">=4.2" +gprof2dot = ">=2017.09.19" +sqlparse = "*" + [[package]] name = "djangorestframework" version = "3.14.0" @@ -919,6 +950,17 @@ files = [ {file = "frozenlist-1.4.1.tar.gz", hash = "sha256:c037a86e8513059a2613aaba4d817bb90b9d9b6b69aace3ce9c877e8c8ed402b"}, ] +[[package]] +name = "gprof2dot" +version = "2024.6.6" +description = "Generate a dot graph from the output of several profilers." +optional = false +python-versions = ">=3.8" +files = [ + {file = "gprof2dot-2024.6.6-py2.py3-none-any.whl", hash = "sha256:45b14ad7ce64e299c8f526881007b9eb2c6b75505d5613e96e66ee4d5ab33696"}, + {file = "gprof2dot-2024.6.6.tar.gz", hash = "sha256:fa1420c60025a9eb7734f65225b4da02a10fc6dd741b37fa129bc6b41951e5ab"}, +] + [[package]] name = "hyperlink" version = "21.0.0" @@ -2209,4 +2251,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "f2198ba94898f4260705bc395c05b70dff5b019786c9c0011da0ba92852f92b4" +content-hash = "9a504ffb729f32f4824b2e07fa523c8bf40f460e3082a51edcf7d1424208e566" diff --git a/pyproject.toml b/pyproject.toml index 84cbfc1d..17e06d9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ flake8 = "^7.1.1" isort = "^5.13.2" pre-commit = "^3.8.0" pdoc = "14.5.1" +django-silk = "^5.3.2" [tool.poetry.group.release.dependencies] sentry-sdk = "2.7.1"