.. include:: global.rst.inc .. highlight:: bash .. _development: Development =========== This chapter will get you started with Borg development. Borg is written in Python (with a little bit of Cython and C for the performance critical parts). Contributions ------------- ... are welcome! Some guidance for contributors: - Discuss changes on the GitHub issue tracker, on IRC or on the 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 squash into the bad commit later. - If there are no ongoing reviews or you did not push the bad commit yet: amend 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 any issues that come up. - Make a pull request on GitHub. - Wait for review by other developers. Branching model --------------- Borg development happens on the ``master`` branch and uses GitHub pull requests (if you don't have GitHub or don't want to use it you can send smaller patches via the borgbackup 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 filed against the ``master`` branch. Only if an issue affects **only** a particular maintenance branch a PR should be filed against it directly. While discussing / reviewing a PR it will be decided whether the change should be applied to maintenance branches. Each maintenance branch has a corresponding *backport/x.y-maint* label, which will then be applied. Changes that are typically considered for backporting: - Data loss, corruption and inaccessibility fixes. - Security fixes. - Forward-compatibility improvements. - Documentation corrections. .. rubric:: Maintainer part From time to time a maintainer will backport the changes for a maintenance branch, typically before a release or if enough changes were 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. To preserve authorship metadata, do not follow the ``git cherry-pick`` instructions to use ``git commit`` after resolving conflicts. Instead, stage conflict resolutions and run ``git cherry-pick --continue``, much like using ``git rebase``. To avoid merge issues (a cherry pick is a form of merge), use these options (similar to the ``git merge`` options used previously, the ``-x`` option adds a reference to the original commit):: git cherry-pick --strategy recursive -X rename-threshold=5% -x 4. Make a PR of the backporting branch against the maintenance branch for backport review. Mention the backported PRs in this PR, e.g.: Includes changes from #2055 #2057 #2381 This way GitHub will automatically show in these PRs where they were backported. .. rubric:: Historic model Previously (until release 1.0.10) Borg used a `"merge upwards" `_ model where most minor changes and fixes where committed to a maintenance branch (eg. 1.0-maint), and the maintenance branch(es) were regularly merged back into the main development branch. This became more and more troublesome due to merges growing more conflict-heavy and error-prone. Code and issues --------------- Code is stored on GitHub, in the `Borgbackup organization `_. `Issues `_ and `pull requests `_ should be sent there as well. See also the :ref:`support` section for more details. Style guide ----------- We generally follow `pep8 `_, with 120 columns instead of 79. We do *not* use form-feed (``^L``) characters to separate sections either. Compliance is tested automatically when you run the tests. Continuous Integration ---------------------- All pull requests go through `GitHub Actions`_, which runs the tests on misc. Python versions and on misc. platforms as well as some additional checks. .. _GitHub Actions: https://github.com/borgbackup/borg/actions Output and Logging ------------------ When writing logger calls, always use correct log level (debug only for debugging, info for informative messages, warning for warnings, error for errors, 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 emitted at info level, use flags like ``--stats`` or ``--list``, then create a topic logger for messages controlled by that flag. See ``_setup_implied_logging()`` in ``borg/archiver.py`` for the entry point to topic logging. Building a development environment ---------------------------------- First, just install borg into a virtual env :ref:`as described before `. To install some additional packages needed for running the tests, activate your virtual env and run:: pip install -r requirements.d/development.txt This project utilizes pre-commit to lint code before it is committed. Although pre-commit is installed when running the command above, the pre-commit hooks will have to be installed separately. Run this command to install the pre-commit hooks:: pre-commit install Running 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 have fakeroot, 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 tests Some more advanced examples:: # verify a changed tox.ini (run this after any change to tox.ini): fakeroot -u tox --recreate fakeroot -u tox -e py39 # run all tests, but only on python 3.9 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.test Important notes: - When using ``--`` to give options to py.test, you MUST also give ``borg.testsuite[.module]``. Running the tests (using the pypi package) ------------------------------------------ Since borg 1.4, it is also possible to run the tests without a development environment, using the borgbackup dist package (downloaded from pypi.org or github releases page):: # optional: create and use a virtual env: python3 -m venv env . env/bin/activate # install packages pip install borgbackup pip install pytest pytest-benchmark # method A: use a pytest.ini cat >pytest.ini <<`_ with the new version number and release date. - Announce on: - Mailing list. - Twitter. - IRC channel (change ``/topic``). - Create a GitHub release, include: * pypi dist package and signature * Standalone binaries (see above for how to create them). + For macOS, document the macFUSE version in the README of the binaries. macFUSE uses a kernel extension that needs to be compatible with the code contained in the binary. * A link to ``CHANGES.rst``.