blob: b125d1afbf9b3fd4046cc01c0ced6a9be9407f67 [file] [log] [blame]
Alex Gaynorc72e63f2013-09-09 21:44:26 -07001Contributing
2============
3
4Process
5-------
6
7As an open source project, ``cryptography`` welcomes contributions of all
8forms. These can include:
9
10* Bug reports and feature requests
11* Pull requests for both code and documentation
12* Patch reviews
13
Alex Gaynor2c67c822013-09-09 23:44:13 -070014You can file bugs and submit pull requests on `GitHub`_. To discuss larger
Alex Gaynorc72e63f2013-09-09 21:44:26 -070015changes you can start a conversation on `our mailing list`_.
16
17Because cryptography is so complex, and the implications of getting it wrong so
18devastating, ``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 Gaynore6466a52013-10-18 14:53:04 -070023 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 Gaynorc72e63f2013-09-09 21:44:26 -070025* 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
32The purpose of these policies is to minimize the chances we merge a change
33which jeopardizes our users' security.
34
35We 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
37encrypted with PGP to key fingerprint
38``E27D 4AA0 1651 72CB C5D2 AF2B 125F 5C67 DFE9 4084`` (this public key is
39available from most commonly-used keyservers).
40
41Code
42----
43
44When in doubt, refer to `PEP 8`_ for Python code.
45
46Every code file must start with the boilerplate notice of the Apache License.
47Additionally, every Python code file must contain
48
49.. code-block:: python
50
51 from __future__ import absolute_import, division, print_function
52
Alex Gaynore6466a52013-10-18 14:53:04 -070053C bindings
54----------
55
56When binding C code with ``cffi`` we have our own style guide, it's pretty
57simple.
58
59Don't name parameters:
60
61.. code-block:: c
62
63 // Good
64 long f(long);
65 // Bad
66 long f(long x);
67
68Don't include stray ``void`` parameters:
69
70.. code-block:: c
71
72 // Good
73 long f();
74 // Bad
75 long f(void);
76
77Wrap lines at 80 characters like so:
78
79.. code-block:: c
80
81 // Pretend this went to 80 characters
82 long f(long, long,
83 int *)
84
Alex Gaynor1e8744a2013-10-18 14:57:18 -070085Include a space after commas between parameters:
86
87.. code-block:: c
88
89 // Good
90 long f(int, char *)
91 // Bad
92 long f(int,char *)
93
Alex Gaynore6466a52013-10-18 14:53:04 -070094
Alex Gaynorc72e63f2013-09-09 21:44:26 -070095Documentation
96-------------
97
98All features should be documented with prose.
99
100Docstrings should be written like this:
101
102.. code-block:: python
103
104 def some_function(some_arg):
105 """
106 Does some things.
107
108 :param some_arg: Some argument.
109 """
110
111So, specifically:
112
113- Always use three double quotes.
114- Put the three double quotes on their own line.
115- No blank line at the end.
116- Use Sphinx parameter/attribute documentation `syntax`_.
117
Richard Wall40cde822013-10-01 20:20:15 +0100118Development Environment
119-----------------------
Richard Wall0d9bb142013-10-01 16:17:24 +0100120
121Working on ``cryptography`` requires the installation of a small number of
Alex Gaynor166cbd32013-10-01 13:30:29 -0700122development dependencies. These are listed in ``dev-requirements.txt`` and they
123can be installed in a `virtualenv`_ using `pip`_. Once you've installed the
124dependencies, install ``cryptography`` in ``editable`` mode. For example:
Richard Wall0d9bb142013-10-01 16:17:24 +0100125
Alex Gaynorae5c9072013-10-06 11:04:08 -0700126.. code-block:: console
Richard Wall0d9bb142013-10-01 16:17:24 +0100127
Alex Gaynor7587ded2013-10-06 12:14:05 -0700128 $ # Create a virtualenv and activate it
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100129 $ pip install --requirement dev-requirements.txt
130 $ pip install --editable .
Richard Wall0d9bb142013-10-01 16:17:24 +0100131
132You are now ready to run the tests and build the documentation.
Richard Wall0d9bb142013-10-01 16:17:24 +0100133
Richard Wall40cde822013-10-01 20:20:15 +0100134Running Tests
135-------------
Richard Wall0d9bb142013-10-01 16:17:24 +0100136
Alex Gaynor166cbd32013-10-01 13:30:29 -0700137``cryptography`` unit tests are found in the ``tests/`` directory and are
138designed to be run using `pytest`_. `pytest`_ will discover the tests
139automatically, so all you have to do is:
Richard Wall0d9bb142013-10-01 16:17:24 +0100140
Alex Gaynorae5c9072013-10-06 11:04:08 -0700141.. code-block:: console
Richard Wall0d9bb142013-10-01 16:17:24 +0100142
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100143 $ py.test
Richard Wall0d9bb142013-10-01 16:17:24 +0100144 ...
145 4294 passed in 15.24 seconds
146
147This runs the tests with the default Python interpreter.
148
149You can also verify that the tests pass on other supported Python interpreters.
Richard Wallc3d1eb52013-10-01 16:29:07 +0100150For this we use `tox`_, which will automatically create a `virtualenv`_ for
Richard Wall40cde822013-10-01 20:20:15 +0100151each supported Python version and run the tests. For example:
Richard Wall0d9bb142013-10-01 16:17:24 +0100152
Alex Gaynorae5c9072013-10-06 11:04:08 -0700153.. code-block:: console
Richard Wall0d9bb142013-10-01 16:17:24 +0100154
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100155 $ tox
Richard Wall0d9bb142013-10-01 16:17:24 +0100156 ...
Richard Wall40cde822013-10-01 20:20:15 +0100157 ERROR: py26: InterpreterNotFound: python2.6
158 py27: commands succeeded
159 ERROR: pypy: InterpreterNotFound: pypy
160 ERROR: py32: InterpreterNotFound: python3.2
161 py33: commands succeeded
162 docs: commands succeeded
163 pep8: commands succeeded
Richard Wall0d9bb142013-10-01 16:17:24 +0100164
Alex Gaynor166cbd32013-10-01 13:30:29 -0700165You may not have all the required Python versions installed, in which case you
166will see one or more ``InterpreterNotFound`` errors.
Richard Wall0d9bb142013-10-01 16:17:24 +0100167
168Building Documentation
169----------------------
170
Alex Gaynor166cbd32013-10-01 13:30:29 -0700171``cryptography`` documentation is stored in the ``docs/`` directory. It is
172written in `reStructured Text`_ and rendered using `Sphinx`_.
Richard Wall0d9bb142013-10-01 16:17:24 +0100173
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100174Use `tox`_ to build the documentation. For example:
Richard Wall0d9bb142013-10-01 16:17:24 +0100175
Alex Gaynorae5c9072013-10-06 11:04:08 -0700176.. code-block:: console
Richard Wall0d9bb142013-10-01 16:17:24 +0100177
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100178 $ tox -e docs
Richard Wall0d9bb142013-10-01 16:17:24 +0100179 ...
Richard Wallc3d1eb52013-10-01 16:29:07 +0100180 docs: commands succeeded
Richard Wall0d9bb142013-10-01 16:17:24 +0100181 congratulations :)
182
Richard Wall7d4ca1e2013-10-01 21:10:45 +0100183The HTML documentation index can now be found at ``docs/_build/html/index.html``
Richard Wall40cde822013-10-01 20:20:15 +0100184
Alex Gaynorc72e63f2013-09-09 21:44:26 -0700185
Donald Stufft85707942013-10-04 23:55:27 -0400186.. _`GitHub`: https://github.com/pyca/cryptography
Alex Gaynorc72e63f2013-09-09 21:44:26 -0700187.. _`our mailing list`: https://mail.python.org/mailman/listinfo/cryptography-dev
188.. _`PEP 8`: http://www.peps.io/8/
189.. _`syntax`: http://sphinx-doc.org/domains.html#info-field-lists
Richard Wallc3d1eb52013-10-01 16:29:07 +0100190.. _`pytest`: https://pypi.python.org/pypi/pytest
191.. _`tox`: https://pypi.python.org/pypi/tox
192.. _`virtualenv`: https://pypi.python.org/pypi/virtualenv
193.. _`pip`: https://pypi.python.org/pypi/pip
194.. _`sphinx`: https://pypi.python.org/pypi/sphinx
Alex Gaynor166cbd32013-10-01 13:30:29 -0700195.. _`reStructured Text`: http://docutils.sourceforge.net/rst.html