-
Notifications
You must be signed in to change notification settings - Fork 4
/
manage.py
executable file
·70 lines (53 loc) · 1.97 KB
/
manage.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import warnings
import dotenv
ENV_INFO_FLAG = "--env-info"
def output_env_info():
"""Inspect and output environment diagnostics for help with platform /
environment debugging."""
import pwd
from pathlib import Path
cwd = Path().resolve()
script_path = Path(__file__).resolve()
executable_path = Path(sys.executable).resolve()
path = os.environ.get("PATH")
username = pwd.getpwuid(os.getuid()).pw_name
print("Environment diagnostics")
print("----")
print(f" Current working directory: {cwd}")
print(f" Current script path: {script_path}")
print(f" Python executable path: {executable_path}")
print(f" PATH: {path}")
print(f" username: {username}")
print("----")
# Remove the flag to avoid Django unknown command errors.
sys.argv = [arg for arg in sys.argv if arg != ENV_INFO_FLAG]
def set_django_settings_module():
"""Set the DJANGO_SETTINGS_MODULE env var with an appropriate value."""
in_test = not {"pytest", "test"}.isdisjoint(sys.argv[1:])
in_dev = in_test is False and "DEV" == str(os.environ.get("ENV")).upper()
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"settings.test" if in_test else "settings.dev" if in_dev else "settings",
)
def main():
if ENV_INFO_FLAG in sys.argv:
output_env_info()
set_django_settings_module()
try:
from django.core.management import execute_from_command_line
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
execute_from_command_line(sys.argv)
if __name__ == "__main__":
with warnings.catch_warnings():
warnings.simplefilter("ignore")
dotenv.load_dotenv()
main()