Skip to content

Commit 5404511

Browse files
authored
Move manage.py content to evap.__main__ (#2387)
This is in preparation for #2328, where we want to include the `manage.py` code, but cannot include the `manage.py` file because it is outside the `evap` module. Using `__main__` allows running management commands with `python -m evap` if evap is installed into the environment. Running `manage.py` still works, as it uses the builtin `runpy` module to simulate running `python -m evap`.
1 parent e1cffa7 commit 5404511

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

evap/__main__.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
6+
from django.conf import settings
7+
from django.core.management import execute_from_command_line
8+
9+
10+
def main():
11+
assert not settings.configured
12+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evap.settings")
13+
settings.DATADIR.mkdir(exist_ok=True)
14+
execute_from_command_line(sys.argv)
15+
16+
17+
if __name__ == "__main__":
18+
sys.exit(main())

manage.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#!/usr/bin/env python3
22

3-
import os
4-
import sys
3+
import runpy
54

6-
if __name__ == "__main__":
7-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evap.settings")
8-
9-
from django.conf import settings
10-
from django.core.management import execute_from_command_line
11-
12-
settings.DATADIR.mkdir(exist_ok=True)
13-
execute_from_command_line(sys.argv)
5+
runpy.run_module("evap", run_name="__main__")

0 commit comments

Comments
 (0)