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 |
Alex Gaynor | e6466a5 | 2013-10-18 14:53:04 -0700 | [diff] [blame] | 23 | merge their changes. If multiple people work on a pull request, it must be |
| 24 | merged by someone who did not work on it. |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 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 | |
Alex Gaynor | 99b69d9 | 2013-10-19 17:52:58 -0700 | [diff] [blame] | 35 | If you believe you've identified a security issue in ``cryptography``, please |
| 36 | follow the directions on the :doc:`security page </security>`. |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 37 | |
| 38 | Code |
| 39 | ---- |
| 40 | |
| 41 | When in doubt, refer to `PEP 8`_ for Python code. |
| 42 | |
| 43 | Every code file must start with the boilerplate notice of the Apache License. |
| 44 | Additionally, every Python code file must contain |
| 45 | |
| 46 | .. code-block:: python |
| 47 | |
| 48 | from __future__ import absolute_import, division, print_function |
| 49 | |
Alex Gaynor | e6466a5 | 2013-10-18 14:53:04 -0700 | [diff] [blame] | 50 | C bindings |
| 51 | ---------- |
| 52 | |
| 53 | When binding C code with ``cffi`` we have our own style guide, it's pretty |
| 54 | simple. |
| 55 | |
| 56 | Don't name parameters: |
| 57 | |
| 58 | .. code-block:: c |
| 59 | |
| 60 | // Good |
| 61 | long f(long); |
| 62 | // Bad |
| 63 | long f(long x); |
| 64 | |
Paul Kehrer | 3ed80ba | 2013-10-19 20:00:26 -0500 | [diff] [blame] | 65 | ...unless they're inside a struct: |
| 66 | |
| 67 | .. code-block:: c |
| 68 | |
| 69 | struct my_struct { |
| 70 | char *name; |
| 71 | int number; |
| 72 | ...; |
| 73 | }; |
| 74 | |
Alex Gaynor | e6466a5 | 2013-10-18 14:53:04 -0700 | [diff] [blame] | 75 | Don't include stray ``void`` parameters: |
| 76 | |
| 77 | .. code-block:: c |
| 78 | |
| 79 | // Good |
| 80 | long f(); |
| 81 | // Bad |
| 82 | long f(void); |
| 83 | |
| 84 | Wrap lines at 80 characters like so: |
| 85 | |
| 86 | .. code-block:: c |
| 87 | |
| 88 | // Pretend this went to 80 characters |
| 89 | long f(long, long, |
| 90 | int *) |
| 91 | |
Alex Gaynor | 1e8744a | 2013-10-18 14:57:18 -0700 | [diff] [blame] | 92 | Include a space after commas between parameters: |
| 93 | |
| 94 | .. code-block:: c |
| 95 | |
| 96 | // Good |
| 97 | long f(int, char *) |
| 98 | // Bad |
| 99 | long f(int,char *) |
| 100 | |
Alex Gaynor | e6466a5 | 2013-10-18 14:53:04 -0700 | [diff] [blame] | 101 | |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 102 | Documentation |
| 103 | ------------- |
| 104 | |
| 105 | All features should be documented with prose. |
| 106 | |
| 107 | Docstrings should be written like this: |
| 108 | |
| 109 | .. code-block:: python |
| 110 | |
| 111 | def some_function(some_arg): |
| 112 | """ |
| 113 | Does some things. |
| 114 | |
| 115 | :param some_arg: Some argument. |
| 116 | """ |
| 117 | |
| 118 | So, specifically: |
| 119 | |
Alex Gaynor | 05a190e | 2013-10-29 17:11:25 -0700 | [diff] [blame] | 120 | * Always use three double quotes. |
| 121 | * Put the three double quotes on their own line. |
| 122 | * No blank line at the end. |
| 123 | * Use Sphinx parameter/attribute documentation `syntax`_. |
| 124 | |
| 125 | When documenting a new module in the ``hazmat`` package, its documentation |
| 126 | should begin with the "Hazardous Materials" warning: |
| 127 | |
| 128 | .. code-block:: rest |
| 129 | |
| 130 | .. hazmat:: |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 131 | |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 132 | Development Environment |
| 133 | ----------------------- |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 134 | |
| 135 | Working on ``cryptography`` requires the installation of a small number of |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 136 | development dependencies. These are listed in ``dev-requirements.txt`` and they |
| 137 | can be installed in a `virtualenv`_ using `pip`_. Once you've installed the |
| 138 | dependencies, install ``cryptography`` in ``editable`` mode. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 139 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 140 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 141 | |
Alex Gaynor | 7587ded | 2013-10-06 12:14:05 -0700 | [diff] [blame] | 142 | $ # Create a virtualenv and activate it |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 143 | $ pip install --requirement dev-requirements.txt |
| 144 | $ pip install --editable . |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 145 | |
| 146 | You are now ready to run the tests and build the documentation. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 147 | |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 148 | Running Tests |
| 149 | ------------- |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 150 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 151 | ``cryptography`` unit tests are found in the ``tests/`` directory and are |
| 152 | designed to be run using `pytest`_. `pytest`_ will discover the tests |
| 153 | automatically, so all you have to do is: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 154 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 155 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 156 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 157 | $ py.test |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 158 | ... |
| 159 | 4294 passed in 15.24 seconds |
| 160 | |
| 161 | This runs the tests with the default Python interpreter. |
| 162 | |
| 163 | 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] | 164 | For this we use `tox`_, which will automatically create a `virtualenv`_ for |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 165 | each supported Python version and run the tests. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 166 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 167 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 168 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 169 | $ tox |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 170 | ... |
Richard Wall | 40cde82 | 2013-10-01 20:20:15 +0100 | [diff] [blame] | 171 | ERROR: py26: InterpreterNotFound: python2.6 |
| 172 | py27: commands succeeded |
| 173 | ERROR: pypy: InterpreterNotFound: pypy |
| 174 | ERROR: py32: InterpreterNotFound: python3.2 |
| 175 | py33: commands succeeded |
| 176 | docs: commands succeeded |
| 177 | pep8: commands succeeded |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 178 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 179 | You may not have all the required Python versions installed, in which case you |
| 180 | will see one or more ``InterpreterNotFound`` errors. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 181 | |
| 182 | Building Documentation |
| 183 | ---------------------- |
| 184 | |
Alex Gaynor | 166cbd3 | 2013-10-01 13:30:29 -0700 | [diff] [blame] | 185 | ``cryptography`` documentation is stored in the ``docs/`` directory. It is |
| 186 | written in `reStructured Text`_ and rendered using `Sphinx`_. |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 187 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 188 | Use `tox`_ to build the documentation. For example: |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 189 | |
Alex Gaynor | ae5c907 | 2013-10-06 11:04:08 -0700 | [diff] [blame] | 190 | .. code-block:: console |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 191 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 192 | $ tox -e docs |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 193 | ... |
Richard Wall | c3d1eb5 | 2013-10-01 16:29:07 +0100 | [diff] [blame] | 194 | docs: commands succeeded |
Richard Wall | 0d9bb14 | 2013-10-01 16:17:24 +0100 | [diff] [blame] | 195 | congratulations :) |
| 196 | |
Richard Wall | 7d4ca1e | 2013-10-01 21:10:45 +0100 | [diff] [blame] | 197 | 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] | 198 | |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 199 | |
Donald Stufft | 8570794 | 2013-10-04 23:55:27 -0400 | [diff] [blame] | 200 | .. _`GitHub`: https://github.com/pyca/cryptography |
Alex Gaynor | c72e63f | 2013-09-09 21:44:26 -0700 | [diff] [blame] | 201 | .. _`our mailing list`: https://mail.python.org/mailman/listinfo/cryptography-dev |
| 202 | .. _`PEP 8`: http://www.peps.io/8/ |
| 203 | .. _`syntax`: http://sphinx-doc.org/domains.html#info-field-lists |
Richard Wall | c3d1eb5 | 2013-10-01 16:29:07 +0100 | [diff] [blame] | 204 | .. _`pytest`: https://pypi.python.org/pypi/pytest |
| 205 | .. _`tox`: https://pypi.python.org/pypi/tox |
| 206 | .. _`virtualenv`: https://pypi.python.org/pypi/virtualenv |
| 207 | .. _`pip`: https://pypi.python.org/pypi/pip |
| 208 | .. _`sphinx`: https://pypi.python.org/pypi/sphinx |
Alex Gaynor | a05358d | 2013-11-06 11:01:22 -0800 | [diff] [blame] | 209 | .. _`reStructured Text`: http://sphinx-doc.org/rest.html |