hacking.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. Hacking on :mod:`zope.interface`
  2. ================================
  3. Getting the Code
  4. ################
  5. The main repository for :mod:`zope.interface` is in the Zope Foundation
  6. Github repository:
  7. https://github.com/zopefoundation/zope.interface
  8. You can get a read-only checkout from there:
  9. .. code-block:: sh
  10. $ git clone https://github.com/zopefoundation/zope.interface.git
  11. or fork it and get a writeable checkout of your fork:
  12. .. code-block:: sh
  13. $ git clone git@github.com/jrandom/zope.interface.git
  14. The project also mirrors the trunk from the Github repository as a
  15. Bazaar branch on Launchpad:
  16. https://code.launchpad.net/zope.interface
  17. You can branch the trunk from there using Bazaar:
  18. .. code-block:: sh
  19. $ bzr branch lp:zope.interface
  20. Working in a ``virtualenv``
  21. ###########################
  22. Running the tests
  23. -----------------
  24. If you use the ``virtualenv`` package to create lightweight Python
  25. development environments, you can run the tests using nothing more
  26. than the ``python`` binary in a virtualenv. First, create a scratch
  27. environment:
  28. .. code-block:: sh
  29. $ /path/to/virtualenv --no-site-packages /tmp/hack-zope.interface
  30. Next, get this package registered as a "development egg" in the
  31. environment:
  32. .. code-block:: sh
  33. $ /tmp/hack-zope.interface/bin/python setup.py develop
  34. Finally, run the tests using the build-in ``setuptools`` testrunner:
  35. .. code-block:: sh
  36. $ /tmp/hack-zope.interface/bin/python setup.py test -q
  37. running test
  38. ...
  39. ----------------------------------------------------------------------
  40. Ran 2 tests in 0.000s
  41. OK
  42. The ``dev`` command alias downloads and installs extra tools, like the
  43. :mod:`nose` testrunner and the :mod:`coverage` coverage analyzer:
  44. .. code-block:: sh
  45. $ /tmp/hack-zope.interface/bin/python setup.py dev
  46. $ /tmp/hack-zope.interface/bin/nosetests
  47. running nosetests
  48. .................................... (lots more dots)
  49. ----------------------------------------------------------------------
  50. Ran 707 tests in 2.166s
  51. OK
  52. If you have the :mod:`coverage` package installed in the virtualenv,
  53. you can see how well the tests cover the code:
  54. .. code-block:: sh
  55. $ /tmp/hack-zope.interface/bin/nosetests --with coverage
  56. running nosetests
  57. .................................... (lots more dots)
  58. Name Stmts Miss Cover Missing
  59. ----------------------------------------------------------------
  60. zope.interface 30 0 100%
  61. zope.interface.adapter 440 0 100%
  62. zope.interface.advice 69 0 100%
  63. zope.interface.common 0 0 100%
  64. zope.interface.common.idatetime 98 0 100%
  65. zope.interface.common.interfaces 81 0 100%
  66. zope.interface.common.mapping 32 0 100%
  67. zope.interface.common.sequence 38 0 100%
  68. zope.interface.declarations 312 0 100%
  69. zope.interface.document 54 0 100%
  70. zope.interface.exceptions 21 0 100%
  71. zope.interface.interface 378 0 100%
  72. zope.interface.interfaces 137 0 100%
  73. zope.interface.registry 300 0 100%
  74. zope.interface.ro 25 0 100%
  75. zope.interface.verify 48 0 100%
  76. ----------------------------------------------------------------
  77. TOTAL 2063 0 100%
  78. ----------------------------------------------------------------------
  79. Ran 707 tests in 2.166s
  80. OK
  81. Building the documentation
  82. --------------------------
  83. :mod:`zope.interface` uses the nifty :mod:`Sphinx` documentation system
  84. for building its docs. Using the same virtualenv you set up to run the
  85. tests, you can build the docs:
  86. The ``docs`` command alias downloads and installs Sphinx and its dependencies:
  87. .. code-block:: sh
  88. $ /tmp/hack-zope.interface/bin/python setup.py docs
  89. ...
  90. $ bin/sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
  91. ...
  92. build succeeded.
  93. Build finished. The HTML pages are in docs/_build/html.
  94. You can also test the code snippets in the documentation:
  95. .. code-block:: sh
  96. $ bin/sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest
  97. ...
  98. running tests...
  99. Document: index
  100. ---------------
  101. 1 items passed all tests:
  102. 17 tests in default
  103. 17 tests in 1 items.
  104. 17 passed and 0 failed.
  105. Test passed.
  106. Doctest summary
  107. ===============
  108. 17 tests
  109. 0 failures in tests
  110. 0 failures in setup code
  111. build succeeded.
  112. Testing of doctests in the sources finished, look at the \
  113. results in docs/_build/doctest/output.txt.
  114. Using :mod:`zc.buildout`
  115. ########################
  116. Setting up the buildout
  117. -----------------------
  118. :mod:`zope.interface` ships with its own :file:`buildout.cfg` file and
  119. :file:`bootstrap.py` for setting up a development buildout:
  120. .. code-block:: sh
  121. $ /path/to/python2.7 bootstrap.py
  122. ...
  123. Generated script '.../bin/buildout'
  124. $ bin/buildout
  125. Develop: '/home/jrandom/projects/Zope/BTK/interface/.'
  126. ...
  127. Generated script '.../bin/sphinx-quickstart'.
  128. Generated script '.../bin/sphinx-build'.
  129. Running the tests
  130. -----------------
  131. You can now run the tests:
  132. .. code-block:: sh
  133. $ bin/test --all
  134. Running zope.testing.testrunner.layer.UnitTests tests:
  135. Set up zope.testing.testrunner.layer.UnitTests in 0.000 seconds.
  136. Ran 702 tests with 0 failures and 0 errors in 0.000 seconds.
  137. Tearing down left over layers:
  138. Tear down zope.testing.testrunner.layer.UnitTests in 0.000 seconds.
  139. Using :mod:`tox`
  140. ################
  141. Running Tests on Multiple Python Versions
  142. -----------------------------------------
  143. `tox <http://tox.testrun.org/latest/>`_ is a Python-based test automation
  144. tool designed to run tests against multiple Python versions. It creates
  145. a ``virtualenv`` for each configured version, installs the current package
  146. and configured dependencies into each ``virtualenv``, and then runs the
  147. configured commands.
  148. :mod:`zope.interface` configures the following :mod:`tox` environments via
  149. its ``tox.ini`` file:
  150. - The defined Python environments build a ``virtualenv`` with various Python 2,
  151. Python 3, PyPy 2 and PyPy 3 versions, install :mod:`zope.interface` and
  152. dependencies, and run the tests via ``python setup.py test -q``.
  153. - The ``coverage`` environment builds a ``virtualenv`` with ``python2.7``,
  154. installs :mod:`zope.interface` and dependencies, installs
  155. :mod:`nose` and :mod:`coverage`, and runs ``nosetests`` with statement
  156. coverage.
  157. - The ``docs`` environment builds a virtualenv with ``python2.7``, installs
  158. :mod:`zope.interface` and dependencies, installs ``Sphinx`` and
  159. dependencies, and then builds the docs and exercises the doctest snippets.
  160. This example requires that you have a working ``python2.7`` on your path,
  161. as well as installing ``tox``:
  162. .. code-block:: sh
  163. $ tox -e py26
  164. GLOB sdist-make: .../zope.interface/setup.py
  165. py26 sdist-reinst: .../zope.interface/.tox/dist/zope.interface-4.0.2dev.zip
  166. py26 runtests: commands[0]
  167. ...
  168. ----------------------------------------------------------------------
  169. Ran 1341 tests in 0.477s
  170. OK
  171. ___________________________________ summary ____________________________________
  172. py26: commands succeeded
  173. congratulations :)
  174. Running ``tox`` with no arguments runs all the configured environments,
  175. including building the docs and testing their snippets:
  176. .. code-block:: sh
  177. $ tox
  178. GLOB sdist-make: .../zope.interface/setup.py
  179. py26 sdist-reinst: .../zope.interface/.tox/dist/zope.interface-4.0.2dev.zip
  180. py26 runtests: commands[0]
  181. ...
  182. Doctest summary
  183. ===============
  184. 678 tests
  185. 0 failures in tests
  186. 0 failures in setup code
  187. 0 failures in cleanup code
  188. build succeeded.
  189. ___________________________________ summary ____________________________________
  190. py26: commands succeeded
  191. py27: commands succeeded
  192. py32: commands succeeded
  193. pypy: commands succeeded
  194. coverage: commands succeeded
  195. docs: commands succeeded
  196. congratulations :)
  197. Contributing to :mod:`zope.interface`
  198. #####################################
  199. Submitting a Bug Report
  200. -----------------------
  201. :mod:`zope.interface` tracks its bugs on Github:
  202. https://github.com/zopefoundation/zope.interface/issues
  203. Please submit bug reports and feature requests there.
  204. Sharing Your Changes
  205. --------------------
  206. .. note::
  207. Please ensure that all tests are passing before you submit your code.
  208. If possible, your submission should include new tests for new features
  209. or bug fixes, although it is possible that you may have tested your
  210. new code by updating existing tests.
  211. If have made a change you would like to share, the best route is to fork
  212. the Githb repository, check out your fork, make your changes on a branch
  213. in your fork, and push it. You can then submit a pull request from your
  214. branch:
  215. https://github.com/zopefoundation/zope.interface/pulls
  216. If you branched the code from Launchpad using Bazaar, you have another
  217. option: you can "push" your branch to Launchpad:
  218. .. code-block:: sh
  219. $ bzr push lp:~jrandom/zope.interface/cool_feature
  220. After pushing your branch, you can link it to a bug report on Launchpad,
  221. or request that the maintainers merge your branch using the Launchpad
  222. "merge request" feature.