Commit 7e12e401 by Adam

Merge pull request #5532 from edx/adam/disable-pycontracts-on-startup

disable pycontracts except in development environments (PLAT-122)
parents ed59dfbc 1aba7f81
......@@ -19,6 +19,7 @@ import os
import sys
import importlib
from argparse import ArgumentParser
import contracts
def parse_args():
"""Parse edx specific arguments to manage.py"""
......@@ -41,6 +42,11 @@ def parse_args():
choices=['lms', 'lms-xml', 'lms-preview'],
default='lms',
help='Which service variant to run, when using the aws environment')
lms.add_argument(
'--contracts',
action='store_true',
default=False,
help='Turn on pycontracts for local development')
lms.set_defaults(
help_string=lms.format_help(),
settings_base='lms/envs',
......@@ -59,6 +65,11 @@ def parse_args():
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.dev")
cms.add_argument('-h', '--help', action='store_true', help='show this help message and exit')
cms.add_argument(
'--contracts',
action='store_true',
default=False,
help='Turn on pycontracts for local development')
cms.set_defaults(
help_string=cms.format_help(),
settings_base='cms/envs',
......@@ -86,6 +97,11 @@ if __name__ == "__main__":
os.environ.setdefault("SERVICE_VARIANT", edx_args.service_variant)
enable_contracts = os.environ.get('ENABLE_CONTRACTS', False)
# can override with '--contracts' argument
if not enable_contracts and not edx_args.contracts:
contracts.disable_all()
if edx_args.help:
print "Django:"
# This will trigger django-admin.py to print out its help
......
......@@ -13,7 +13,7 @@ DEFAULT_PORT = {"lms": 8000, "studio": 8001}
DEFAULT_SETTINGS = 'devstack'
def run_server(system, settings=None, port=None, skip_assets=False):
def run_server(system, settings=None, port=None, skip_assets=False, contracts=False):
"""
Start the server for the specified `system` (lms or studio).
`settings` is the Django settings module to use; if not provided, use the default.
......@@ -36,9 +36,12 @@ def run_server(system, settings=None, port=None, skip_assets=False):
if port is None:
port = DEFAULT_PORT[system]
run_process(django_cmd(
system, settings, 'runserver', '--traceback',
'--pythonpath=.', '0.0.0.0:{}'.format(port)))
args = [settings, 'runserver', '--traceback', '--pythonpath=.', '0.0.0.0:{}'.format(port)]
if contracts:
args.append("--contracts")
run_process(django_cmd(system, *args))
@task
......@@ -86,8 +89,14 @@ def devstack(args):
parser = argparse.ArgumentParser(prog='paver devstack')
parser.add_argument('system', type=str, nargs=1, help="lms or studio")
parser.add_argument('--fast', action='store_true', default=False, help="Skip updating assets")
parser.add_argument(
'--no-contracts',
action='store_true',
default=False,
help="Disable contracts. By default, they're enabled in devstack."
)
args = parser.parse_args(args)
run_server(args.system[0], settings='devstack', skip_assets=args.fast)
run_server(args.system[0], settings='devstack', skip_assets=args.fast, contracts=(not args.no_contracts))
@task
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment