From 53ba1513e27ddbc1fff2d6a4e91fedcda7e33768 Mon Sep 17 00:00:00 2001 From: mprahl Date: Tue, 7 May 2019 13:05:52 -0400 Subject: [PATCH] Add a code style guide --- README.rst | 8 ++++++ docs/CONTRIBUTING.rst | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/README.rst b/README.rst index 0ee73a09..8eff63d9 100644 --- a/README.rst +++ b/README.rst @@ -23,6 +23,14 @@ For a detailed change log, see |docs/CHANGELOG.rst|_. .. |docs/CHANGELOG.rst| replace:: ``docs/CHANGELOG.rst`` .. _docs/CHANGELOG.rst: docs/CHANGELOG.rst +Contributing +============ + +For detailed information on how to contribute, see |docs/CONTRIBUTING.rst|_. + +.. |docs/CONTRIBUTING.rst| replace:: ``docs/CONTRIBUTING.rst`` +.. _docs/CONTRIBUTING.rst: docs/CONTRIBUTING.rst + Supported build systems ======================= diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst index 33871cb6..2da053c3 100644 --- a/docs/CONTRIBUTING.rst +++ b/docs/CONTRIBUTING.rst @@ -17,6 +17,68 @@ Then run the tests with:: $ sudo docker run -t --rm -v $PWD:/src:Z mbs/test +Style Guide +=========== + +Automatically Checked +--------------------- + +The codebase conforms to the style enforced by ``flake8`` with the following exceptions: + +- The maximum line length allowed is 100 characters instead of 80 characters +- The use of lambda functions are allowed (ignoring E731) +- Line breaks should occur before a binary operator (ignoring W503) + +These rules are enforced by running ``tox -e flake8`` on pull-requests. + +Requires Manual Review +---------------------- + +In addition to the ``flake8`` rules, **double quotes** are used over single quotes. If the string +contains double quotes in it, then single quotes may be used to avoid escaping. + +Also, the format of the docstrings should be in the +`Sphinx style `_ such as: + +:: + + Calculate the sum of two numbers. + + :param int a: the first number to add + :param int b: the second number to add + :return: the sum of a and b + :rtype: int + :raises TypeError: if a or b are not integers + + +Additionally, the imports should be ordered by standard library, third-party, then local. For example: + +:: + + import math + import os + + import flask + import requests + + import module_build_service.utils + from module_build_service.errors import ValidationError + + +Lastly, hanging indentation should be avoided when possible. For example: + +:: + + # Preferred + def get_module_build_dependencies( + self, name=None, stream=None, version=None, context=None, mmd=None, strict=False + ): + pass + + # Should be avoided + def get_module_build_dependencies(self, name=None, stream=None, version=None, + context=None, mmd=None, strict=False): + pass Development ===========