Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
david-okeke1337 authored and oyeniyipa committed Dec 13, 2024
1 parent 2f01344 commit 1d34a82
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
]
}
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 17 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

35 changes: 35 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1d34a82

Please sign in to comment.