The cms/startup.py and lms/startup.py files were created to
allow us to do a lot of custom initialization around things
like the ModuleStore, monkey-patching, adding MIME types to
our process, etc. As far back as 2017, we recognized that
this was a bad thing, marked these modules as "deprecated",
and started removing things or putting them in the standard
Django locations for them (0279181).
In its current state, these startup modules no longer do any
custom work, and just invoke django.startup(). But this is
meant for running Django code in "standalone" usage, e.g. if
you have a script that isn't a management command but needs
some Django functionality.
The "runserver" command used during development normally
launches a child process to serve requests and knows how to
kill and respawn that process when files are modified, so
that changes are reflected. It can also normally handle the
case where there's a SyntaxError in the child process, and
fixing that error will reload the code again.
Something about running django.startup() manually interferes
with this functionality in "runserver". It still reloads the
code in response to changes, but if the code gets into a
broken state for any reason (like a syntax error), the master
process itself dies. That causes the container to restart,
only to die again shortly afterwards in a loop until the
error is fixed. The container restarts will break any shell
you had opened into the container, as well as any IDE
integrations that connected to that container to access the
files and Python instance.
Getting rid of the custom startup code fixes this and moves
us one small step closer to being a more normal Django
project.
100 lines
3.6 KiB
Python
Executable File
100 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
"""
|
|
Usage: manage.py {lms|cms} [--settings env] ...
|
|
|
|
Run django management commands. Because edx-platform contains multiple django projects,
|
|
the first argument specifies which project to run (cms [Studio] or lms [Learning Management System]).
|
|
|
|
By default, those systems run in with a settings file appropriate for development. However,
|
|
by passing the --settings flag, you can specify what environment specific settings file to use.
|
|
|
|
Any arguments not understood by this manage.py will be passed to django-admin.py
|
|
"""
|
|
# pylint: disable=wrong-import-order, wrong-import-position
|
|
|
|
from openedx.core.lib.logsettings import log_python_warnings
|
|
log_python_warnings()
|
|
|
|
# Patch the xml libs before anything else.
|
|
from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip
|
|
defuse_xml_libs()
|
|
|
|
import os
|
|
import sys
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
def parse_args():
|
|
"""Parse edx specific arguments to manage.py"""
|
|
parser = ArgumentParser()
|
|
subparsers = parser.add_subparsers(title='system', description='edX service to run')
|
|
|
|
lms = subparsers.add_parser(
|
|
'lms',
|
|
help='Learning Management System',
|
|
add_help=False,
|
|
usage='%(prog)s [options] ...'
|
|
)
|
|
lms.add_argument('-h', '--help', action='store_true', help='show this help message and exit')
|
|
lms.add_argument(
|
|
'--settings',
|
|
help="Which django settings module to use under lms.envs. If not provided, the DJANGO_SETTINGS_MODULE "
|
|
"environment variable will be used if it is set, otherwise it will default to lms.envs.devstack_docker")
|
|
lms.add_argument(
|
|
'--service-variant',
|
|
choices=['lms', 'lms-xml', 'lms-preview'],
|
|
default='lms',
|
|
help='Which service variant to run, when using the production environment')
|
|
lms.set_defaults(
|
|
help_string=lms.format_help(),
|
|
settings_base='lms/envs',
|
|
default_settings='lms.envs.devstack_docker',
|
|
)
|
|
|
|
cms = subparsers.add_parser(
|
|
'cms',
|
|
help='Studio',
|
|
add_help=False,
|
|
usage='%(prog)s [options] ...'
|
|
)
|
|
cms.add_argument(
|
|
'--settings',
|
|
help="Which django settings module to use under cms.envs. If not provided, the DJANGO_SETTINGS_MODULE "
|
|
"environment variable will be used if it is set, otherwise it will default to cms.envs.devstack_docker")
|
|
cms.add_argument('-h', '--help', action='store_true', help='show this help message and exit')
|
|
cms.set_defaults(
|
|
help_string=cms.format_help(),
|
|
settings_base='cms/envs',
|
|
default_settings='cms.envs.devstack_docker',
|
|
service_variant='cms',
|
|
)
|
|
|
|
edx_args, django_args = parser.parse_known_args()
|
|
|
|
if edx_args.help:
|
|
print("edX:")
|
|
print(edx_args.help_string)
|
|
|
|
return edx_args, django_args
|
|
|
|
|
|
if __name__ == "__main__":
|
|
edx_args, django_args = parse_args()
|
|
|
|
edx_args_base = edx_args.settings_base.replace('/', '.') + '.'
|
|
if edx_args.settings:
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = edx_args_base + edx_args.settings
|
|
elif os.environ.get("EDX_PLATFORM_SETTINGS") and not os.environ.get("DJANGO_SETTINGS_MODULE"):
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = edx_args_base + os.environ["EDX_PLATFORM_SETTINGS"]
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", edx_args.default_settings)
|
|
os.environ.setdefault("SERVICE_VARIANT", edx_args.service_variant)
|
|
|
|
if edx_args.help:
|
|
print("Django:")
|
|
# This will trigger django-admin.py to print out its help
|
|
django_args.append('--help')
|
|
|
|
from django.core.management import execute_from_command_line
|
|
execute_from_command_line([sys.argv[0]] + django_args)
|