development.rst 6.1 KB

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