|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Please open issues to discuss enhancements and bugs that you may encounter with |
| 4 | +libNeuroML. Pull requests with enhancements and bug fixes are welcome. |
| 5 | + |
| 6 | +## Virtual environments and editable installs |
| 7 | + |
| 8 | +It is best to use [virtual environments](https://docs.python.org/3/tutorial/venv.html) when developing Python packages. |
| 9 | +This ensures that one uses a clean environment that includes the necessary |
| 10 | +dependencies and does not affect the overall system installation. |
| 11 | + |
| 12 | +For quick development, consider using [editable installs](https://setuptools.pypa.io/en/latest/userguide/development_mode.html). |
| 13 | +The dependencies are broken down in the `setup.cfg` file. To get a complete development environment, one can run: |
| 14 | + |
| 15 | + |
| 16 | + pip install -e .[dev] # an editable install with all development dependecies installed |
| 17 | + |
| 18 | + |
| 19 | +## Code style |
| 20 | + |
| 21 | +1. The source code uses spaces, and each tab is equivalent to 4 spaces. |
| 22 | + |
| 23 | +2. We use the [reStructuredText (reST) |
| 24 | + format](https://stackoverflow.com/a/24385103/375067) for Python docstrings. |
| 25 | + Please document your code when opening pull requests. |
| 26 | + All methods/functions/modules *must* include docstrings that explain the parameters. |
| 27 | + |
| 28 | +3. We use [ruff](https://pypi.org/project/ruff/) to format and lint our code. (See the section on pre-commit below.) |
| 29 | + |
| 30 | +4. Please use [type hints](https://docs.python.org/3/library/typing.html) wherever applicable. |
| 31 | + You can set up type checkers such as [mypy](https://mypy.readthedocs.io/) to use type hints in your development environment/IDE. |
| 32 | + |
| 33 | + |
| 34 | + pip install mypy |
| 35 | + |
| 36 | + |
| 37 | +### Pre-commit |
| 38 | + |
| 39 | +A number of [pre-commit](https://pre-commit.com/) hooks are used to improve code-quality. |
| 40 | +Please run the following code to set up the pre-commit hooks: |
| 41 | + |
| 42 | + $ pre-commit install |
| 43 | + |
| 44 | +The hooks will be run at each `git commit`. |
| 45 | +Please see `.pre-commit-config.yaml` for information on what hooks we run. |
| 46 | + |
| 47 | + |
| 48 | +### Commit messages |
| 49 | + |
| 50 | +Writing good commit messages makes things easy to follow. |
| 51 | +Please see these posts: |
| 52 | + |
| 53 | +- [How to write a Git commit message](https://cbea.ms/git-commit/) |
| 54 | +- While not compulsory, we prefer [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) |
| 55 | + |
| 56 | + |
| 57 | +## Tests |
| 58 | + |
| 59 | +Bug fixes and new features should include unit tests to test for correctness. |
| 60 | +One can base new tests off the current ones included in the `tests/` directory. |
| 61 | +To see how tests are run, please see the [GitHub Actions configuration file](https://github.com/NeuralEnsemble/libNeuroML/blob/development/.github/workflows/ci.yml). |
| 62 | + |
| 63 | +We use [pytest](https://docs.pytest.org/) for unit testing. |
| 64 | +One can run it from the root of the repository: |
| 65 | + |
| 66 | + pytest |
| 67 | + |
| 68 | + |
| 69 | +To run specific tests, one can use the `-k` flag: |
| 70 | + |
| 71 | + |
| 72 | + pytest -k "..." |
| 73 | + |
| 74 | + |
| 75 | +## Pull Request Process |
| 76 | + |
| 77 | +1. Please contribute pull requests against the `development` branch. |
| 78 | +2. Please ensure that the automated build for your pull request passes. |
| 79 | +3. Please write good commit messages (see the section above). |
| 80 | + |
| 81 | +### Updating your pull request branch |
| 82 | + |
| 83 | +Over time, as pull requests are reviewed, the `development` branch continues to move on with other changes. |
| 84 | +Sometimes, it can be useful/necessary to pull in these changes to the pull request branch, using the following steps. |
| 85 | + |
| 86 | +Add the upstream libNeuroML repository as a remote: |
| 87 | + |
| 88 | + |
| 89 | + git remote add upstream https://github.com/NeuralEnsemble/libNeuroML.git |
| 90 | + |
| 91 | + |
| 92 | +Update your local copy of the `development` branch, and the remote copy in your fork: |
| 93 | + |
| 94 | + |
| 95 | + git checkout development |
| 96 | + git pull upstream development |
| 97 | + git push |
| 98 | + |
| 99 | + |
| 100 | +Pull in changes from development to your branch: |
| 101 | + |
| 102 | + |
| 103 | + git checkout <feature branch being used for PR> |
| 104 | + git merge development |
| 105 | + |
| 106 | + |
| 107 | +If there are merge conflicts, you will need to [resolve these](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merge_conflicts), since merging the feature branch in the pull request will also result in these. |
| 108 | +After any merge conflicts have been resolved (or if there aren't any), you can |
| 109 | +push your branch to your fork to update the pull request: |
| 110 | + |
| 111 | + |
| 112 | + git push |
0 commit comments