Contributing Guide
This is a brief guide describing how to contribute to the PuncturedFEM project.
TL;DR
First-time setup:
- Fork the GitHub repo
- Checkout a new branch
- Create and activate a virtual environment
- Install dev tools
- Install this package in edit mode
Make your changes:
- Use
numpy-style docstrings - Use
pylintandmypyfor linting - Use
isortandblack(in that order) for formatting - Run tests with
pytest - Clear all Jupyter notebook outputs
Final steps:
- Commit your changes
- Push to your fork
- Open a pull request
Prerequisites
- git (don't forget to configure your username and email)
- python3 (version 3.9 or later)
- pip (should be installed with Python)
- venv (or another virtual environment manager)
First-time setup
Fork & clone
- Fork the repo on GitHub and make sure it is up-to-date
- Clone your fork to your local machine, and change directory to your local repo:
Set up a virtual environment
- Configure a virtual environment:
- Activate your virtual environment:
- Linux/Mac
- Windows command line
- Windows PowerShell
Install dependencies and developer tools
- Use
pipto install developer tools: - Install this package in edit mode:
Make your changes
- Make sure that the
mainbranch is up-to-date: - Checkout a new branch, named according to the contribution you wish to make (short but descriptive is best):
- Set the upstream branch:
- Make your changes and save your files
Best practices
- It is best practice to make small, incremental changes and make commits as you go
- This way if you make a mistake, it is easy to return to a version of your code that works
- Running tests and linters frequently can help catch errors early
- Write and update documentation as you go
Run formatters
This step helps make the code you've written more readable and standardized.
- Be sure that your virtual environment is active
- Format import statements with isort and format code with black:
- NOTE: Always run
blackafter runningisort - If contributing Jupyter notebooks, clear all outputs:
Tests and linters (for source code)
This step ensures that your code is correct and follows best practices.
Run tests
- Be sure that your virtual environment is active
- Use pytest to run the tests in the
test/directory - Optionally, you can use the
-sflag to see print statements (helpful for debugging) - Be sure all tests pass before proceeding
Run linters
- Be sure that your virtual environment is active
pylintwill print the filename, line number, and a description of any errors it finds:- Hint: If you encounter formatting errors (e.g. lines over 80 characters, running black may resolve some of them)
- Similarly for
mypy: - Fix any errors before proceeding
Write documentation (for source code)
This step ensures that users will be able to find information about how to use the new features you've added.
Docstrings
- Use numpy-style docstrings for all public functions, classes, and modules
- Check that your docstrings are formatted correctly with pydocstyle:
MkDocs
- If adding a new function/class/module, include a markdown file in the appropriate subdirectory of
doc/src - Add the new file to the
navsection ofmkdocs.yml - If you are contributing to the documentation, you can use MkDocs to preview your changes:
- Open a web browser and navigate to
http://127.0.0.1:8000/to preview the documentation
Commit your changes
- Stage your changes
- Don't add any files you haven't directly edited (e.g. don't add your virtual environment files)
- Do you want
gitto ignore certain files or directories? - Did you accidentally add a file?
- Commit your changes
- Do you need to undo a commit?
Push your changes
- Once you are happy with the state of your code and are ready to merge them with the
mainbranch, push your changes to your fork: - Finally, open a pull request on GitHub to merge your changes into the
mainbranch of the parent repository
Release (maintainers only)
Create a release branch
- Ensure that
mainis up-to-date: - Create a new branch for the release:
Update the version number and changelog
- Update the version number in
pyproject.toml - Update the
doc/ROADMAP.md - Move completed items to the
CHANGELOG.md - Update the
CHANGELOG.md - Version number
- Date
- List of changes
- Commit the changes:
- Push the changes:
- Open a pull request to merge the release branch into
main
Merge the release branch
- Once the pull request is merged, update the
mainbranch: - Tag the release:
- Push the tag:
- Publish the release on GitHub
Publish to PyPI
- Build the distribution:
- Publish the distribution: