| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 | .. include:: global.rst.inc.. highlight:: bash.. _development:Development===========This chapter will get you started with |project_name| development.|project_name| is written in Python (with a little bit of Cython and C forthe performance critical parts).Contributions-------------... are welcome!Some guidance for contributors:- discuss about changes on github issue tracker, IRC or mailing list- make your PRs on the ``master`` branch (see `Branching Model`_ for details)- do clean changesets:  - focus on some topic, resist changing anything else.  - do not do style changes mixed with functional changes.  - try to avoid refactorings mixed with functional changes.  - if you need to fix something after commit/push:    - if there are ongoing reviews: do a fixup commit you can      merge into the bad commit later.    - if there are no ongoing reviews or you did not push the      bad commit yet: edit the commit to include your fix or      merge the fixup commit before pushing.  - have a nice, clear, typo-free commit comment  - if you fixed an issue, refer to it in your commit comment  - follow the style guide (see below)- if you write new code, please add tests and docs for it- run the tests, fix anything that comes up- make a pull request on github- wait for review by other developersBranching model---------------Borg development happens on the ``master`` branch and uses GitHub pullrequests (if you don't have GitHub or don't want to use it you cansend smaller patches via the borgbackup :ref:`mailing_list` to the maintainers).Stable releases are maintained on maintenance branches named x.y-maint, eg.the maintenance branch of the 1.0.x series is 1.0-maint.Most PRs should be made against the ``master`` branch. Only if anissue affects **only** a particular maintenance branch a PR should bemade against it directly.While discussing / reviewing a PR it will be decided whether thechange should be applied to maintenance branch(es). Each maintenancebranch has a corresponding *backport/x.y-maint* label, which will thenbe applied.Changes that are typically considered for backporting:- Data loss, corruption and inaccessibility fixes- Security fixes- Forward-compatibility improvements- Documentation corrections.. rubric:: Maintainer partFrom time to time a maintainer will backport the changes for amaintenance branch, typically before a release or if enough changeswere collected:1. Notify others that you're doing this to avoid duplicate work.2. Branch a backporting branch off the maintenance branch.3. Cherry pick and backport the changes from each labelled PR, remove   the label for each PR you've backported.4. Make a PR of the backporting branch against the maintenance branch   for backport review. Mention the backported PRs in this PR, eg:       Includes changes from #2055 #2057 #2381   This way GitHub will automatically show in these PRs where they   were backported... rubric:: Historic modelPreviously (until release 1.0.10) Borg used a `"merge upwards"<https://git-scm.com/docs/gitworkflows#_merging_upwards>`_ model wheremost minor changes and fixes where committed to a maintenance branch(eg. 1.0-maint), and the maintenance branch(es) were regularly mergedback into the main development branch. This became more and moretroublesome due to merges growing more conflict-heavy and error-prone.Code and issues---------------Code is stored on Github, in the `Borgbackup organization<https://github.com/borgbackup/borg/>`_. `Issues<https://github.com/borgbackup/borg/issues>`_ and `pull requests<https://github.com/borgbackup/borg/pulls>`_ should be sent there aswell. See also the :ref:`support` section for more details.Style guide-----------We generally follow `pep8<https://www.python.org/dev/peps/pep-0008/>`_, with 120 columnsinstead of 79. We do *not* use form-feed (``^L``) characters toseparate sections either. Compliance is tested automatically whenyou run the tests.Continuous Integration----------------------All pull requests go through Travis-CI_, which runs the tests on Linuxand Mac OS X as well as the flake8 style checker. Additional Unix-like platformsare tested on Golem_... _Golem: https://golem.enkore.de/view/Borg/.. _Travis-CI: https://travis-ci.org/borgbackup/borgOutput and Logging------------------When writing logger calls, always use correct log level (debug only fordebugging, info for informative messages, warning for warnings, error forerrors, critical for critical errors/states).When directly talking to the user (e.g. Y/N questions), do not use logging,but directly output to stderr (not: stdout, it could be connected to a pipe).To control the amount and kinds of messages output to stderr or emitted atinfo level, use flags like ``--stats`` or ``--list``.Building a development environment----------------------------------First, just install borg into a virtual env as described before.To install some additional packages needed for running the tests, activate yourvirtual env and run::  pip install -r requirements.d/development.txtRunning the tests-----------------The tests are in the borg/testsuite package.To run all the tests, you need to have fakeroot installed. If you do not havefakeroot, you still will be able to run most tests, just leave away the`fakeroot -u` from the given command lines.To run the test suite use the following command::  fakeroot -u tox  # run all testsSome more advanced examples::  # verify a changed tox.ini (run this after any change to tox.ini):  fakeroot -u tox --recreate  fakeroot -u tox -e py34  # run all tests, but only on python 3.4  fakeroot -u tox borg.testsuite.locking  # only run 1 test module  fakeroot -u tox borg.testsuite.locking -- -k '"not Timer"'  # exclude some tests  fakeroot -u tox borg.testsuite -- -v  # verbose py.testImportant notes:- When using ``--`` to give options to py.test, you MUST also give ``borg.testsuite[.module]``.Regenerate usage files----------------------Usage documentation is currently committed directly to git,although those files are generated automatically from the sourcetree.When a command is added, a commandline flag changed, added or removed,the usage docs need to be rebuilt as well::  ./setup.py build_usageHowever, we prefer to do this as part of our :ref:`releasing`preparations, so it is generally not necessary to update these whensubmitting patches that change something about the command line.Building the docs with Sphinx-----------------------------The documentation (in reStructuredText format, .rst) is in docs/.To build the html version of it, you need to have sphinx installed::  pip3 install sphinx sphinx_rtd_theme  # important: this will install sphinx with Python 3Now run::  cd docs/  make htmlThen point a web browser at docs/_build/html/index.html.The website is updated automatically through Github web hooks on themain repository.Using Vagrant-------------We use Vagrant for the automated creation of testing environments and borgbackupstandalone binaries for various platforms.For better security, there is no automatic sync in the VM to host direction.The plugin `vagrant-scp` is useful to copy stuff from the VMs to the host.Usage::   # To create and provision the VM:   vagrant up OS   # To create an ssh session to the VM:   vagrant ssh OS command   # To shut down the VM:   vagrant halt OS   # To shut down and destroy the VM:   vagrant destroy OS   # To copy files from the VM (in this case, the generated binary):   vagrant scp OS:/vagrant/borg/borg.exe .Creating standalone binaries----------------------------Make sure you have everything built and installed (including llfuse and fuse).When using the Vagrant VMs, pyinstaller will already be installed.With virtual env activated::  pip install pyinstaller  # or git checkout master  pyinstaller -F -n borg-PLATFORM borg/__main__.py  for file in dist/borg-*; do gpg --armor --detach-sign $file; doneIf you encounter issues, see also our `Vagrantfile` for details... note:: Standalone binaries built with pyinstaller are supposed to          work on same OS, same architecture (x86 32bit, amd64 64bit)          without external dependencies.Creating a new release----------------------Checklist:- make sure all issues for this milestone are closed or moved to the  next milestone- check if there are any pending fixes for security issues- find and fix any low hanging fruit left on the issue tracker- check that Travis CI is happy- update ``CHANGES.rst``, based on ``git log $PREVIOUS_RELEASE..``- check version number of upcoming release in ``CHANGES.rst``- verify that ``MANIFEST.in`` and ``setup.py`` are complete- ``python setup.py build_usage`` and commit- tag the release::    git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z- create a clean repo and use it for the following steps::    git clone borg borg-clean  This makes sure no uncommitted files get into the release archive.  It also will find if you forgot to commit something that is needed.  It also makes sure the vagrant machines only get committed files and  do a fresh start based on that.- run tox and/or binary builds on all supported platforms via vagrant,  check for test failures- create a release on PyPi::    python setup.py register sdist upload --identity="Thomas Waldmann" --sign- close release milestone on Github- announce on: - Mailing list - Twitter - IRC channel (change ``/topic``)- create a Github release, include:  * standalone binaries (see above for how to create them)    + for OS X, document the OS X Fuse version in the README of the binaries.      OS X FUSE uses a kernel extension that needs to be compatible with the      code contained in the binary.  * a link to ``CHANGES.rst``
 |