Skip to content

Commit

Permalink
Move manage.py content to evap.__main__ (#2387)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
niklasmohrin authored Feb 10, 2025
1 parent e1cffa7 commit 5404511
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 18 additions & 0 deletions evap/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import os
import sys

from django.conf import settings
from django.core.management import execute_from_command_line


def main():
assert not settings.configured
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evap.settings")
settings.DATADIR.mkdir(exist_ok=True)
execute_from_command_line(sys.argv)


if __name__ == "__main__":
sys.exit(main())
12 changes: 2 additions & 10 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/usr/bin/env python3

import os
import sys
import runpy

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evap.settings")

from django.conf import settings
from django.core.management import execute_from_command_line

settings.DATADIR.mkdir(exist_ok=True)
execute_from_command_line(sys.argv)
runpy.run_module("evap", run_name="__main__")

0 comments on commit 5404511

Please sign in to comment.