development.rst 6.5 KB

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