-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
37 lines (32 loc) · 1.26 KB
/
manage.py
File metadata and controls
37 lines (32 loc) · 1.26 KB
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
#!/usr/bin/env python
import os
import sys
import tomllib as toml
from pathlib import Path
if __name__ == "__main__":
# Set the project base directory
conf_file = Path(__file__).absolute().parents[0] / ".conf"
# Take environment variables from .conf file
try:
conf = conf_file.read_text()
except FileNotFoundError as e:
raise FileNotFoundError(
f"File not found: {conf_file}. Please create a .conf file with the required settings." # noqa: E501
) from e
try:
conf = toml.loads(conf)["django"]
except toml.TOMLDecodeError as e:
raise toml.TOMLDecodeError(
f"Failed to decode TOML file: {conf_file}. Please check the file format." # noqa: E501
) from e
# set settings file develop/productions/test
os.environ.setdefault("DJANGO_SETTINGS_MODULE", conf["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)