development.rst 12 KB

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