development.rst 8.7 KB

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