developers_guide.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. =================
  2. Developers' guide
  3. =================
  4. These instructions are for developing on a Unix-like platform, e.g. Linux or
  5. Mac OS X, with the bash shell. If you develop on Windows, please get in touch.
  6. Mailing lists
  7. -------------
  8. General discussion of Neo development takes place in the `NeuralEnsemble Google
  9. group`_.
  10. Discussion of issues specific to a particular ticket in the issue tracker
  11. should take place on the tracker.
  12. Using the issue tracker
  13. -----------------------
  14. If you find a bug in Neo, please create a new ticket on the `issue tracker`_,
  15. setting the type to "defect".
  16. Choose a name that is as specific as possible to the problem you've found, and
  17. in the description give as much information as you think is necessary to
  18. recreate the problem. The best way to do this is to create the shortest
  19. possible Python script that demonstrates the problem, and attach the file to
  20. the ticket.
  21. If you have an idea for an improvement to Neo, create a ticket with type
  22. "enhancement". If you already have an implementation of the idea, create a
  23. patch (see below) and attach it to the ticket.
  24. To keep track of changes to the code and to tickets, you can register for
  25. a GitHub account and then set to watch the repository at `GitHub Repository`_
  26. (see https://help.github.com/articles/watching-repositories/).
  27. Requirements
  28. ------------
  29. * Python_ 2.6, 2.7, 3.3-3.5
  30. * numpy_ >= 1.7.1
  31. * quantities_ >= 0.9.0
  32. * if using Python 2.6, unittest2_ >= 0.5.1
  33. * Setuptools >= 0.7
  34. * nose_ >= 0.11.1 (for running tests)
  35. * Sphinx_ >= 0.6.4 (for building documentation)
  36. * (optional) tox_ >= 0.9 (makes it easier to test with multiple Python versions)
  37. * (optional) coverage_ >= 2.85 (for measuring test coverage)
  38. * (optional) scipy >= 0.12 (for MatlabIO)
  39. * (optional) h5py >= 2.5 (for KwikIO, NeoHdf5IO)
  40. We strongly recommend you develop within a virtual environment (from virtualenv, venv or conda).
  41. It is best to have at least one virtual environment with Python 2.7 and one with Python 3.x.
  42. Getting the source code
  43. -----------------------
  44. We use the Git version control system. The best way to contribute is through
  45. GitHub_. You will first need a GitHub account, and you should then fork the
  46. repository at `GitHub Repository`_
  47. (see http://help.github.com/fork-a-repo/).
  48. To get a local copy of the repository::
  49. $ cd /some/directory
  50. $ git clone git@github.com:<username>/python-neo.git
  51. Now you need to make sure that the ``neo`` package is on your PYTHONPATH.
  52. You can do this either by installing Neo::
  53. $ cd python-neo
  54. $ python setup.py install
  55. $ python3 setup.py install
  56. (if you do this, you will have to re-run ``setup.py install`` any time you make
  57. changes to the code) *or* by creating symbolic links from somewhere on your
  58. PYTHONPATH, for example::
  59. $ ln -s python-neo/neo
  60. $ export PYTHONPATH=/some/directory:${PYTHONPATH}
  61. An alternate solution is to install Neo with the *develop* option, this avoids
  62. reinstalling when there are changes in the code::
  63. $ sudo python setup.py develop
  64. or using the "-e" option to pip::
  65. $ pip install -e python-neo
  66. To update to the latest version from the repository::
  67. $ git pull
  68. Running the test suite
  69. ----------------------
  70. Before you make any changes, run the test suite to make sure all the tests pass
  71. on your system::
  72. $ cd neo/test
  73. With Python 2.7 or 3.3::
  74. $ python -m unittest discover
  75. $ python3 -m unittest discover
  76. If you have nose installed::
  77. $ nosetests
  78. At the end, if you see "OK", then all the tests
  79. passed (or were skipped because certain dependencies are not installed),
  80. otherwise it will report on tests that failed or produced errors.
  81. To run tests from an individual file::
  82. $ python test_analogsignal.py
  83. $ python3 test_analogsignal.py
  84. Writing tests
  85. -------------
  86. You should try to write automated tests for any new code that you add. If you
  87. have found a bug and want to fix it, first write a test that isolates the bug
  88. (and that therefore fails with the existing codebase). Then apply your fix and
  89. check that the test now passes.
  90. To see how well the tests cover the code base, run::
  91. $ nosetests --with-coverage --cover-package=neo --cover-erase
  92. Working on the documentation
  93. ----------------------------
  94. All modules, classes, functions, and methods (including private and subclassed
  95. builtin methods) should have docstrings.
  96. Please see `PEP257`_ for a description of docstring conventions.
  97. Module docstrings should explain briefly what functions or classes are present.
  98. Detailed descriptions can be left for the docstrings of the respective
  99. functions or classes. Private functions do not need to be explained here.
  100. Class docstrings should include an explanation of the purpose of the class
  101. and, when applicable, how it relates to standard neuroscientific data.
  102. They should also include at least one example, which should be written
  103. so it can be run as-is from a clean newly-started Python interactive session
  104. (that means all imports should be included). Finally, they should include
  105. a list of all arguments, attributes, and properties, with explanations.
  106. Properties that return data calculated from other data should explain what
  107. calculation is done. A list of methods is not needed, since documentation
  108. will be generated from the method docstrings.
  109. Method and function docstrings should include an explanation for what the
  110. method or function does. If this may not be clear, one or more examples may
  111. be included. Examples that are only a few lines do not need to include
  112. imports or setup, but more complicated examples should have them.
  113. Examples can be tested easily using the iPython `%doctest_mode` magic. This will
  114. strip >>> and ... from the beginning of each line of the example, so the
  115. example can be copied and pasted as-is.
  116. The documentation is written in `reStructuredText`_, using the `Sphinx`_
  117. documentation system. Any mention of another Neo module, class, attribute,
  118. method, or function should be properly marked up so automatic
  119. links can be generated. The same goes for quantities or numpy.
  120. To build the documentation::
  121. $ cd python-neo/doc
  122. $ make html
  123. Then open `some/directory/python-neo/doc/build/html/index.html` in your browser.
  124. Committing your changes
  125. -----------------------
  126. Once you are happy with your changes, **run the test suite again to check
  127. that you have not introduced any new bugs**. It is also recommended to check
  128. your code with a code checking program, such as `pyflakes`_ or `flake8`_. Then
  129. you can commit them to your local repository::
  130. $ git commit -m 'informative commit message'
  131. If this is your first commit to the project, please add your name and
  132. affiliation/employer to :file:`doc/source/authors.rst`
  133. You can then push your changes to your online repository on GitHub::
  134. $ git push
  135. Once you think your changes are ready to be included in the main Neo repository,
  136. open a pull request on GitHub
  137. (see https://help.github.com/articles/using-pull-requests).
  138. Python 3
  139. --------
  140. Neo core should work with both recent versions of Python 2 (versions 2.6 and
  141. 2.7) and Python 3 (version 3.3 or newer). Neo IO modules should ideally work with both
  142. Python 2 and 3, but certain modules may only work with one or the other
  143. (see :doc:`install`).
  144. So far, we have managed to write code that works with both Python 2 and 3.
  145. Mainly this involves avoiding the ``print`` statement (use ``logging.info``
  146. instead), and putting ``from __future__ import division`` at the beginning of
  147. any file that uses division.
  148. If in doubt, `Porting to Python 3`_ by Lennart Regebro is an excellent resource.
  149. The most important thing to remember is to run tests with at least one version
  150. of Python 2 and at least one version of Python 3. There is generally no problem
  151. in having multiple versions of Python installed on your computer at once: e.g.,
  152. on Ubuntu Python 2 is available as `python` and Python 3 as `python3`, while
  153. on Arch Linux Python 2 is `python2` and Python 3 `python`. See `PEP394`_ for
  154. more on this. Using virtual environments makes this very straightforward.
  155. Coding standards and style
  156. --------------------------
  157. All code should conform as much as possible to `PEP 8`_, and should run with
  158. Python 2.6, 2.7, and 3.3 or newer.
  159. You can use the `pep8`_ program to check the code for PEP 8 conformity.
  160. You can also use `flake8`_, which combines pep8 and pyflakes.
  161. However, the pep8 and flake8 programs do not check for all PEP 8 issues.
  162. In particular, they do not check that the import statements are in the
  163. correct order.
  164. Also, please do not use ``from xyz import *``. This is slow, can lead to
  165. conflicts, and makes it difficult for code analysis software.
  166. Making a release
  167. ----------------
  168. .. TODO: discuss branching/tagging policy.
  169. Add a section in :file:`/doc/source/whatisnew.rst` for the release.
  170. First check that the version string (in :file:`neo/version.py`,
  171. :file:`setup.py`, :file:`doc/conf.py` and :file:`doc/install.rst`) is correct.
  172. To build a source package::
  173. $ python setup.py sdist
  174. To upload the package to `PyPI`_ (currently Samuel Garcia and Andrew Davison
  175. have the necessary permissions to do this)::
  176. $ python setup.py sdist upload
  177. $ python setup.py upload_docs --upload-dir=doc/build/html
  178. .. talk about readthedocs
  179. Finally, tag the release in the Git repository and push it::
  180. $ git tag <version>
  181. $ git push --tags origin
  182. .. make a release branch
  183. If you want to develop your own IO module
  184. -----------------------------------------
  185. See :ref:`io_dev_guide` for implementation of a new IO.
  186. .. _Python: http://www.python.org
  187. .. _nose: http://somethingaboutorange.com/mrl/projects/nose/
  188. .. _unittest2: http://pypi.python.org/pypi/unittest2
  189. .. _Setuptools: https://pypi.python.org/pypi/setuptools/
  190. .. _tox: http://codespeak.net/tox/
  191. .. _coverage: http://nedbatchelder.com/code/coverage/
  192. .. _`PEP 8`: http://www.python.org/dev/peps/pep-0008/
  193. .. _`issue tracker`: https://github.com/NeuralEnsemble/python-neo/issues
  194. .. _`Porting to Python 3`: http://python3porting.com/
  195. .. _`NeuralEnsemble Google group`: http://groups.google.com/group/neuralensemble
  196. .. _reStructuredText: http://docutils.sourceforge.net/rst.html
  197. .. _Sphinx: http://sphinx.pocoo.org/
  198. .. _numpy: http://numpy.scipy.org/
  199. .. _quantities: http://pypi.python.org/pypi/quantities
  200. .. _PEP257: http://www.python.org/dev/peps/pep-0257/
  201. .. _PEP394: http://www.python.org/dev/peps/pep-0394/
  202. .. _PyPI: http://pypi.python.org
  203. .. _GitHub: http://github.com
  204. .. _`GitHub Repository`: https://github.com/NeuralEnsemble/python-neo/
  205. .. _pep8: https://pypi.python.org/pypi/pep8
  206. .. _flake8: https://pypi.python.org/pypi/flake8/
  207. .. _pyflakes: https://pypi.python.org/pypi/pyflakes/