This repository contains a simple template for Python repositories, including actions and a .gitignore file. The actions include organizing imports with isort, linting using ruff, automatic test execution using pytest, as well as a small coverage report with coverage on merging to the main branch.
First, clone the repository.
Create the main, develop and, gh-pages branches.
Whenever you want to change something, create a new branch. If it is done, create a pull request to the develop branch.
Only pull from develop to main with fully functional, tested and documented new versions.
Branch Protection Rules
- Go to the repository settings
- Open
Branchesin the left sidebar - Click
Add branch ruleset - Choose an appropriate ruleset name, such as
Branch protection rules for main and develop - Under
target branches, entermainanddevelop - Under
Rulesselect at least:Restricht deletionsRequire linear historyRequire a pull request before merging- Select an appropriate number of reviewers
Block force pushes
- Click
Createto finish. you can now find the ruleset underRules>Rulesets
Actions Permissions
- Go to the repository settings
- Open
Actions>Generalin the left sidebar - Under
Workflow permissions, selectRead and write permissionsAllow GitHub Actions to create and approve pull requests
- [Optional] Create a new virtual environment
- Run
pip install -e .[test,docs]
Documentation Setup
- Create a
docsfolder in the root of the project and open it (mkdir docs && cd docs) - Run
spinx-quickstartto create a new documentation (On Windows, runsphinx-quickstart.exe). Fill out all relevant information.- Select no
[n]when askedSeparate source and build directories (y/n) [n]
- Select no
- [Optionally] Run
make htmlto build the documentation (On Windows, might have to write full path tomake.bat). - Copy
docs/conf.pyinto your own docs folder, replacing the existing one. - Change all relevant fields in the
pyproject.tomlanddocs/conf.pyfiles. (Don't forget the intersphinx setup)
If you want to run sphinx locally:
sphinx-apidoc --separate --module-first -d 2 -H "API reference" --follow-links -o apidocs ../src/template_for_python_projectsmake.bathtml- Open
docs/_build/html/index.htmlin your browser
Sometimes it is necessary to have other repositories as submodules. To initiate this you can follow this tutorial by Git itself on Submodules. But in essence you need this command:
git submodule add https://github.com/frehburg/TemplateForPythonProjects
If you then want to import the submodule as a python package in your code, the ci will not be able to resolve it. To fix this, add the following lines to python_ci.yml:
- name: Checkout code
uses: actions/checkout@v3
with: # this
submodules: true # this to ensure submodules are checked out
and further down
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --editable .[test,docs]
python3 -m pip install --editable ./submodules/TemplateForPythonProjects # this to install the submodule package
Please check the tutorial in custom_badges.md for information on creating custom badges for your github repo.
You can also add a badge like this one to your README.md file:
Stable Documentation
Latest Documentation
See here a template for your README
Brief description of your project.
A brief overview of your project and its purpose.
List the key features of your project.
Instructions on how to set up and run your project locally.
List any software, libraries, or dependencies that need to be installed before setting up the project.
Step-by-step instructions on how to install and set up your project.
To install your own code run pip install -e . in a terminal
Provide examples and explanations of how your project can be used. Include code snippets or screenshots if necessary.
Guidelines for contributing to your project. Include information about how others can contribute, submit issues, and create pull requests.
Specify the license under which your project is distributed.