What follow are some suggestions for the coding conventions we should adopt within the Python code of “The Virtual Brain”, hereafter TVB.
When in doubt implementing algorithms from the literature, please follow guidelines described at: http://codecapsule.com/2012/01/18/how-to-implement-a-paper/
The standard reference for Python coding style is the BDFL’s PEP 8:
To ease and simplify the process of attaining a consistent style across the code-base I would suggest we agree upon an automated code checker such as PyLint:
and require as a bare minimum an evaluation of > 7/10. By default, PyLint essentially checks for consistency in line with the PEP 8 specification. However, if there are strong objections to any of the requirements enforced by PyLint, we can always adapt the configuration file to more adequately reflect TVB requirements.
Floating point numbers should always have at least one number before and after the dot. Regexp please ?
We use module level logging, based on the logging mechanism from gemenos, with a fallback to direct use of the python logging package. This means all modules have
from tvb.simulator.common import get_logger
LOG = get_logger
then you can call LOG.error(msg), LOG.warn(msg), LOG.info(msg), etc. as is appropriate. The principle benefit over other ways of keeping track of things (printf debugging, the warning module) is flexibility. Then to distinguish between classes within modules use messages of the form
LOG.debug("%s:a useful message a=%s"%(str(self), self.an_attribute))
which makes use of the “Classes self description”, mentioned above.
# -*- coding: utf-8 -*-
"""
as the construct #!usr/bin/env python is not cross platform.
for more details.
As a means of facilitating convergence on these conventions a template python file should be created for TVB project and be used as a starting point for any TVB Python modules.
As a rough first example see, template_tvb.py