-
Notifications
You must be signed in to change notification settings - Fork 2
/
repl.py
executable file
·31 lines (25 loc) · 976 Bytes
/
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
#!/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(f"from {app}.models import *") # pylint: disable=exec-used # noqa: S102
except ModuleNotFoundError: # noqa: PERF203
pass