diff --git a/modules/django.py b/modules/django.py index 058dd78..ef0d8c8 100644 --- a/modules/django.py +++ b/modules/django.py @@ -122,30 +122,55 @@ def manage(args="help", workingdir=None, prefix="", suffix=""): # shell='/bin/bash' in all uses of local! +def coverage_test(): + """ + helper method to determine if coverage config exists and if not print + out an error message + """ + + configuration = env.config + + if configuration.coverage is None: + print("\n\nWARNING! There is no coverage file specified " + "in the virtualenv settings for this branch!") + + print("\ncoverage file settings should resemble the following:\n") + + print("coverage:") + print(" config: setup.cfg") + print(" paths:") + print(" root: share/coverage") + print(" html: htmlcov") + + print("\nExiting.") + + import sys + sys.exit() + + @task def coverage(args="test", workingdir=None, outputdir=None, - coveragerc=False, report=True, html=True): + coveragerc=True, report=True, html=True): """ helper method that uses the coverage package - coveragerc file is only locaterd in share/coverage/setup.cfg + coveragerc file is located in share/coverage/setup.cfg + you can modify this in the virtualenv settings for this branch TODO: test if coverage is installed and if it isn't give an error explaining the problem """ + configuration = env.config + coverage_test() + prefix = "coverage run" suffix = "" - coveragepath = "{projectroot}/share/coverage".format( - projectroot=configuration.paths.project.root, - outputdir=outputdir) - if coveragerc: - prefix += " --rcfile={coveragepath}/setup.cfg".format( - coveragepath=coveragepath) + prefix += " --rcfile=%s" % configuration.coverage.config if report: suffix += " && coverage report" @@ -153,20 +178,11 @@ def coverage(args="test", workingdir=None, outputdir=None, if html: suffix += " && coverage html" - if outputdir: - outputpath = outputdir - - else: - outputpath = coveragepath - - outputpath += "/htmlcov" - suffix += " -d %s" % outputpath + suffix += " -d %s" % configuration.coverage.paths.html if env.debug: print("args: %s" % args) print("workigindir: %s" % args) - print("\noutput directory: %s" % outputdir) - print("full output path: %s" % outputpath) print("\nis report: %s" % report) print("is html: %s" % html) print("\nprefix: %s" % prefix) @@ -743,11 +759,25 @@ def edit(param='help'): django_path=django_path, project_branch=project_branch) + # + # set .coveragerc path and filename + + if param == 'coverage': + coverage_test() + + settings_coveragepath = "{projectroot}/share/coverage/settings.cfg".format( + projectroot=configuration.paths.project.root) + file_debug_handler = configuration.logging.django.handlers.file_debug - # locations = ['gunicorn', 'gunicorn_link', 'gunicorn_build', + # locations = ['coverage', 'gunicorn', 'gunicorn_link', 'gunicorn_build', # 'settings', 'local'] locations = { + 'coverage': { + 'path': configuration.coverage.config, + 'desc': 'coveragerc config file', + }, + 'gunicorn': { 'path': link_path, 'desc': 'gunicorn.conf file', diff --git a/modules/initialize.py b/modules/initialize.py index 3fccbda..1ae3bcd 100644 --- a/modules/initialize.py +++ b/modules/initialize.py @@ -310,6 +310,29 @@ def get_config(branchname): else: dataobject.project.ssh = None + # + # set the coveragerc configuration file + + if 'coverage' in config: + dataobject.addbranch('coverage') + + dataobject.coverage.addbranch('paths') + + dataobject.coverage.paths.root = os.path.join( + dataobject.paths.project.root, + config['coverage']['paths']['root']) + + dataobject.coverage.paths.html = os.path.join( + dataobject.coverage.paths.root, + config['coverage']['paths']['html']) + + dataobject.coverage.config = os.path.join( + dataobject.coverage.paths.root, + config['coverage']['config']) + + else: + dataobject.coverage = None + # # these are the locations of the scripts/conf file both remote and local diff --git a/share/templates/meta/development.yml b/share/templates/meta/development.yml index 5242851..5216894 100644 --- a/share/templates/meta/development.yml +++ b/share/templates/meta/development.yml @@ -31,6 +31,16 @@ maintenance: commands: {reload: supervisorctl reload, start: supervisorctl start, status: supervisorctl status, stop: supervisorctl stop, update: supervisorctl update} execute: local + +# +# uncomment if you have and plan to use coverage python package +# +# coverage: +# config: setup.cfg +# paths: +# root: share/coverage +# html: htmlcov + media: paths: {dynamic: dynamic, root: public/media, static: static} nginx: diff --git a/share/templates/meta/staging.yml b/share/templates/meta/staging.yml index 6cb081f..d598f0e 100644 --- a/share/templates/meta/staging.yml +++ b/share/templates/meta/staging.yml @@ -21,6 +21,16 @@ maintenance: execute: run media: paths: {dynamic: dynamic, root: public/media, static: static} + +# +# uncomment if you have and plan to use coverage python package +# +# coverage: +# config: setup.cfg +# paths: +# root: share/coverage +# html: htmlcov + nginx: paths: {available: sites-available, enabled: sites-enabled, root: /etc/nginx} port: NGINX_PORT