development.rst 6.4 KB

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