development.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. - make your PRs on the ``master`` branch (see `Branching Model`_ for details)
  15. - do clean changesets:
  16. - focus on some topic, resist changing anything else.
  17. - do not do style changes mixed with functional changes.
  18. - try to avoid refactorings mixed with functional changes.
  19. - if you need to fix something after commit/push:
  20. - if there are ongoing reviews: do a fixup commit you can
  21. merge into the bad commit later.
  22. - if there are no ongoing reviews or you did not push the
  23. bad commit yet: edit the commit to include your fix or
  24. merge the fixup commit before pushing.
  25. - have a nice, clear, typo-free commit comment
  26. - if you fixed an issue, refer to it in your commit comment
  27. - follow the style guide (see below)
  28. - if you write new code, please add tests and docs for it
  29. - run the tests, fix anything that comes up
  30. - make a pull request on github
  31. - wait for review by other developers
  32. Branching model
  33. ---------------
  34. Borg development happens on the ``master`` branch and uses GitHub pull
  35. requests (if you don't have GitHub or don't want to use it you can
  36. send smaller patches via the borgbackup :ref:`mailing_list` to the maintainers).
  37. Stable releases are maintained on maintenance branches named x.y-maint, eg.
  38. the maintenance branch of the 1.0.x series is 1.0-maint.
  39. Most PRs should be made against the ``master`` branch. Only if an
  40. issue affects **only** a particular maintenance branch a PR should be
  41. made against it directly.
  42. While discussing / reviewing a PR it will be decided whether the
  43. change should be applied to maintenance branch(es). Each maintenance
  44. branch has a corresponding *backport/x.y-maint* label, which will then
  45. be applied.
  46. Changes that are typically considered for backporting:
  47. - Data loss, corruption and inaccessibility fixes
  48. - Security fixes
  49. - Forward-compatibility improvements
  50. - Documentation corrections
  51. .. rubric:: Maintainer part
  52. From time to time a maintainer will backport the changes for a
  53. maintenance branch, typically before a release or if enough changes
  54. were collected:
  55. 1. Notify others that you're doing this to avoid duplicate work.
  56. 2. Branch a backporting branch off the maintenance branch.
  57. 3. Cherry pick and backport the changes from each labelled PR, remove
  58. the label for each PR you've backported.
  59. 4. Make a PR of the backporting branch against the maintenance branch
  60. for backport review. Mention the backported PRs in this PR, eg:
  61. Includes changes from #2055 #2057 #2381
  62. This way GitHub will automatically show in these PRs where they
  63. were backported.
  64. .. rubric:: Historic model
  65. Previously (until release 1.0.10) Borg used a `"merge upwards"
  66. <https://git-scm.com/docs/gitworkflows#_merging_upwards>`_ model where
  67. most minor changes and fixes where committed to a maintenance branch
  68. (eg. 1.0-maint), and the maintenance branch(es) were regularly merged
  69. back into the main development branch. This became more and more
  70. troublesome due to merges growing more conflict-heavy and error-prone.
  71. Code and issues
  72. ---------------
  73. Code is stored on Github, in the `Borgbackup organization
  74. <https://github.com/borgbackup/borg/>`_. `Issues
  75. <https://github.com/borgbackup/borg/issues>`_ and `pull requests
  76. <https://github.com/borgbackup/borg/pulls>`_ should be sent there as
  77. well. See also the :ref:`support` section for more details.
  78. Style guide
  79. -----------
  80. We generally follow `pep8
  81. <https://www.python.org/dev/peps/pep-0008/>`_, with 120 columns
  82. instead of 79. We do *not* use form-feed (``^L``) characters to
  83. separate sections either. Compliance is tested automatically when
  84. you run the tests.
  85. Continuous Integration
  86. ----------------------
  87. All pull requests go through Travis-CI_, which runs the tests on Linux
  88. and Mac OS X as well as the flake8 style checker. Windows builds run on AppVeyor_,
  89. while additional Unix-like platforms are tested on Golem_.
  90. .. _AppVeyor: https://ci.appveyor.com/project/borgbackup/borg/
  91. .. _Golem: https://golem.enkore.de/view/Borg/
  92. .. _Travis-CI: https://travis-ci.org/borgbackup/borg
  93. Output and Logging
  94. ------------------
  95. When writing logger calls, always use correct log level (debug only for
  96. debugging, info for informative messages, warning for warnings, error for
  97. errors, critical for critical errors/states).
  98. When directly talking to the user (e.g. Y/N questions), do not use logging,
  99. but directly output to stderr (not: stdout, it could be connected to a pipe).
  100. To control the amount and kinds of messages output emitted at info level, use
  101. flags like ``--stats`` or ``--list``, then create a topic logger for messages
  102. controlled by that flag. See ``_setup_implied_logging()`` in
  103. ``borg/archiver.py`` for the entry point to topic logging.
  104. Building a development environment
  105. ----------------------------------
  106. First, just install borg into a virtual env as described before.
  107. To install some additional packages needed for running the tests, activate your
  108. virtual env and run::
  109. pip install -r requirements.d/development.txt
  110. Running the tests
  111. -----------------
  112. The tests are in the borg/testsuite package.
  113. To run all the tests, you need to have fakeroot installed. If you do not have
  114. fakeroot, you still will be able to run most tests, just leave away the
  115. `fakeroot -u` from the given command lines.
  116. To run the test suite use the following command::
  117. fakeroot -u tox # run all tests
  118. Some more advanced examples::
  119. # verify a changed tox.ini (run this after any change to tox.ini):
  120. fakeroot -u tox --recreate
  121. fakeroot -u tox -e py34 # run all tests, but only on python 3.4
  122. fakeroot -u tox borg.testsuite.locking # only run 1 test module
  123. fakeroot -u tox borg.testsuite.locking -- -k '"not Timer"' # exclude some tests
  124. fakeroot -u tox borg.testsuite -- -v # verbose py.test
  125. Important notes:
  126. - When using ``--`` to give options to py.test, you MUST also give ``borg.testsuite[.module]``.
  127. Documentation
  128. -------------
  129. Generated files
  130. ~~~~~~~~~~~~~~~
  131. Usage documentation (found in ``docs/usage/``) and man pages
  132. (``docs/man/``) are generated automatically from the command line
  133. parsers declared in the program and their documentation, which is
  134. embedded in the program (see archiver.py). These are committed to git
  135. for easier use by packagers downstream.
  136. When a command is added, a commandline flag changed, added or removed,
  137. the usage docs need to be rebuilt as well::
  138. python setup.py build_usage
  139. python setup.py build_man
  140. However, we prefer to do this as part of our :ref:`releasing`
  141. preparations, so it is generally not necessary to update these when
  142. submitting patches that change something about the command line.
  143. The code documentation (which is currently not part of the released
  144. docs) also uses a generated file (``docs/api.rst``), that needs to be
  145. updated when a module is added or removed::
  146. python setup.py build_api
  147. Building the docs with Sphinx
  148. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. The documentation (in reStructuredText format, .rst) is in docs/.
  150. To build the html version of it, you need to have sphinx installed::
  151. pip3 install sphinx sphinx_rtd_theme # important: this will install sphinx with Python 3
  152. Now run::
  153. cd docs/
  154. make html
  155. Then point a web browser at docs/_build/html/index.html.
  156. The website is updated automatically through Github web hooks on the
  157. main repository.
  158. Using Vagrant
  159. -------------
  160. We use Vagrant for the automated creation of testing environments and borgbackup
  161. standalone binaries for various platforms.
  162. For better security, there is no automatic sync in the VM to host direction.
  163. The plugin `vagrant-scp` is useful to copy stuff from the VMs to the host.
  164. Usage::
  165. # To create and provision the VM:
  166. vagrant up OS
  167. # To create an ssh session to the VM:
  168. vagrant ssh OS
  169. # To execute a command via ssh in the VM:
  170. vagrant ssh OS -c "command args"
  171. # To shut down the VM:
  172. vagrant halt OS
  173. # To shut down and destroy the VM:
  174. vagrant destroy OS
  175. # To copy files from the VM (in this case, the generated binary):
  176. vagrant scp OS:/vagrant/borg/borg.exe .
  177. Creating standalone binaries
  178. ----------------------------
  179. Make sure you have everything built and installed (including llfuse and fuse).
  180. When using the Vagrant VMs, pyinstaller will already be installed.
  181. With virtual env activated::
  182. pip install pyinstaller # or git checkout master
  183. pyinstaller -F -n borg-PLATFORM borg/__main__.py
  184. for file in dist/borg-*; do gpg --armor --detach-sign $file; done
  185. If you encounter issues, see also our `Vagrantfile` for details.
  186. .. note:: Standalone binaries built with pyinstaller are supposed to
  187. work on same OS, same architecture (x86 32bit, amd64 64bit)
  188. without external dependencies.
  189. Merging maintenance branches
  190. ----------------------------
  191. As mentioned above bug fixes will usually be merged into a maintenance branch (x.y-maint) and then
  192. merged back into the master branch. Large diffs between these branches can make automatic merges troublesome,
  193. therefore we recommend to use these merge parameters::
  194. git merge 1.0-maint -s recursive -X rename-threshold=20%
  195. .. _releasing:
  196. Creating a new release
  197. ----------------------
  198. Checklist:
  199. - make sure all issues for this milestone are closed or moved to the
  200. next milestone
  201. - find and fix any low hanging fruit left on the issue tracker
  202. - check that Travis CI is happy
  203. - update ``CHANGES.rst``, based on ``git log $PREVIOUS_RELEASE..``
  204. - check version number of upcoming release in ``CHANGES.rst``
  205. - verify that ``MANIFEST.in`` and ``setup.py`` are complete
  206. - ``python setup.py build_api ; python setup.py build_usage ; python setup.py build_man`` and commit
  207. - tag the release::
  208. git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z
  209. - create a clean repo and use it for the following steps::
  210. git clone borg borg-clean
  211. This makes sure no uncommitted files get into the release archive.
  212. It also will find if you forgot to commit something that is needed.
  213. It also makes sure the vagrant machines only get committed files and
  214. do a fresh start based on that.
  215. - run tox and/or binary builds on all supported platforms via vagrant,
  216. check for test failures
  217. - create a release on PyPi::
  218. python setup.py register sdist upload --identity="Thomas Waldmann" --sign
  219. - close release milestone on Github
  220. - announce on:
  221. - Mailing list
  222. - Twitter (follow @ThomasJWaldmann for these tweets)
  223. - IRC channel (change ``/topic``)
  224. - create a Github release, include:
  225. * standalone binaries (see above for how to create them)
  226. + for OS X, document the OS X Fuse version in the README of the binaries.
  227. OS X FUSE uses a kernel extension that needs to be compatible with the
  228. code contained in the binary.
  229. * a link to ``CHANGES.rst``