CONTRIBUTING.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. All functionality should be available in pure Python. Optional Rust
  2. implementations may be written for performance reasons, but should never
  3. replace the Python implementation.
  4. Where possible include updates to NEWS along with your improvements.
  5. New functionality and bug fixes should be accompanied by matching unit tests.
  6. Installing development dependencies
  7. -----------------------------------
  8. Contributing to Dulwich requires several more dependencies than are required to install
  9. the base package; they are used to run tests and various other checks.
  10. First, make sure your system has the Rust compiler and Cargo (the Rust package manager)
  11. installed. As this is a system-level requirement and not a Python library, the right way
  12. to install it depends on your platform. Please consult the `Rust documentation
  13. <https://www.rust-lang.org/learn/get-started>`__ to find out more.
  14. Next, you will need to set up your Python environment for Dulwich. An easy way to get
  15. started is to install the checked out Dulwich package in editable mode with ``dev``
  16. extras, preferably in a new virtual environment:
  17. .. code:: console
  18. $ cd ~/path/to/checkouts/dulwich
  19. # Create and activate a virtual environment via your favourite method, such as pyenv,
  20. # uv, built-in venv module...
  21. $ python -m venv .venv && . .venv/bin/activate
  22. # Now install Dulwich and the required dependencies
  23. $ pip install -e ".[dev]"
  24. This will ensure the tools needed to test your changes are installed. It is not necessary
  25. to install Dulwich in editable mode (``-e``), but doing so is convenient for development,
  26. as code changes will be visible immediately, without requiring a reinstall (although any
  27. running Python processes will need to be reloaded to see the updated module
  28. definitions). Editable mode only applies to Python code; if you modify any of the Rust
  29. extension code, you will need to reinstall the package for the extensions to be
  30. recompiled.
  31. There are also other, optional dependencies which are needed to run the full test suite,
  32. implement optional features, and provide the full typing information. They are however not
  33. strictly necessary; the above is sufficient to start developing and have your PR pass the
  34. tests in most cases. Please consult the ``[project.optional-dependencies]`` section in
  35. ``pyproject.toml`` and the various targets in ``Makefile`` for a full list of optional
  36. dependencies.
  37. Coding style
  38. ------------
  39. The code follows the PEP8 coding style. There are ``ruff`` rules in place that define the
  40. exact code style, please run it to make sure your changes are conformant. See also "Style
  41. and typing checks" below for details on running style checkers.
  42. Public methods, functions and classes should all have doc strings. Please use
  43. Google style docstrings to document parameters and return values.
  44. You can generate the documentation by running "make doc".
  45. String Types
  46. ~~~~~~~~~~~~
  47. Like Linux, Git treats filenames as arbitrary bytestrings. There is no prescribed
  48. encoding for these strings, and although it is fairly common to use UTF-8, any
  49. raw byte strings are supported.
  50. For this reason, the lower levels in Dulwich treat git-based filenames as
  51. bytestrings. It is up to the Dulwich API user to encode and decode them if
  52. necessary. The porcelain may accept unicode strings and convert them to
  53. bytestrings as necessary on the fly (using 'utf-8').
  54. * on-disk filenames: regular strings, or ideally, pathlib.Path instances
  55. * git-repository related filenames: bytes
  56. * object sha1 digests (20 bytes long): bytes
  57. * object sha1 hexdigests (40 bytes long): str (bytestrings on python2, strings
  58. on python3)
  59. Exceptions
  60. ~~~~~~~~~~
  61. When catching exceptions, please catch the specific exception type rather than
  62. a more generic type (like OSError, IOError, Exception, etc.). This will
  63. ensure that you do not accidentally catch unrelated exceptions.
  64. The only exception is when you are reraising an exception, e.g. when
  65. re-raising an exception after logging it.
  66. Do not catch bare except, although ruff will warn you about this.
  67. Keep the code within a try/except block as small as possible, so
  68. that you do not accidentally catch unrelated exceptions.
  69. Deprecating functionality
  70. ~~~~~~~~~~~~~~~~~~~~~~~~~
  71. Dulwich uses the `dissolve` package to manage deprecations. If you want to deprecate
  72. functionality, please use the `@replace_me` decorator from the root of the
  73. dulwich package. This will ensure that the deprecation is handled correctly:
  74. * It will be logged as a warning
  75. * When the version of Dulwich is bumped, the deprecation will be removed
  76. * Users can use `dissolve migrate` to automatically replace deprecated
  77. functionality in their code
  78. Running the tests
  79. -----------------
  80. To run the testsuite, you should be able to simply run "make check". This
  81. will run the tests using unittest.
  82. .. code:: console
  83. $ make check
  84. The compatibility tests that verify Dulwich behaves in a way that is compatible
  85. with C Git are the slowest, so you may want to avoid them while developing:
  86. .. code:: console
  87. $ make check-nocompat
  88. testr and tox configuration is also present.
  89. Style and typing checks
  90. -----------------------
  91. Use ``make all-style`` to run all style-related checks. Use ``make typing`` for typing
  92. checks. Those checks are *mandatory*, a PR will not pass tests and will not be merged if
  93. they aren't successful.
  94. .. code:: console
  95. $ make all-style
  96. $ make typing
  97. Some of these checks will modify the code to fix issues encountered, remember to commit
  98. these changes afterwards!
  99. There are also individual ``make`` targets to run just a single style check, see the
  100. definition of ``all-style`` in ``Makefile``.
  101. Merge requests
  102. --------------
  103. Please either send pull requests to the maintainer (jelmer@jelmer.uk) or create
  104. new pull requests on GitHub.
  105. Licensing
  106. ---------
  107. All contributions should be made under the same license that Dulwich itself
  108. comes under: both Apache License, version 2.0 or later and GNU General Public
  109. License, version 2.0 or later.