-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.py
executable file
·36 lines (30 loc) · 1.02 KB
/
repl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""Run Django shell with imported modules"""
if __name__ == "__main__":
import os
if not os.environ.get("PYTHONSTARTUP"):
import sys
from subprocess import check_call
base_dir = os.path.dirname(os.path.abspath(__file__)) # noqa: PTH100, PTH120
sys.exit(
check_call(
[ # noqa: S603
os.path.join(base_dir, "manage.py"), # noqa: PTH118
"shell",
*sys.argv[1:],
],
env={
**os.environ,
"PYTHONSTARTUP": os.path.join(base_dir, "repl.py"), # noqa: PTH118
},
)
)
# put imports here used by PYTHONSTARTUP
from django.conf import settings
for app in settings.INSTALLED_APPS:
try: # noqa: SIM105
exec( # pylint: disable=exec-used # noqa: S102
f"from {app}.models import *"
)
except ModuleNotFoundError:
pass