development.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. .. include:: global.rst.inc
  2. .. highlight:: bash
  3. .. _development:
  4. Development
  5. ===========
  6. This chapter will get you started with |project_name| development.
  7. |project_name| is written in Python (with a little bit of Cython and C for
  8. the performance critical parts).
  9. Contributions
  10. -------------
  11. ... are welcome!
  12. Some guidance for contributors:
  13. - discuss about changes on github issue tracker, IRC or mailing list
  14. - choose the branch you base your changesets on wisely:
  15. - choose x.y-maint for stuff that should go into next x.y.z release
  16. (it usually gets merged into master branch later also), like:
  17. - bug fixes (code or docs)
  18. - missing *important* (and preferably small) features
  19. - docs rearrangements (so stuff stays in-sync to avoid merge
  20. troubles in future)
  21. - choose master if that does not apply, like for:
  22. - developing new features
  23. - do clean changesets:
  24. - focus on some topic, resist changing anything else.
  25. - do not do style changes mixed with functional changes.
  26. - try to avoid refactorings mixed with functional changes.
  27. - if you need to fix something after commit/push:
  28. - if there are ongoing reviews: do a fixup commit you can
  29. merge into the bad commit later.
  30. - if there are no ongoing reviews or you did not push the
  31. bad commit yet: edit the commit to include your fix or
  32. merge the fixup commit before pushing.
  33. - have a nice, clear, typo-free commit comment
  34. - if you fixed an issue, refer to it in your commit comment
  35. - follow the style guide (see below)
  36. - if you write new code, please add tests and docs for it
  37. - run the tests, fix anything that comes up
  38. - make a pull request on github
  39. - wait for review by other developers
  40. Style guide
  41. -----------
  42. We generally follow `pep8
  43. <https://www.python.org/dev/peps/pep-0008/>`_, with 120 columns
  44. instead of 79. We do *not* use form-feed (``^L``) characters to
  45. separate sections either. Compliance is tested automatically when
  46. you run the tests.
  47. Continuous Integration
  48. ----------------------
  49. All pull requests go through Travis-CI_, which runs the tests on Linux
  50. and Mac OS X as well as the flake8 style checker. Additional Unix-like platforms
  51. are tested on Golem_.
  52. .. _Golem: https://golem.enkore.de/view/Borg/
  53. .. _Travis-CI: https://travis-ci.org/borgbackup/borg
  54. Output and Logging
  55. ------------------
  56. When writing logger calls, always use correct log level (debug only for
  57. debugging, info for informative messages, warning for warnings, error for
  58. errors, critical for critical errors/states).
  59. When directly talking to the user (e.g. Y/N questions), do not use logging,
  60. but directly output to stderr (not: stdout, it could be connected to a pipe).
  61. To control the amount and kinds of messages output to stderr or emitted at
  62. info level, use flags like ``--stats`` or ``--list``.
  63. Building a development environment
  64. ----------------------------------
  65. First, just install borg into a virtual env as described before.
  66. To install some additional packages needed for running the tests, activate your
  67. virtual env and run::
  68. pip install -r requirements.d/development.txt
  69. Running the tests
  70. -----------------
  71. The tests are in the borg/testsuite package.
  72. To run all the tests, you need to have fakeroot installed. If you do not have
  73. fakeroot, you still will be able to run most tests, just leave away the
  74. `fakeroot -u` from the given command lines.
  75. To run the test suite use the following command::
  76. fakeroot -u tox # run all tests
  77. Some more advanced examples::
  78. # verify a changed tox.ini (run this after any change to tox.ini):
  79. fakeroot -u tox --recreate
  80. fakeroot -u tox -e py34 # run all tests, but only on python 3.4
  81. fakeroot -u tox borg.testsuite.locking # only run 1 test module
  82. fakeroot -u tox borg.testsuite.locking -- -k '"not Timer"' # exclude some tests
  83. fakeroot -u tox borg.testsuite -- -v # verbose py.test
  84. Important notes:
  85. - When using ``--`` to give options to py.test, you MUST also give ``borg.testsuite[.module]``.
  86. Regenerate usage files
  87. ----------------------
  88. Usage and API documentation is currently committed directly to git,
  89. although those files are generated automatically from the source
  90. tree.
  91. When a new module is added, the ``docs/api.rst`` file needs to be
  92. regenerated::
  93. ./setup.py build_api
  94. When a command is added, a commandline flag changed, added or removed,
  95. the usage docs need to be rebuilt as well::
  96. ./setup.py build_usage
  97. Building the docs with Sphinx
  98. -----------------------------
  99. The documentation (in reStructuredText format, .rst) is in docs/.
  100. To build the html version of it, you need to have sphinx installed::
  101. pip3 install sphinx sphinx_rtd_theme # important: this will install sphinx with Python 3
  102. Now run::
  103. cd docs/
  104. make html
  105. Then point a web browser at docs/_build/html/index.html.
  106. The website is updated automatically through Github web hooks on the
  107. main repository.
  108. Using Vagrant
  109. -------------
  110. We use Vagrant for the automated creation of testing environments and borgbackup
  111. standalone binaries for various platforms.
  112. For better security, there is no automatic sync in the VM to host direction.
  113. The plugin `vagrant-scp` is useful to copy stuff from the VMs to the host.
  114. Usage::
  115. # To create and provision the VM:
  116. vagrant up OS
  117. # To create an ssh session to the VM:
  118. vagrant ssh OS command
  119. # To shut down the VM:
  120. vagrant halt OS
  121. # To shut down and destroy the VM:
  122. vagrant destroy OS
  123. # To copy files from the VM (in this case, the generated binary):
  124. vagrant scp OS:/vagrant/borg/borg.exe .
  125. Creating standalone binaries
  126. ----------------------------
  127. Make sure you have everything built and installed (including llfuse and fuse).
  128. When using the Vagrant VMs, pyinstaller will already be installed.
  129. With virtual env activated::
  130. pip install pyinstaller # or git checkout master
  131. pyinstaller -F -n borg-PLATFORM borg/__main__.py
  132. for file in dist/borg-*; do gpg --armor --detach-sign $file; done
  133. If you encounter issues, see also our `Vagrantfile` for details.
  134. .. note:: Standalone binaries built with pyinstaller are supposed to
  135. work on same OS, same architecture (x86 32bit, amd64 64bit)
  136. without external dependencies.
  137. Creating a new release
  138. ----------------------
  139. Checklist:
  140. - make sure all issues for this milestone are closed or moved to the
  141. next milestone
  142. - find and fix any low hanging fruit left on the issue tracker
  143. - check that Travis CI is happy
  144. - update ``CHANGES.rst``, based on ``git log $PREVIOUS_RELEASE..``
  145. - check version number of upcoming release in ``CHANGES.rst``
  146. - verify that ``MANIFEST.in`` and ``setup.py`` are complete
  147. - ``python setup.py build_api ; python setup.py build_usage`` and commit
  148. - tag the release::
  149. git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z
  150. - create a clean repo and use it for the following steps::
  151. git clone borg borg-clean
  152. This makes sure no uncommitted files get into the release archive.
  153. It also will find if you forgot to commit something that is needed.
  154. It also makes sure the vagrant machines only get committed files and
  155. do a fresh start based on that.
  156. - run tox and/or binary builds on all supported platforms via vagrant,
  157. check for test failures
  158. - create a release on PyPi::
  159. python setup.py register sdist upload --identity="Thomas Waldmann" --sign
  160. - close release milestone on Github
  161. - announce on:
  162. - Mailing list
  163. - Twitter (follow @ThomasJWaldmann for these tweets)
  164. - IRC channel (change ``/topic``)
  165. - create a Github release, include:
  166. * standalone binaries (see above for how to create them)
  167. + for OS X, document the OS X Fuse version in the README of the binaries.
  168. OS X FUSE uses a kernel extension that needs to be compatible with the
  169. code contained in the binary.
  170. * a link to ``CHANGES.rst``