Contributions are always welcome and greatly appreciated! Here is how you can help:
- Report bugs at https://github.com/markus-ebke/python-billiards/issues. Please include your Python version, a list of steps to reproduce the bug (or an example file) and any details about your local setup that may be helpful in troubleshooting.
- Suggest a feature: File an issue labeled with
enhancementand describe your idea. - Improve documentation: billiards could always use more and clearer documentation, in the docstrings or as part of the official docs. You can also contribute example files.
- Fix bugs or implement features: Have a look at the issues page or work on your own ideas. The section below explains how to setup the project for local development.
Before you start, make sure that you have Python version >= 3.8.
-
Fork this project (via the button on the Github page) and clone your fork locally:
git clone https://github.com/<your_username>/python-billiards.git
-
Install the local copy, preferably inside a virtual environment. With pipenv this is quite easy:
cd python-billiards pipenv install --devBut you can also use venv or virtualenv to create a virtual environment and, after activating it, install the required packages with pip like this:
pip install --editable .[visualize] pip install -r requirements_dev.txt
-
Optional: Install pre-commit (not included in
requirements_dev.txt) and its git hook scripts:pip install pre-commit pre-commit install
This will run several checks automatically before every commit:
- flynt and pyupgrade to upgrade python syntax (will modify files)
- isort, black and blacken-docs for automatic code formatting (will modify files)
- flake8 as linter for code
- pydocstyle (only for
src/billiards/) and doc8 (only fordocs/) as linters for documentation
You can also run the tools manually:
pre-commit run --all-files
-
Create a branch for local development (I suggest you follow the GitHub flow model):
git checkout -b <name-of-your-feature>
and now you can start on your new feature, bugfix, etc.
-
Commit the changes and push your branch to GitHub:
git add . git commit -m "Write a description of your changes" git push origin <name-of-your-feature>
Helpful: How to Write a Git Commit Message
-
Before submitting a pull request, please run the unit tests with pytest. Note that pytest will also create a coverage report via pytest-cov (summary on the command line, details in
htmlcov/index.html). Depending on the kind of changes you made, there are some additional steps you should take to keep everything consistent:-
If you changed code in
visualize_matplotlib.py, please regenerate the images and videos for the documentation with:python docs/create_visualizations.py
-
If you changed docstrings or documentation files, check that the documentation is generated correctly via tox:
tox -e docs-lint tox -e docs-build
The first command will run pydocstyle on the
src/billiardsfolder and doc8 followed by Sphinx doctest and linkcheck on thedocsfolder. The second command will generate the documentation and place it in thebuild/docsfolder. -
If you want to run the unit tests against other versions of Python, use tox. The command
tox -l
will list all Python versions that billiards should be compatible with. For example, to run against Python 3.13 (assuming the corresponding Python interpreter is already installed on your system):
tox -e py313
This will run pytest and also overwrite the coverage report in
htmlcov/index.html. -
While modifing the markdown files
README.mdorCONTRIBUTING.md, you can preview the changes in your browser with grip (not included inrequirements_dev.txt):grip -b
or for
CONTRIBUTING.md:grip -b CONTRIBUTING.md
-
-
Submit a pull request through the GitHub website and I will have a look!
If you need some code review or feedback while you're developing the code, just make a pull request.
Before merging, you should:
- Include new tests (if any) and make sure they pass (run pytest or tox).
- Update docstrings and the documentation files if you changed the API or added functionality. For docstrings, use the Google style guide. Example file: https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html.
- Add a note in the top section of
CHANGELOG.mddescribing the changes. - Add yourself to the Authors section in the
README.mdfile.
-
Complete the notes in
CHANGELOG.mdand close off the topmost section with**v<new_version>**(write it exactly as stated here, later bump2version will replace<new_version>with the updated version number). -
Commit, message:
Update CHANGELOG.mdor similar. -
Go to master branch and merge develop into master:
git checkout master git merge develop
-
In the master branch use bump2version to update the version number in the files. The version identifier should always be of the form
N.N.N[.devN]. To prepare a new release, usebump2version part
where
partismajor,minororpatch. This will set the version number tomajor.minor.patch.dev0, i.e. it is automatically a development version. To bump the development number, usedev_numberforpart; to promote the development version to final, usebump2version dev_label --tag
The tag will be
v<major.minor.patch>.To skip development versions (e.g. when using
patch), use the--new-versionargument and set the version number explicitly. Other useful arguments:--dry-runand--list. -
Push to Github:
git push --all git push --tags
-
The tox environment metadata checks that the project can be correctly packaged, it runs check-manifest (configuration settings in
tox.ini) and twine check to make sure the important files are included. To check the metadata and build the package usetox -e metadata python3 -m build
TODO: Figure out a way to upload this package to PyPi.
-
Return to develop branch and merge master branch (to get current version number):
git checkout develop git merge master
Then continue working.
-
Update packages and pre-commit hooks to their newest version:
pipenv update pre-commit autoupdate
-
The configuration settings are in
pyproject.toml,setup.cfg(TODO: move topyproject.toml),tox.ini(TODO: can move topyproject.toml, but requires version >=v4.21.0?) and.flake8(doesn't supportpyproject.toml, workaround: Flake8-pyproject?) -
I don't include
Pipfile.lockin git because the official recommendation isDo not keep
Pipfile.lockin version control if multiple versions of Python are being targeted.And billiards is intended as a libary for multiple Python versions and not as a standalone application.
-
I used markdownlint when writing the readme and this file.
-
Using pandoc, I converted the readme file to rst and copied some of the text to the documentation
pandoc README.md --from markdown --to rst -s -o readme.rst
-
Generate the API documentation templates:
sphinx-apidoc -f -o {toxinidir}/docs/api_reference {toxinidir}/src/billiards -
Create docs manually (i.e. without tox):
cd docs/ pip install -r requirements_docs.txt make html
- flynt (f-string conversion)
- pyupgrade --py37-plus
- isort
- black
- blacken-docs
- flake8 (with flake8-bugbear, flake8-comprehensions)
- pydocstyle (only for src, not for tests or examples)
- docs8
- pytest, coverage report
- sphinx-build
- check-manifest and twine
- tox
- bump2version
| Tool name | name.cfg/ini | setup.cfg | pyproject.toml |
|---|---|---|---|
| isort | yes (preferred) | yes | yes (preferred) |
| black | no | no | yes |
| flake8 | yes | yes | Flake8-pyproject |
| pydocstyle | yes | yes | yes |
| doc8 | yes | yes | yes |
| pytest | yes | no | yes |
| coverage | yes | no | yes |
| bumpversion | yes | yes | no |
| check-manifest | no | yes | yes |
-
Files and folders that can be safely removed:
build,dist,htmlcov,src/billiards.egg-info,.eggs,.pytest_cache,.tox,.coverage -
Remove pipenv virtual environment: $ pipenv --rm
-
When using Pipenv on Linux: delete the virtualenv folder in
~/.local/share/virtualenvs