Skip to content

Commit 757e398

Browse files
author
Peter Bengtsson
authored
tips on how to debug with a file (mozilla-services#192)
1 parent b6ffe37 commit 757e398

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ yarn-debug.log*
2121
yarn-error.log*
2222
.docker-build
2323
.python_history
24+
hack.py

docs/dev.rst

+18-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ run the gunicorn workers:
304304

305305
.. code-block:: shell
306306
307-
$ DJANGO_CONFIGURATION=Prodlike docker-compose run --service-ports web web
307+
$ docker-compose run --service-ports --user 0 web bash
308308
309309
This will start 4 ``gunicorn`` workers exposed on ``0.0.0.0:8000`` and
310310
exposed outside of docker onto your host.
@@ -363,3 +363,20 @@ and then run it with extra ``pytest`` parameters. For example:
363363
.. code-block:: shell
364364
365365
$ docker-compose run systemtest tests/systemtest/run_tests.sh -k test_delberately_404ing_and_csv_reporting
366+
367+
Shells and ``hack.py``
368+
======================
369+
370+
There are a couple of good ways to get into the Python environment and
371+
be able to "hack around" and try stuff. For example, you might want to just
372+
poke around in the ORM, or test various performance tricks and as it
373+
gets more complicated it gets messy in a shell. Especially if you want to
374+
re-run something on multiple lines repeatedly.
375+
376+
Instead, copy the file ``hack.py-dist`` to ``hack.py`` and start editing it.
377+
Then, to run it, start a shell and execute it:
378+
379+
.. code-block:: shell
380+
381+
$ make shell
382+
# python hack.py

hack.py-dist

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Development hack tool. This file is meant for developers trying stuff.
3+
Oftentimes, it's enough to start a Python shell, or the Django shell
4+
but that can get cumbersome and it's obviously not editable in your
5+
editor. That's that this file is for.
6+
"""
7+
8+
import os
9+
from django.core.wsgi import get_wsgi_application
10+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tecken.settings')
11+
application = get_wsgi_application() # for django-configurations
12+
# End of boilerplate stuff
13+
14+
15+
# from django.conf import settings
16+
from tecken.something import something

0 commit comments

Comments
 (0)