From 1aba7f81b4a9d6cf3b8d5e2192ff9e590a7a27f9 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Thu, 9 Oct 2014 09:47:02 -0400 Subject: [PATCH] disable pycontracts except in development environments (PLAT-122) --- manage.py | 16 ++++++++++++++++ pavelib/servers.py | 19 ++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/manage.py b/manage.py index a5c6e5fb2b..22ec8d8bb7 100755 --- a/manage.py +++ b/manage.py @@ -15,6 +15,7 @@ import os import sys import importlib from argparse import ArgumentParser +import contracts def parse_args(): """Parse edx specific arguments to manage.py""" @@ -37,6 +38,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', @@ -55,6 +61,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', @@ -82,6 +93,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 diff --git a/pavelib/servers.py b/pavelib/servers.py index 8fe31a511b..0f5b7e322c 100644 --- a/pavelib/servers.py +++ b/pavelib/servers.py @@ -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