|
| 1 | +# Contributing to pymavswarm |
| 2 | + |
| 3 | +Thank you for considering contributing to `pymavswarm`! This document serves |
| 4 | +to provide a set of guidelines for contributing. |
| 5 | + |
| 6 | +Contributions include but are not restricted to: |
| 7 | + |
| 8 | +- Contributing to the `pymavswarm` codebase |
| 9 | +- Writing documentation |
| 10 | +- Writing tests |
| 11 | +- Performing field tests |
| 12 | +- Reporting bugs |
| 13 | +- Answering [discussion questions](https://github.com/unl-nimbus-lab/pymavswarm/discussions) |
| 14 | + |
| 15 | +## Workflow |
| 16 | + |
| 17 | +- Send all pull requests to the `main` branch (unless otherwise requested) |
| 18 | +- Limit each pull request to resolving a single [issue](https://github.com/unl-nimbus-lab/pymavswarm/issues) |
| 19 | +- It is your responsibility to ensure that your development branch is up-to-date |
| 20 | +with the `main` branch. You may either rebase on `main` or merge `main` into |
| 21 | +your development branch. |
| 22 | +- Always test and document your code. We also encourage performing field tests |
| 23 | +for significant changes. |
| 24 | +- Ensure that your changes pass our CI. We will not review your PR until the CI |
| 25 | +passes. |
| 26 | + |
| 27 | +## Setting up a local development environment |
| 28 | + |
| 29 | +`pymavswarm` provides two ways to configure a local development environment: |
| 30 | + |
| 31 | +1. Using our [VSCode development container](https://code.visualstudio.com/docs/remote/containers) |
| 32 | +2. Using [Pipenv](https://pipenv.pypa.io/en/latest/) |
| 33 | + |
| 34 | +A VSCode development container has been provided to offer a fully sandboxed |
| 35 | +development environment. This environment includes all development Python |
| 36 | +packages (e.g., `pre-commit`) used by the `pymavswarm` development team and |
| 37 | +utilizes a variety of VSCode packages that make it easy to run tests and to |
| 38 | +ensure that all style conventions are followed. Follow the instructions |
| 39 | +[here](https://code.visualstudio.com/docs/remote/containers) to learn how to |
| 40 | +install and launch development containers using VSCode. Once these steps have |
| 41 | +been completed, launch the `pymavswarm` project using the provided development |
| 42 | +image. Launching the development image will also install `pymavswarm` in |
| 43 | +editable mode. |
| 44 | + |
| 45 | +A `Pipfile` has also been provided to enable support for creating and managing |
| 46 | +a [virtual environment](https://virtualenv.pypa.io/en/latest/) using |
| 47 | +[Pipenv](https://pipenv.pypa.io/en/latest/). To use a virtual environment, |
| 48 | +first ensure that `pipenv` has been [installed](https://pipenv.pypa.io/en/latest/). |
| 49 | +After successfully installing `pipenv`, navigate to the base `pymavswarm/` |
| 50 | +directory: |
| 51 | + |
| 52 | +```bash |
| 53 | +cd path/to/pymavswarm/ |
| 54 | +``` |
| 55 | + |
| 56 | +Next, install the project dependencies: |
| 57 | + |
| 58 | +```bash |
| 59 | +pipenv install --dev |
| 60 | +``` |
| 61 | + |
| 62 | +We also recommend installing `pymavswarm` in editable mode: |
| 63 | + |
| 64 | +```bash |
| 65 | +pip3 install -e . |
| 66 | +``` |
| 67 | + |
| 68 | +Finally, launch the virtual environment: |
| 69 | + |
| 70 | +```bash |
| 71 | +pipenv shell |
| 72 | +``` |
| 73 | + |
| 74 | +At this point, running the project tests should work and pass (in both the |
| 75 | +development container and the virtual environment): |
| 76 | + |
| 77 | +```bash |
| 78 | +python3 -m unittest |
| 79 | +``` |
| 80 | + |
| 81 | +## Coding guidelines |
| 82 | + |
| 83 | +The following section documents the `pymavswarm` coding guidelines (e.g., |
| 84 | +styling, convention, etc.) |
| 85 | + |
| 86 | +### Linting |
| 87 | + |
| 88 | +`pymavswarm` uses `pre-commit` to run code formatting checks such as `black`, |
| 89 | +`flake8`, `pydocstyle`, and `isort`. If you have installed the project |
| 90 | +using one of our recommended local development configurations, you may run |
| 91 | +`pre-commit` using the following command: |
| 92 | + |
| 93 | +```bash |
| 94 | +pre-commit run --all-files |
| 95 | +``` |
| 96 | + |
| 97 | +We *strongly* recommend running `pre-commit` before committing your code to |
| 98 | +ensure that your commit follows our code style conventions. Any warnings from |
| 99 | +these checks will cause the CI to fail. |
| 100 | + |
| 101 | +### Type hints |
| 102 | + |
| 103 | +`pymavswarm` uses [PEP 484](https://peps.python.org/pep-0484/) type-hints. Any |
| 104 | +new development should use type hints. When using type-hints, it is preferred |
| 105 | +that built-in types are used (see [PEP 585](https://peps.python.org/pep-0585/)). |
| 106 | +The `Optional` type-hint should be avoided in favor of `| None`. For example, |
| 107 | +rather than |
| 108 | + |
| 109 | +```python |
| 110 | +from typing import Optional |
| 111 | + |
| 112 | +agent_location: Optional[Location] = None |
| 113 | +``` |
| 114 | + |
| 115 | +You should use |
| 116 | + |
| 117 | +```python |
| 118 | +from __future__ import annotations |
| 119 | + |
| 120 | +agent_location: Location | None = None |
| 121 | +``` |
| 122 | + |
| 123 | +Commonly used types will appear in `pymavswarm._types`. These should be used |
| 124 | +where applicable. |
| 125 | + |
| 126 | +## Writing documentation |
| 127 | + |
| 128 | +`pymavswarm` uses Sphinx to generate online developer documentation from |
| 129 | +docstrings. Broadly, docstrings should adhere to |
| 130 | +[PEP 257](https://peps.python.org/pep-0257/), unless otherwise specified. |
| 131 | + |
| 132 | +All docstrings should use triple quotation marks. Multi-line docstrings should |
| 133 | +start on new-lines. Parameters and their types should be prefaced with `:param` |
| 134 | +and `:type`, respectively. All methods should have a short summary. An extended |
| 135 | +summary should be used when an in-depth explanation of a method is required. |
| 136 | + |
| 137 | +The following example demonstrates the Sphinx markdown conventions used by |
| 138 | +`pymavswarm`: |
| 139 | + |
| 140 | +```python |
| 141 | +def compute_location(current_location: Location | None = None) -> Location | None: |
| 142 | + """ |
| 143 | + Demonstrate how to write a docstring. |
| 144 | +
|
| 145 | + Docstrings are a great way to add developer documentation. |
| 146 | +
|
| 147 | + :param current_location: current location of an agent, defaults to None |
| 148 | + :type current_location: Location | None, optional |
| 149 | + :return: computed agent location |
| 150 | + :rtype: Location | None |
| 151 | + """ |
| 152 | + return current_location |
| 153 | +``` |
| 154 | + |
| 155 | +### Testing |
| 156 | + |
| 157 | +Unit tests should be implemented using `unittest`. Unit tests should be |
| 158 | +implemented whenever possible. Functional tests should be named `def test_*`. |
| 159 | +It is suggested that field tests are also performed when adding a code |
| 160 | +contribution; however, this is not required (we understand that not everyone |
| 161 | +has a fleet of drones laying around). |
| 162 | + |
| 163 | +## Support |
| 164 | + |
| 165 | +If you have questions regarding your contribution, please create a new |
| 166 | +discussion post on the `pymavswarm` [Discussions](https://github.com/unl-nimbus-lab/pymavswarm/discussions) |
| 167 | +board. |
0 commit comments