-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
54 lines (40 loc) · 1.45 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
"""Generate migrations for mentions app without installing it in a project."""
import argparse
import sys
from importlib.util import find_spec
from typing import List, Tuple
import django
from django.conf import settings
from django.core.management import execute_from_command_line
extra_apps = []
is_wagtail_installed = find_spec("wagtail") is not None
if is_wagtail_installed:
extra_apps += ["wagtail"]
MIGRATION_SETTINGS = {
"DEBUG": False,
"SECRET_KEY": "django-wm-fake-key",
"INSTALLED_APPS": [
"django.contrib.auth",
"django.contrib.contenttypes",
"mentions",
*extra_apps,
],
"DEFAULT_AUTO_FIELD": "django.db.models.BigAutoField",
}
def parse_args() -> Tuple[argparse.Namespace, List[str]]:
parser = argparse.ArgumentParser()
subs = parser.add_subparsers(dest="command")
makemigrations = subs.add_parser("makemigrations")
makemigrations.add_argument("migration_apps", nargs="*")
known_, remaining_ = parser.parse_known_args()
MIGRATION_SETTINGS["INSTALLED_APPS"] += known_.migration_apps
known_.migration_apps = [x.split(".")[-1] for x in known_.migration_apps]
return known_, remaining_
if __name__ == "__main__":
program = [sys.argv[0]]
args_, remaining = parse_args()
sys.argv = program + remaining
settings.configure(**MIGRATION_SETTINGS)
django.setup()
args = sys.argv + [args_.command] + args_.migration_apps
execute_from_command_line(args)