A Cookiecutter template for projects using MkDocs + tox + uv. This template was extended from monarch-project-template which was developed thanks to the tutorials by the cookiecutter project along with the instructions provided in HelloCookieCutter1 by Bruce Eckel.
First, install the cruft package. Cruft enables keeping projects up-to-date with future updates made to this original template.
pip install cruft
Next, create a project using the pheval-runner-template.
cookiecutter https://github.com/monarch-initiative/pheval-runner-template.git
This kickstarts an interactive session where you declare the following:
project_name: Name of the project. [defaults to: Project_X]github_org_name: Name of either the organisation or user. [defaults to: Org_X]project_description: Description of the project. [defaults to: This is the project description.].file_name: The name of the main python file. [defaults to:mainformain.py]runner_name: The name of the runner. [defaults to: PhEvalToolRunner]greeting_recipient: Just a string that will be displayed when the boilerplate code is invoked. [defaults to:Worldas inHello, World!]full_name: Your name [defaults to: Author 1]email: your email [defaults to: author@org.org]license: Choose one from [MIT,BSD-3,GNU GPL v3.0,Apache Software License 2.0] [defaults to:MIT]⚠️ github_token_variable_name_for_doc_deployment: The github token variable name for document deployment usingSphinx. [defaults to:GH_TOKEN]⚠️ github_token_variable_name_for_pypi_deployment: The github token variable name which aligns with your autogenerated PyPI token for making releases. [defaults to:PYPI_TOKEN]
⚠️ Do NOT enter actual token here, this is just the variable name that holds the token value in the project repository's Secrets.
This will generate the project folder abiding by the template configuration specified by pheval-runner-template in the cookiecutter.json file.
The following files and directories are autogenerated in the project:
- Github wokflows:
- For code quality checks (
qc.yml) - Documentation deployment (
deploy-docs.yml) - PyPI deployment (
pypi-publish.yml)
- For code quality checks (
docsdirectory withMkDocsconfiguration files and anindex.mdfile.srcdirectory structure with theproject_namedirectory within it.- Within the
project_namedirectory, there are 3 python files:runner.pyfor implementing plugin runner.main_file.pycli.pyforclickcommands.
- Within the
testsdirectory with a very basic test.uvcompatiblepyproject.tomlfile containing minimal package requirements.tox.inifile containing configuration for:coverage-cleanlintcodespelldocstr-coveragepytest
LICENSEfile based on the choice made during setup.README.mdfile containingproject_descriptionvalue entered during setup.
git initInstall uv if you haven't already.
pip install uv
uv sync
pre-commit runs hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements. For more information click here.
uv run pre-commit install
which will result in the message:
pre-commit installed at .git/hooks/pre-commit
This indicates that you have a successful pre-commit setup.
uv run tox
This should run all the bullets mentioned above under the tox configuration and ideally you should see the following at the end of the run:
ruff: OK (0.29=setup[0.01]+cmd[0.28] seconds)
py: OK (1.29=setup[0.01]+cmd[1.28] seconds)
congratulations :) (2.55 seconds)
And as the last line says: congratulations :)!! Your project is ready to evolve!
On the command line, type the project_name. In this example, ABCD:
uv run ABCD run
Should return Hello, **greeting_recipient value chosen during setup**
To run commands within the uv environment either preface the command with uv run, i.e. uv run /path-to/my-command --options or activate the uv venv with source .venv/bin/activate.
In order to be up-to-date with the template, first check if there is a mismatch between the project's boilerplate code and the template by running:
cruft check
This indicates if there is a difference between the current project's boilerplate code and the latest version of the project template. If the project is up-to-date with the template:
SUCCESS: Good work! Project's cruft is up to date and as clean as possible :).
Otherwise, it will indicate that the project's boilerplate code is not up-to-date by the following:
FAILURE: Project's cruft is out of date! Run `cruft update` to clean this mess up.
For viewing the difference, run cruft diff. This shows the difference between the project's boilerplate code and the template's latest version.
After running cruft update, the project's boilerplate code will be updated to the latest version of the template.
For the first time, you'll need to just run the following commands:
uv build
uv publish -u YOUR_PYPI_USERNAME -p YOUR_PYPI_PASSWORD
This will release a 0.0.0 version of your project on PyPI.
-
Go to [https://github.com/new] and follow the instructions, being sure NOT to add the README.md and .gitignore files (the cookiecutter template will take care of these for you)
-
Add the remote to your local git repository
git remote add origin https://github.com/my-user-or-organization/ABCD.git git branch -M main git add . git commit -m "first commit" git push -u origin main
Use "Trusted Publishers" by PyPI
The documentation desired should be placed in the docs directory.
Let's say the user has 2 more .md files to add:
- intro.md
- installation.md
These two files should be placed in the docs directory and the mkdocs.yml file should be updated to read the following
site_name: {{cookiecutter.project_name}}
theme:
name: material
palette:
- scheme: default
primary: indigo
toggle:
icon: material/weather-night
name: Night Mode
- scheme: slate
primary: indigo
toggle:
icon: material/weather-sunny
name: Day Mode
markdown_extensions:
- pymdownx.emoji
- pymdownx.tasklist
- pymdownx.mark
- pymdownx.tilde
- pymdownx.highlight
- mkdocs-click
plugins:
- search
- autorefs
- include_dir_to_nav
- mkdocstrings:
enable_inventory: true
watch:
- src
nav:
- "index.md"
- "intro.md"
- "installation.md"
site_url: https://{{cookiecutter.github_org_name}}.github.io/{{cookiecutter.project_name}}/
repo_url: https://github.com/{{cookiecutter.github_org_name}}/{{cookiecutter.project_name}}
edit_uri: "edit/docs/docs/"This lets MkDocs know to look for theses md files and generate equivalent HTML files.
Documentation is automatically built and deployed via the github workflow deploy-docs.yml.
When changes are added to the main branch, this workflow is triggered. For this to work, the user needs to
set-up the github repository of the project to enable documentation from a specific branch. In the Settings tab
of the repository, click the Pages section in the left bar. For the Branch, choose the gh-pages branch.
The full GitHub Pages documentation can be found here.