|
| 1 | +# Contributing to labthings-fastapi |
| 2 | + |
| 3 | +First off, thank you for considering contributing to `labthings-fastapi`! We welcome contributions from everyone, whether it's reporting a bug, suggesting a feature, improving documentation, or writing code. |
| 4 | + |
| 5 | +This document outlines the processes for getting help, reporting issues, and contributing to the codebase. |
| 6 | + |
| 7 | +## Seeking Support |
| 8 | + |
| 9 | +If you have a question about how to use `labthings-fastapi`, or if you are running into trouble: |
| 10 | + |
| 11 | +* **Check the Documentation:** Please review the official documentation on [readthedocs]. |
| 12 | +* **GitHub Discussions / Issues:** If you cannot find the answer, feel free to open an issue on our [GitHub Issues page]. |
| 13 | +* **OpenFlexure Community:** Because `labthings-fastapi` is the underlying framework for v3 of the [OpenFlexure Microscope software], you may also find support by engaging with the broader [OpenFlexure Forum]. |
| 14 | + |
| 15 | +## Reporting Issues or Bugs |
| 16 | + |
| 17 | +If you find a bug or have a feature request, please report it by opening an issue on our [GitHub Issues page]. |
| 18 | + |
| 19 | +When reporting an issue, please include as much detail as possible: |
| 20 | + |
| 21 | +* **Description:** A clear and concise description of what the bug is. |
| 22 | +* **Reproduction steps:** How can we reproduce the problem? (A minimal reproducible example is highly appreciated). |
| 23 | +* **Expected behaviour:** What did you expect to happen? |
| 24 | +* **Environment:** Include your OS, Python version, and `labthings-fastapi` version. Include full error tracebacks if applicable. |
| 25 | + |
| 26 | +## Contributing Code or Documentation |
| 27 | + |
| 28 | +We welcome pull requests for bug fixes, new features, and documentation improvements. |
| 29 | + |
| 30 | +### 1. Local Development Setup |
| 31 | + |
| 32 | +To work on the code, you will need to clone the repository and install the development dependencies. |
| 33 | +Please see the [installation notes](./README.md#installation-notes) for more detail about compatible Python versions and Windows installation. |
| 34 | + |
| 35 | +```bash |
| 36 | +# Clone the repository |
| 37 | +git clone https://github.com/labthings/labthings-fastapi.git |
| 38 | +cd labthings-fastapi |
| 39 | + |
| 40 | +# Install the package in editable mode with development dependencies |
| 41 | +pip install -r dev-requirements.txt |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. Linting and Testing |
| 45 | + |
| 46 | +We use several tools to maintain code quality. All of these run in CI with [GitHub Actions], but you should run them locally before submitting a Pull Request. Both `ruff` and `flake8` are configured from [`pyproject.toml`]. |
| 47 | + |
| 48 | +* **Linting:** We use [`ruff`] for fast linting and formatting. We highly recommend setting up a pre-commit hook to ensure [`ruff`] passes on every commit. |
| 49 | + ```bash |
| 50 | + ruff format --check |
| 51 | + ruff check . |
| 52 | + ``` |
| 53 | + |
| 54 | +* **Docstrings:** [`flake8`] is primarily used to enable stricter checks on docstrings. |
| 55 | + ```bash |
| 56 | + flake8 src |
| 57 | + ``` |
| 58 | + |
| 59 | +* **Spelling:** We use [`codespell`] to prevent common spelling mistakes in code and documentation. |
| 60 | + ```bash |
| 61 | + codespell . |
| 62 | + ``` |
| 63 | + |
| 64 | +* **Type Checking:** We use [`mypy`] for static type checking. It is configured in `pyproject.toml`. |
| 65 | + ```bash |
| 66 | + mypy |
| 67 | + ``` |
| 68 | + |
| 69 | +* **Testing:** We use [`pytest`] for our test suite and test coverage. Ensure all tests pass locally. |
| 70 | + ```bash |
| 71 | + pytest --cov=src |
| 72 | + ``` |
| 73 | + |
| 74 | +### 3. Managing Dependencies |
| 75 | + |
| 76 | +Dependencies are defined in [`pyproject.toml`]. If you need to compile a `dev-requirements.txt` file (e.g., for reproducible CI/CD or local isolated environments), you can do so using [`uv`]: |
| 77 | + |
| 78 | +```bash |
| 79 | +uv pip compile --extra dev pyproject.toml --output-file dev-requirements.txt |
| 80 | +``` |
| 81 | + |
| 82 | +*(If you're not using `uv`, regular `pip-compile` from `pip-tools` will achieve the same thing).* |
| 83 | + |
| 84 | +### 4. Submitting a Pull Request (PR) |
| 85 | + |
| 86 | +All changes to the codebase must go via pull requests. Unless you are a core maintainer with write access, please use the standard fork-and-branch workflow: |
| 87 | + |
| 88 | +1. **Fork the repository** to your own GitHub account using the "Fork" button at the top of the repository page. |
| 89 | +2. **Clone your fork** locally and set up the upstream remote: |
| 90 | + ```bash |
| 91 | + git clone https://github.com/YOUR-USERNAME/labthings-fastapi.git |
| 92 | + cd labthings-fastapi |
| 93 | + git remote add upstream https://github.com/labthings/labthings-fastapi.git |
| 94 | + ``` |
| 95 | +3. **Create a new branch** for your feature or bugfix: |
| 96 | + ```bash |
| 97 | + git checkout -b feature-name |
| 98 | + ``` |
| 99 | +4. **Commit your changes** with clear, descriptive commit messages. |
| 100 | +5. **Push your branch** up to your fork: |
| 101 | + ```bash |
| 102 | + git push origin feature-name |
| 103 | + ``` |
| 104 | +6. **Open a Pull Request** against the `main` branch of the `labthings/labthings-fastapi` repository. |
| 105 | + |
| 106 | +**Pull Request Guidelines:** |
| 107 | + |
| 108 | +* Code should only be merged once all the checks in the CI test job are passing. |
| 109 | +* **Unpinned Dependencies:** Note that we have a specific CI job called `test-with-unpinned-dependencies`. It is acceptable to merge code if only this specific job fails, provided the failure is due to upstream dependency issues. We prefer to deal with upstream dependency issues in a separate PR, particularly when the required fixes are distinct from the code in your current PR. The same applies to the `pip-audit` job. |
| 110 | +* Update documentation (`docs/` or docstrings) if your changes modify existing behavior or add new features. |
| 111 | + |
| 112 | +[readthedocs]: https://labthings-fastapi.readthedocs.io/ |
| 113 | +[GitHub Issues page]: https://github.com/labthings/labthings-fastapi/issues |
| 114 | +[OpenFlexure Forum]: https://openflexure.discourse.group/ |
| 115 | +[OpenFlexure Microscope software]: https://gitlab.com/openflexure/openflexure-microscope-server/ |
| 116 | +[GitHub Actions]: https://github.com/labthings/labthings-fastapi/actions |
| 117 | +[`ruff`]: https://docs.astral.sh/ruff/ |
| 118 | +[`pyproject.toml`]: ./pyproject.toml |
| 119 | +[`flake8`]: https://flake8.pycqa.org/en/latest/ |
| 120 | +[`mypy`]: https://mypy-lang.org/ |
| 121 | +[`pytest`]: https://docs.pytest.org/en/stable/ |
| 122 | +[`uv`]: https://docs.astral.sh/uv/ |
0 commit comments