Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 1 | Contributing |
| 2 | ============ |
| 3 | |
| 4 | Process |
| 5 | ------- |
| 6 | |
| 7 | As an open source project, ``cryptography`` welcomes contributions of all |
| 8 | forms. These can include: |
| 9 | |
| 10 | * Bug reports and feature requests |
| 11 | * Pull requests for both code and documentation |
| 12 | * Patch reviews |
| 13 | |
Alex Gaynor | 2c67c82 | 2013-09-09 23:44:13 -0700 | [diff] [blame] | 14 | You can file bugs and submit pull requests on `GitHub`_. To discuss larger |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 15 | changes you can start a conversation on `our mailing list`_. |
| 16 | |
| 17 | Because cryptography is so complex, and the implications of getting it wrong so |
| 18 | devastating, ``cryptography`` has a strict code review policy: |
| 19 | |
| 20 | * Patches must *never* be pushed directly to ``master``, all changes (even the |
| 21 | most trivial typo fixes!) must be submitted as a pull request. |
| 22 | * A committer may *never* merge their own pull request, a second party must |
| 23 | merge their changes. If multiple people work on a pull request, the merger |
| 24 | may not be any of them. |
| 25 | * A patch which breaks tests, or introduces regressions by changing or removing |
| 26 | existing tests should not be merged. Tests must always be passing on |
| 27 | ``master``. |
| 28 | * If somehow the tests get into a failing state on ``master`` (such as by a |
| 29 | backwards incompatible release of a dependency) no pull requests may be |
| 30 | merged until this is rectified. |
| 31 | |
| 32 | The purpose of these policies is to minimize the chances we merge a change |
| 33 | which jeopardizes our users' security. |
| 34 | |
| 35 | We do not yet have a formal security contact. To report security issues in |
| 36 | ``cryptography`` you should email ``alex.gaynor@gmail.com``, messages may be |
| 37 | encrypted with PGP to key fingerprint |
| 38 | ``E27D 4AA0 1651 72CB C5D2 AF2B 125F 5C67 DFE9 4084`` (this public key is |
| 39 | available from most commonly-used keyservers). |
| 40 | |
| 41 | Code |
| 42 | ---- |
| 43 | |
| 44 | When in doubt, refer to `PEP 8`_ for Python code. |
| 45 | |
| 46 | Every code file must start with the boilerplate notice of the Apache License. |
| 47 | Additionally, every Python code file must contain |
| 48 | |
| 49 | .. code-block:: python |
| 50 | |
| 51 | from __future__ import absolute_import, division, print_function |
| 52 | |
| 53 | Documentation |
| 54 | ------------- |
| 55 | |
| 56 | All features should be documented with prose. |
| 57 | |
| 58 | Docstrings should be written like this: |
| 59 | |
| 60 | .. code-block:: python |
| 61 | |
| 62 | def some_function(some_arg): |
| 63 | """ |
| 64 | Does some things. |
| 65 | |
| 66 | :param some_arg: Some argument. |
| 67 | """ |
| 68 | |
| 69 | So, specifically: |
| 70 | |
| 71 | - Always use three double quotes. |
| 72 | - Put the three double quotes on their own line. |
| 73 | - No blank line at the end. |
| 74 | - Use Sphinx parameter/attribute documentation `syntax`_. |
| 75 | |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 76 | Development Environment |
| 77 | ----------------------- |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 78 | |
| 79 | Working on ``cryptography`` requires the installation of a small number of |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 80 | development dependencies. These are listed in ``dev-requirements.txt`` and they |
| 81 | can be installed in a `virtualenv`_ using `pip`_. Once you've installed the |
| 82 | dependencies, install ``cryptography`` in ``editable`` mode. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 83 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 84 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 85 | |
Alex Gaynor | 7587ded | 2013-10-06 12:14:05 -0700 | [diff] [blame] | 86 | $ # Create a virtualenv and activate it |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 87 | $ pip install --requirement dev-requirements.txt |
| 88 | $ pip install --editable . |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 89 | |
| 90 | You are now ready to run the tests and build the documentation. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 91 | |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 92 | Running Tests |
| 93 | ------------- |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 94 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 95 | ``cryptography`` unit tests are found in the ``tests/`` directory and are |
| 96 | designed to be run using `pytest`_. `pytest`_ will discover the tests |
| 97 | automatically, so all you have to do is: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 98 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 99 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 100 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 101 | $ py.test |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 102 | ... |
| 103 | 4294 passed in 15.24 seconds |
| 104 | |
| 105 | This runs the tests with the default Python interpreter. |
| 106 | |
| 107 | You can also verify that the tests pass on other supported Python interpreters. |
Richard Wall | c3d1eb5 | 2013-10-01 16:29:07 +0100 | [diff] [blame] | 108 | For this we use `tox`_, which will automatically create a `virtualenv`_ for |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 109 | each supported Python version and run the tests. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 110 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 111 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 112 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 113 | $ tox |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 114 | ... |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 115 | ERROR: py26: InterpreterNotFound: python2.6 |
| 116 | py27: commands succeeded |
| 117 | ERROR: pypy: InterpreterNotFound: pypy |
| 118 | ERROR: py32: InterpreterNotFound: python3.2 |
| 119 | py33: commands succeeded |
| 120 | docs: commands succeeded |
| 121 | pep8: commands succeeded |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 122 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 123 | You may not have all the required Python versions installed, in which case you |
| 124 | will see one or more ``InterpreterNotFound`` errors. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 125 | |
| 126 | Building Documentation |
| 127 | ---------------------- |
| 128 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 129 | ``cryptography`` documentation is stored in the ``docs/`` directory. It is |
| 130 | written in `reStructured Text`_ and rendered using `Sphinx`_. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 131 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 132 | Use `tox`_ to build the documentation. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 133 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 134 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 135 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 136 | $ tox -e docs |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 137 | ... |
Richard Wall | c3d1eb5 | 2013-10-01 16:29:07 +0100 | [diff] [blame] | 138 | docs: commands succeeded |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 139 | congratulations :) |
| 140 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 141 | The HTML documentation index can now be found at ``docs/_build/html/index.html`` |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 142 | |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 143 | |
Donald Stufft | 8570794 | 2013-10-04 23:55:27 -0400 | [diff] [blame] | 144 | .. _`GitHub`: https://github.com/pyca/cryptography |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 145 | .. _`our mailing list`: https://mail.python.org/mailman/listinfo/cryptography-dev |
| 146 | .. _`PEP 8`: http://www.peps.io/8/ |
| 147 | .. _`syntax`: http://sphinx-doc.org/domains.html#info-field-lists |
Richard Wall | c3d1eb5 | 2013-10-01 16:29:07 +0100 | [diff] [blame] | 148 | .. _`pytest`: https://pypi.python.org/pypi/pytest |
| 149 | .. _`tox`: https://pypi.python.org/pypi/tox |
| 150 | .. _`virtualenv`: https://pypi.python.org/pypi/virtualenv |
| 151 | .. _`pip`: https://pypi.python.org/pypi/pip |
| 152 | .. _`sphinx`: https://pypi.python.org/pypi/sphinx |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 153 | .. _`reStructured Text`: http://docutils.sourceforge.net/rst.html |