Debian Codegraph @

.github/contributing.md

raw symbols SCIP
1 ## Environment Setup
2
3 1. We use [uv](https://docs.astral.sh/uv/) for managing virtual environments and dependencies.
4 Once uv is installed, run `uv sync --all-extras` in this repo to get started.
5 2. For managing linters, static-analysis, and other tools, we use [pre-commit](https://pre-commit.com/#installation).
6 Once Pre-commit is installed, run `uv run pre-commit install` in this repo to install the hooks.
7 Using pre-commit ensures PRs match the linting requirements of the codebase.
8
9 ## Documentation
10 Whenever possible, please add docstrings to your code!
11 We use [numpy-style napoleon docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/#google-vs-numpy).
12 To confirm docstrings are valid, build the docs by running `uv run make html` in the `docs/` folder.
13
14 I typically write docstrings first, it will act as a guide to limit scope and encourage unit-testable code.
15 Good docstrings include information like:
16
17 1. If not immediately obvious, what is the intended use-case? When should this function be used?
18 2. What happens during errors/edge-cases.
19 3. When dealing with physical values, include units.
20
21 ## Unit Tests
22 We use the [pytest](https://docs.pytest.org/) framework for unit testing. Ideally, all new code is partnered with
23 new unit tests to exercise that code. If fixing a bug, consider writing the test first to confirm the existence of the
24 bug, and to confirm that the new code fixes it.
25
26 Unit tests should only test a single concise body of code. If this is hard to do, there are two solutions that can help:
27 1. Restructure the code. Keep inputs/outputs to be simple variables. Avoid complicated interactions with state.
28 2. Use [pytest-mock](https://pytest-mock.readthedocs.io/en/latest/) to mock out external interactions.
29 3. Run tests with `python -m pytest`.
30
31 ## Coding Style
32 In an attempt to keep consistency and maintainability in the code-base, here are some high-level guidelines for code that might not be enforced by linters.
33
34 * Use f-strings.
35 * Keep/cast path variables as `pathlib.Path` objects.
36 Do not use `os.path`.
37 For public-facing functions, cast path arguments immediately to `Path`.
38 * Use magic-methods when appropriate. It might be better to implement ``MyClass.__call__()`` instead of ``MyClass.run()``.
39 * Do not return sentinel values for error-states like `-1` or `None`. Instead, raise an exception.
40 * Avoid deeply nested code. Techniques like returning early and breaking up a complicated function into multiple functions results in easier to read and test code.
41 * Consider if you are double-name-spacing and how modules are meant to be imported.
42 E.g. it might be better to name a function `read` instead of `image_read` in the module `my_package/image.py`.
43 Consider the module name-space and whether or not it's flattened in `__init__.py`.
44 * Only use multiple-inheritance if using a mixin. Mixin classes should end in `"Mixin"`.