added methods to use coverage in both the initialize and django modules, including in django.edit, a helper test method to see if coverage is specified in the virtual env file for the branch, and commented out code in the virtual env. also django.coverage directly checks the configuration file coverage branch which will be there if coverage is specified in the virutalenv file for the branch

This commit is contained in:
ronny abraham 2023-07-04 03:13:23 +03:00
parent 4f2750ebb4
commit 45ba1ac426
4 changed files with 92 additions and 19 deletions

View file

@ -122,30 +122,55 @@ def manage(args="help", workingdir=None, prefix="", suffix=""):
# shell='/bin/bash' in all uses of local! # 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 @task
def coverage(args="test", workingdir=None, outputdir=None, 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 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 TODO: test if coverage is installed and if it isn't give
an error explaining the problem an error explaining the problem
""" """
configuration = env.config configuration = env.config
coverage_test()
prefix = "coverage run" prefix = "coverage run"
suffix = "" suffix = ""
coveragepath = "{projectroot}/share/coverage".format(
projectroot=configuration.paths.project.root,
outputdir=outputdir)
if coveragerc: if coveragerc:
prefix += " --rcfile={coveragepath}/setup.cfg".format( prefix += " --rcfile=%s" % configuration.coverage.config
coveragepath=coveragepath)
if report: if report:
suffix += " && coverage report" suffix += " && coverage report"
@ -153,20 +178,11 @@ def coverage(args="test", workingdir=None, outputdir=None,
if html: if html:
suffix += " && coverage html" suffix += " && coverage html"
if outputdir: suffix += " -d %s" % configuration.coverage.paths.html
outputpath = outputdir
else:
outputpath = coveragepath
outputpath += "/htmlcov"
suffix += " -d %s" % outputpath
if env.debug: if env.debug:
print("args: %s" % args) print("args: %s" % args)
print("workigindir: %s" % args) print("workigindir: %s" % args)
print("\noutput directory: %s" % outputdir)
print("full output path: %s" % outputpath)
print("\nis report: %s" % report) print("\nis report: %s" % report)
print("is html: %s" % html) print("is html: %s" % html)
print("\nprefix: %s" % prefix) print("\nprefix: %s" % prefix)
@ -743,11 +759,25 @@ def edit(param='help'):
django_path=django_path, django_path=django_path,
project_branch=project_branch) 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 file_debug_handler = configuration.logging.django.handlers.file_debug
# locations = ['gunicorn', 'gunicorn_link', 'gunicorn_build', # locations = ['coverage', 'gunicorn', 'gunicorn_link', 'gunicorn_build',
# 'settings', 'local'] # 'settings', 'local']
locations = { locations = {
'coverage': {
'path': configuration.coverage.config,
'desc': 'coveragerc config file',
},
'gunicorn': { 'gunicorn': {
'path': link_path, 'path': link_path,
'desc': 'gunicorn.conf file', 'desc': 'gunicorn.conf file',

View file

@ -310,6 +310,29 @@ def get_config(branchname):
else: else:
dataobject.project.ssh = None 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 # these are the locations of the scripts/conf file both remote and local

View file

@ -31,6 +31,16 @@ maintenance:
commands: {reload: supervisorctl reload, start: supervisorctl start, status: supervisorctl commands: {reload: supervisorctl reload, start: supervisorctl start, status: supervisorctl
status, stop: supervisorctl stop, update: supervisorctl update} status, stop: supervisorctl stop, update: supervisorctl update}
execute: local execute: local
#
# uncomment if you have and plan to use coverage python package
#
# coverage:
# config: setup.cfg
# paths:
# root: share/coverage
# html: htmlcov
media: media:
paths: {dynamic: dynamic, root: public/media, static: static} paths: {dynamic: dynamic, root: public/media, static: static}
nginx: nginx:

View file

@ -21,6 +21,16 @@ maintenance:
execute: run execute: run
media: media:
paths: {dynamic: dynamic, root: public/media, static: static} 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: nginx:
paths: {available: sites-available, enabled: sites-enabled, root: /etc/nginx} paths: {available: sites-available, enabled: sites-enabled, root: /etc/nginx}
port: NGINX_PORT port: NGINX_PORT