|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Welcome to our community! Thank you for taking the time to read the following. |
| 4 | + |
| 5 | +## TL;DR |
| 6 | + |
| 7 | +* All code should have tests. |
| 8 | +* All code should be documented. |
| 9 | +* No changes are ever committed without review and approval. |
| 10 | + |
| 11 | +## Project management |
| 12 | + |
| 13 | +* *github* is used for the code base. |
| 14 | +* For a PR to be integrated, it must be approved at least by one core team member. |
| 15 | +* Development discussions happen on Discord but any request **must** be formalized in *github*. This ensures a common history. |
| 16 | +* Continuous Integration is provided by *Github actions* and configuration is located at ``.github/workflows``. |
| 17 | + |
| 18 | +## Code |
| 19 | + |
| 20 | +### Local development |
| 21 | + |
| 22 | +After cloning the repository, install with: |
| 23 | + |
| 24 | +```bash |
| 25 | +$ pip install -e ".[dev]" |
| 26 | +``` |
| 27 | + |
| 28 | +### Testing |
| 29 | + |
| 30 | +Testing your code is paramount. Without continuous integration, we **cannot** |
| 31 | +guaranty the quality of the code. Some minor modification on a function can |
| 32 | +have unexpected implications. With a single commit, everything can go south! |
| 33 | +The ``main`` branch is always on a passing state: CI is green, working code, |
| 34 | +and an installable Python package. |
| 35 | + |
| 36 | +The library [pytest](https://docs.pytest.org/en/latest/) is used with |
| 37 | +[coverage](https://coverage.readthedocs.io/) to ensure the added |
| 38 | +functionalities are covered by tests. |
| 39 | + |
| 40 | +All tests can be launched using: |
| 41 | + |
| 42 | +```bash |
| 43 | +pytest --cov simdec --cov-report term-missing |
| 44 | +``` |
| 45 | + |
| 46 | +The output consists in tests results and coverage report. |
| 47 | + |
| 48 | +> Tests will be automatically launched when you will push your branch to |
| 49 | +> GitHub. Be mindful of this resource! |
| 50 | +
|
| 51 | +### Style |
| 52 | + |
| 53 | +For all python code, developers **must** follow guidelines from the Python Software Foundation. As a quick reference: |
| 54 | + |
| 55 | +* For code: [PEP 8](https://www.python.org/dev/peps/pep-0008/) |
| 56 | +* For documentation: [PEP 257](https://www.python.org/dev/peps/pep-0257/) |
| 57 | +* Use NumPyDoc formatting: [Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) |
| 58 | + |
| 59 | +And for a more Pythonic code: [PEP 20](https://www.python.org/dev/peps/pep-0020/) |
| 60 | +Last but not least, avoid common pitfalls: [Anti-patterns](https://docs.quantifiedcode.com/python-anti-patterns/) |
| 61 | + |
| 62 | +### Linter |
| 63 | + |
| 64 | +Apart from normal unit and integration tests, you can perform a static |
| 65 | +analysis of the code using [black](https://black.readthedocs.io/en/stable/) |
| 66 | +and [ruff](https://github.com/astral-sh/ruff): |
| 67 | + |
| 68 | +```bash |
| 69 | +black . |
| 70 | +ruff . |
| 71 | +``` |
| 72 | + |
| 73 | +This allows to spot naming errors for example as well as other style errors. |
| 74 | + |
| 75 | +## GIT |
| 76 | + |
| 77 | +### Workflow |
| 78 | + |
| 79 | +The development model is based on the Cactus Model also called |
| 80 | +[Trunk Based Development](https://trunkbaseddevelopment.com) model. |
| 81 | +More specificaly, we use the Scaled Trunk-Based Development model. |
| 82 | + |
| 83 | +> Some additional ressources: |
| 84 | +> [gitflow](https://nvie.com/posts/a-successful-git-branching-model/), |
| 85 | +> [gitflow critique](https://barro.github.io/2016/02/a-succesful-git-branching-model-considered-harmful/), |
| 86 | +> [github PR](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges). |
| 87 | +
|
| 88 | +It means that **each** new feature has to go through a new branch. Why? |
| 89 | +For peer review. Pushing directly on the develop without review should be |
| 90 | +exceptional (hotfix)! |
| 91 | + |
| 92 | +This project is using pre-commit hooks. So you have to set it up like this: |
| 93 | + |
| 94 | +```bash |
| 95 | +pre-commit install |
| 96 | +pre-commit run --all-files |
| 97 | +``` |
| 98 | +When you try to commit your changes, it will launch the pre-commit hooks |
| 99 | +(``.pre-commit-config.yaml``) |
| 100 | +and modify the files if there are any changes to be made for the commit to be |
| 101 | +accepted. If you don't use this feature and your changes are not compliant |
| 102 | +(linter), CI will fail. |
| 103 | + |
| 104 | +### Recipe for new feature |
| 105 | + |
| 106 | +If you want to add a modification, create a new branch branching off ``main``. |
| 107 | +Then you can create a merge request on *github*. From here, the fun begins. |
| 108 | + |
| 109 | +> For every commit you push, the linter and tests are launched. |
| 110 | +
|
| 111 | +Your request will only be considered for integration if in a **finished** state: |
| 112 | + |
| 113 | +1. Respect python coding rules, |
| 114 | +2. Have tests regarding the changes, |
| 115 | +3. The branch passes all tests (current and new ones), |
| 116 | +4. Maintain test coverage, |
| 117 | +5. Have the respective documentation. |
| 118 | + |
| 119 | +#### Writing the commit message |
| 120 | + |
| 121 | +Commit messages should be clear and follow a few basic rules. Example: |
| 122 | + |
| 123 | +```bash |
| 124 | + Add functionality X. |
| 125 | + |
| 126 | + Lines shouldn't be longer than 72 |
| 127 | + characters. If the commit is related to a ticket, you can indicate that |
| 128 | + with "See #3456", "See ticket 3456", "Closes #3456", or similar. |
| 129 | +``` |
| 130 | +
|
| 131 | +Describing the motivation for a change, the nature of a bug for bug fixes or |
| 132 | +some details on what an enhancement does are also good to include in a commit |
| 133 | +message. Messages should be understandable without looking at the code |
| 134 | +changes. A commit message like ``fixed another one`` is an example of |
| 135 | +what not to do; the reader has to go look for context elsewhere. |
| 136 | +
|
| 137 | +### Squash, rebase and merge |
| 138 | +
|
| 139 | +Squash-merge is systematically used to maintain a linear history. It's |
| 140 | +important to check the message on the squash commit. |
| 141 | + |
| 142 | +## Making a release |
| 143 | + |
| 144 | +Following is the process that the development team follows in order to make |
| 145 | +a release: |
| 146 | + |
| 147 | +1. Update the version in the main `pyproject.toml`. |
| 148 | +2. Build locally using `hatch build`, and verify the content of the artifacts |
| 149 | +3. Submit PR, wait for tests to pass, and merge release into `main` |
| 150 | +4. Tag release with version number and push to the repo |
| 151 | +5. Check that release has been deployed to PyPI |
| 152 | +6. Check documentation is built and deployed to readthedocs |
| 153 | +7. Check that auto-generated PR is auto-merged on the conda-forge feedstock repo |
0 commit comments