From 1d34a825b4b5f970064e3a0a8514b8750e533dd6 Mon Sep 17 00:00:00 2001 From: David Okeke Date: Fri, 6 Dec 2024 15:43:55 +0000 Subject: [PATCH] initial setup --- .env.example | 1 + README.md | 28 ++++++++++++++++++++++++++++ config/settings/base.py | 2 ++ docker-compose.yml | 3 ++- manage.py | 20 +++++++++++++++++--- poetry.lock | 35 +++++++++++++++++++++++++++++++++++ pyproject.toml | 1 + 7 files changed, 86 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index fd253f5a8..eea46a1ec 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ DJANGO_SETTINGS_MODULE=config.settings.local SECRET_KEY=super-secret-key ALLOWED_HOSTS="*" DEBUG=True +ENABLE_DEBUGPY=false DISABLE_COLLECTSTATIC="0" DATABASE_URL=psql://postgres:postgres@db:5432/fido CACHE_ENDPOINT=redis://redis:6379 diff --git a/README.md b/README.md index 6d904b7d1..af2d9f019 100644 --- a/README.md +++ b/README.md @@ -140,3 +140,31 @@ The names of the management commands denote their function. - Amend the custom_usermodel table to be the same as the new User app one - Add the user app initial migration to the list of django migrations that have been run - Deploy new codebase + +# Setup DebugPy + +Add environment variable in your .env file + + ENABLE_DEBUGPY=True + +Create launch.json file inside .vscode directory + + { + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach (DebugPy)", + "type": "python", + "request": "attach", + "port": 5678, + "host": "localhost", + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app/" + } + ], + "justMyCode": true + }, + ] + } diff --git a/config/settings/base.py b/config/settings/base.py index d63ffebbd..e4a519314 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -33,6 +33,8 @@ DEBUG = env.bool("DEBUG", default=False) +ENABLE_DEBUGPY = env.bool("ENABLE_DEBUGPY", False) + # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env("SECRET_KEY") diff --git a/docker-compose.yml b/docker-compose.yml index c2288ab27..c33d26b2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,8 @@ services: command: python manage.py runserver 0.0.0.0:8000 # command: granian --interface wsgi config.wsgi:application --workers 2 --host 0.0.0.0 --port 8000 ports: - - "0.0.0.0:8000:8000" + - "8000:8000" + - "5678:5678" volumes: - ./:/app/ depends_on: diff --git a/manage.py b/manage.py index 786928154..c479c8cf7 100755 --- a/manage.py +++ b/manage.py @@ -2,8 +2,14 @@ import os import sys +def initialize_debugpy(): + import debugpy -if __name__ == "__main__": + if not os.getenv("RUN_MAIN"): + debugpy.listen(("0.0.0.0", 5678)) + sys.stdout.write("debugpy listening on port 5678...\n") + +def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.prod") try: from django.core.management import execute_from_command_line @@ -13,11 +19,19 @@ # exceptions on Python 2. try: import django - except ImportError: + except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" - ) + ) from exc raise execute_from_command_line(sys.argv) + +if __name__ == "__main__": + ENABLE_DEBUGPY = os.getenv("ENABLE_DEBUGPY") + print("DEBUGPY: ", ENABLE_DEBUGPY) + if ENABLE_DEBUGPY and ENABLE_DEBUGPY.lower() == "true": + initialize_debugpy() + main() + diff --git a/poetry.lock b/poetry.lock index eb3a4dd86..1eaee76fb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -679,6 +679,41 @@ opentelemetry-propagator-aws-xray = ">=1.0.1,<2.0.0" opentelemetry-sdk-extension-aws = ">=2.0.1,<3.0.0" requests = ">=2.31.0,<3.0.0" +[[package]] +name = "debugpy" +version = "1.8.9" +description = "An implementation of the Debug Adapter Protocol for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "debugpy-1.8.9-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:cfe1e6c6ad7178265f74981edf1154ffce97b69005212fbc90ca22ddfe3d017e"}, + {file = "debugpy-1.8.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ada7fb65102a4d2c9ab62e8908e9e9f12aed9d76ef44880367bc9308ebe49a0f"}, + {file = "debugpy-1.8.9-cp310-cp310-win32.whl", hash = "sha256:c36856343cbaa448171cba62a721531e10e7ffb0abff838004701454149bc037"}, + {file = "debugpy-1.8.9-cp310-cp310-win_amd64.whl", hash = "sha256:17c5e0297678442511cf00a745c9709e928ea4ca263d764e90d233208889a19e"}, + {file = "debugpy-1.8.9-cp311-cp311-macosx_14_0_universal2.whl", hash = "sha256:b74a49753e21e33e7cf030883a92fa607bddc4ede1aa4145172debc637780040"}, + {file = "debugpy-1.8.9-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62d22dacdb0e296966d7d74a7141aaab4bec123fa43d1a35ddcb39bf9fd29d70"}, + {file = "debugpy-1.8.9-cp311-cp311-win32.whl", hash = "sha256:8138efff315cd09b8dcd14226a21afda4ca582284bf4215126d87342bba1cc66"}, + {file = "debugpy-1.8.9-cp311-cp311-win_amd64.whl", hash = "sha256:ff54ef77ad9f5c425398efb150239f6fe8e20c53ae2f68367eba7ece1e96226d"}, + {file = "debugpy-1.8.9-cp312-cp312-macosx_14_0_universal2.whl", hash = "sha256:957363d9a7a6612a37458d9a15e72d03a635047f946e5fceee74b50d52a9c8e2"}, + {file = "debugpy-1.8.9-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5e565fc54b680292b418bb809f1386f17081d1346dca9a871bf69a8ac4071afe"}, + {file = "debugpy-1.8.9-cp312-cp312-win32.whl", hash = "sha256:3e59842d6c4569c65ceb3751075ff8d7e6a6ada209ceca6308c9bde932bcef11"}, + {file = "debugpy-1.8.9-cp312-cp312-win_amd64.whl", hash = "sha256:66eeae42f3137eb428ea3a86d4a55f28da9bd5a4a3d369ba95ecc3a92c1bba53"}, + {file = "debugpy-1.8.9-cp313-cp313-macosx_14_0_universal2.whl", hash = "sha256:957ecffff80d47cafa9b6545de9e016ae8c9547c98a538ee96ab5947115fb3dd"}, + {file = "debugpy-1.8.9-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1efbb3ff61487e2c16b3e033bc8595aea578222c08aaf3c4bf0f93fadbd662ee"}, + {file = "debugpy-1.8.9-cp313-cp313-win32.whl", hash = "sha256:7c4d65d03bee875bcb211c76c1d8f10f600c305dbd734beaed4077e902606fee"}, + {file = "debugpy-1.8.9-cp313-cp313-win_amd64.whl", hash = "sha256:e46b420dc1bea64e5bbedd678148be512442bc589b0111bd799367cde051e71a"}, + {file = "debugpy-1.8.9-cp38-cp38-macosx_14_0_x86_64.whl", hash = "sha256:472a3994999fe6c0756945ffa359e9e7e2d690fb55d251639d07208dbc37caea"}, + {file = "debugpy-1.8.9-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:365e556a4772d7d0d151d7eb0e77ec4db03bcd95f26b67b15742b88cacff88e9"}, + {file = "debugpy-1.8.9-cp38-cp38-win32.whl", hash = "sha256:54a7e6d3014c408eb37b0b06021366ee985f1539e12fe49ca2ee0d392d9ceca5"}, + {file = "debugpy-1.8.9-cp38-cp38-win_amd64.whl", hash = "sha256:8e99c0b1cc7bf86d83fb95d5ccdc4ad0586d4432d489d1f54e4055bcc795f693"}, + {file = "debugpy-1.8.9-cp39-cp39-macosx_14_0_x86_64.whl", hash = "sha256:7e8b079323a56f719977fde9d8115590cb5e7a1cba2fcee0986ef8817116e7c1"}, + {file = "debugpy-1.8.9-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6953b335b804a41f16a192fa2e7851bdcfd92173cbb2f9f777bb934f49baab65"}, + {file = "debugpy-1.8.9-cp39-cp39-win32.whl", hash = "sha256:7e646e62d4602bb8956db88b1e72fe63172148c1e25c041e03b103a25f36673c"}, + {file = "debugpy-1.8.9-cp39-cp39-win_amd64.whl", hash = "sha256:3d9755e77a2d680ce3d2c5394a444cf42be4a592caaf246dbfbdd100ffcf7ae5"}, + {file = "debugpy-1.8.9-py2.py3-none-any.whl", hash = "sha256:cc37a6c9987ad743d9c3a14fa1b1a14b7e4e6041f9dd0c8abf8895fe7a97b899"}, + {file = "debugpy-1.8.9.zip", hash = "sha256:1339e14c7d980407248f09824d1b25ff5c5616651689f1e0f0e51bdead3ea13e"}, +] + [[package]] name = "defusedxml" version = "0.7.1" diff --git a/pyproject.toml b/pyproject.toml index ea987c8fc..2f9052631 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ django-log-formatter-asim = "^0.0.6" optional = true [tool.poetry.group.dev.dependencies] +debugpy = "^1.8.9" selenium = "^4.18.1" beautifulsoup4 = "^4.9.1" soupsieve = "^2.5"