development.rst 7.4 KB

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