This document provides guidance on developing for this project.
Code should be PEP8 compliant, wherever possible. However, we're a little relaxed when it comes to whitespaces, and enforcing wrapping at column 80 for block comments. The latter addresses situations where URLs and paths just won't nicely fit within 80 columns.
We recommend the flake8
PEP8 linter.
Essentially, everything that can have a docstring, should have a docstring, which mostly captures the spirit of PEP 257 for new code.
PEP 287 specifies use of reStructuredText Docstring formats for docstrings, though it doesn't do a good job of specifying on standardizing docstring content.
Generally, for functions we try to document them with this docstring pattern:
def foo(a, b, c):
""" One liner summary for foo
:param a: does this
:param b: does that
:param c: does something else
:returns: a * b * c
"""
return a * b * c
PEP 484 describes the python3 type hint syntax, and we encourage its use.
(However, we admit at the time of this writing that we, ourselves, are inconsistent in the LEAP implementation, and which we will address at a later point.)
We have an admittedly idiosyncratic standard for including a comment block of this form before functions and classes:
##############################
# Class ExampleClass
##############################
And:
##############################
# Function foo()
##############################
Some editors support a summary window of the entire file, such as sublime and PyCharm, and sometimes those types of comment blocks stand out in those windows to make it easier to pick out module organization.
(We confess we're not consistent in doing this ourselves, but we're trying to get better at enforcement.)
Doctests are a handy way to not only provide examples of use, but provide a simple unit test for a given function. With that in mind, we also encourage the writing of doctests for any new functions.
We also encourage the inclusion of unittests that will be regularly
exercised in our CI pipeline after pushing to the central repository. You
can see examples of existing unit tests in ./tests
.
Note that we also have stochastic unit tests, which are important for evolutionary algorigthms because they're inherently stochastic.
leap_ec.context
to track state that needs to persist outside, say, pipeline
operators or function invocations. If you create a new operator or that
function that relies on leap_ec.context
, please make it the last argument
and have it default to leap_ec.context.context
.