Thank you for your interest in contributing to modelator-py!
This document gives best practices for contributing:
- Development - how to develop
- Architecture - project architecture
- Proposing Changes - process for agreeing to changes
- Forking - fork the repo to make pull requests
- Pull Requests - what makes a good pull request
- pyenv should be used to manage local Python versions. It can be installed with e.g.
brew install pyenv
(Linux and Windows users should check instructions). - Poetry is used to manage dependencies and packaging. See the github page for instructions.
- Git Large File Storage is used to efficiently store large files at Github. The model checker
.jars
are stored this way.
The Python version used is 3.9.9
.
To publish a new release increment the version in pyproject.toml
.
Then
poetry build;
poetry publish; # requires credentials
Please see usage.
- Install
pyenv
- Install
poetry
- Clone this repo
cd <repo>
pyenv install 3.9.9
poetry env use python
poetry shell
poetry install
code .
to open a VSCode instance with a Python 3.9.9 interpreter (assuming VSCode)
With Poetry installed run poetry install
. Then
- Run the cli program:
poetry run modelator <args>
(entrypoint ismodelator/cli:cli
) - Tests:
poetry run pytest
or use your code editor. VSCode has built in support. - Tests with coverage:
poetry run pytest --cov=modelator tests/
- Tests with logging output to terminal:
poetry run pytest --log-cli-level=debug
- Specific test:
poetry run pytest tests/<dir>/<filename>.py -k 'test_<suffix>'
- Specific test and display stdout:
poetry run pytest tests/<dir>/<filename>.py -s -k 'test_<suffix>'
- Run the pre-commit hooks:
pre-commit run --all-files
- Run linter manually:
flake8 .
- Run formatter manually:
black .
- Run static type checker:
mypy .
- Sort imports
isort .
VSCode has solid support for Python development using Poetry. If VSCode does not pick up on Poetry then try navigating to this directory and executing
poetry shell;
code .;
Ensure that the bottom left of your VSCode window shows that you are using the correct Python environment.
The branch vscode-configuration-template contains a .vscode directory which can be used as a starting point for configuring your dev environment.
This project has been setup following the guidelines at this blog post. The page contains useful context for troubleshooting.
If having difficulties installing poetry using curl -sSL https://install.python-poetry.org | python3 -
on MacOS then try adding eval "$(pyenv init --path)";
to your .bashrc or .zshrc file (given that pyenv is installed).
The project is setup as both a cli program and a collection of pure functions. The cli is an interface to use the pure functions but the pure functions can also be used directly by including modelator-py as a dependency and importing it into your python program. The launch point of the cli is in modelator/cli::cli
. This is specified in pyproject.toml::tool.poetry.scripts
.
The cli uses the python-fire library. Documentation for cli commands is inferred [1,2] from python docstrings. Here's an example.
When contributing to the project, following the guidelines will increase the likelihood of changes being accepted quickly.
- A good place to start is to search through the existing issues for the problem you're encountering.
- If no issues exist, submit one describing the problem you're facing, as well as a definition of done. A definition of done, which tells us how to know when the issue can be closed, helps us to scope the problem and give it definite boundaries. Without a definition of done, issues can become vague.
If you do not have write access to the repository, your contribution should be made through a fork on GitHub. Fork the repository, contribute to your fork, and make a pull request back upstream.
When forking, add your fork's URL as a new git remote in your local copy of the repo. For instance, to create a fork and work on a branch of it:
- Create the fork on GitHub, using the fork button.
cd
to the original clone of the repo on your machinegit remote rename origin upstream
git remote add origin git@github.com:<location of fork>
Now origin
refers to your fork and upstream
refers to this version.
git push -u origin master
to update the fork, and make pull requests against
this repo.
To pull in updates from the origin repo, run
git fetch upstream
git rebase upstream/master
(or whatever branch you want)
PRs should:
- make reference to an issue outlining the context.
- update any relevant documentation and include tests.
Commits should be concise but informative, and moderately clean. Commits will be squashed into a single commit for the PR with all the commit messages.
When the problem as well as proposed solution are well understood, changes should start with a draft pull request against master. The draft signals that work is underway. When the work is ready for feedback, hitting "Ready for Review" will signal to the maintainers to take a look. Maintainers will not review draft PRs.