development.rst 8.1 KB

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