Jinja implementation of constructor for Godocs CLI
Project description
Godocs Jinja
Godocs Jinja is a plugin for the Godocs CLI that provides a Jinja2 based constructor implementation to generate documentation.
๐ค How to Use
To use this plugin you'll need to also have installed the main godocs package, which has the core functionality for the CLI.
Once both packages are installed, godocs-jinja will automatically be detected as a plugin and registered in the main Godocs program, thanks to its definition in the project.entry-points."godocs.plugins" table in the pyproject.toml.
๐ฅ Installation
To start using this plugin with the Godocs CLI, you can install both the packages through PIP.
Here's the commands necessary to achieve that:
# To install the main CLI:
pip install godocs
# To install this Jinja2 based constructor:
pip install godocs-jinja
๐ก HINT: Depending on your needs, it may be useful to install packages in a virtual environment, as to not pollute your global env. Sometimes you may want to install stuff globally, though, it really depends.
Generally speaking, I'd recommend installing globally if you're in a CI/ CD runner, for example, and installing in an environment if you're in your local computer testing out in a single repository.
If you desire to isolate installation in a venv, you should previously have run these commands:
# To create a venv in a .venv folder:
python -m venv .venv
# To activate the created venv on Windows:
.venv/Scripts/activate
# Or, on Unix systems or Git Bash, for example:
source .venv/Scripts/activate
๐ Concepts
In this section you'll find some information about important concepts used in this project, which are nice to know to get a better understanding.
๐๏ธ Models
Models in this package are considered to be a certain directory structures that store files used in the doc generation process in a predetermined way.
By default, one model for rst documentation is defined, here's its structure as an example:
rst
โโโ templates
โ โโโ index
โ โ โโโ index.jinja
โ โโโ class
โ โ โโโ index.jinja
โ โ โโโ heading.jinja
โ โ โโโ description.jinja
โ โ โโโ property_index.jinja
โ โ โโโ method_index.jinja
โ โ โโโ constant_descriptions.jinja
โ โ โโโ enum_descriptions.jinja
โ โ โโโ property_descriptions.jinja
โ โ โโโ method_descriptions.jinja
โ โ โโโ signal_descriptions.jinja
โโโ filters.py
Custom models can be passed to the program by specifying a directory in the -M or --models option from the jinja constructor.
๐ Templates
Templates are folders with an index.jinja file or a .jinja file by itself, which defines a Jinja template used for documentation generation.
By default, there are two templates in the rst model: the class template and the index template. The class template defines how a documentation page about a specific class should be, and the index template specifies the output for an index page that allows navigating between all classes with a toctree.
Custom templates can be passed to the program by specifying a directory with templates in the -T or --templates option from the jinja constructor.
๐จ Filters
Filters are functions that return strings which can be used by the Jinja construction process, thanks to the JinjaConstructor defining them as Jinja filters.
Filters can be passed to the CLI by pointing to a file with the given functions via the -F or --filters option in the jinja constructor.
By default, the rst model comes with a few filters, which stay in the filter.py are used throughout the built-in templates.
๐๏ธ Builders
Builders are also functions, but these determine how the construction should respond to specific templates. This is done internally by mapping each builder to a template name.
As an example, there are default builders for the class and index templates. The class builder generates output files for each class in the documentation, different from the index builder, which only generates one index file output.
For each template that should be used, there should be an equivalent builder, so godocs-jinja knows how to generate its output specifically. That's why by default there are the class and index builders - because there are the class and index templates.
For passing custom builders, you can use the -B or --builders option in the jinja constructor pointing to a script with functions representing the builders. The names of the functions should match the name of the templates they should build.
๐๏ธ Commands
This plugin adds the jinja constructor as a subcommand to the main CLI's construct command. This subcommand can then be used to effectively generate docs using Jinja2.
Down below are some quick examples of how the commands, arguments and options added by godocs-jinja to generate documentation can be used (if you installed in a virtual environment, make sure to have it activated before effectively using the program).
If you want a more in depth overview of the features available, you can always use the -h / --help option with any command.
# Generates documentation based on the XML in the input-dir inside the output-dir, in the RST language, by default.
godocs construct jinja <input-dir> <output-dir>
# Generates documentation based on the XML from the input-dir inside the output-dir, in the RST language, by default, translating the syntax of any text within it using the custom translator in the translator-path.
godocs construct jinja --translator <translator-path> <input-dir> <output-dir>
# Generates documentation based on the XML from the input-dir inside the output-dir, using the model specified by md-model, with the md file suffix, translating the syntax of any text within the XML using the custom translator in the md-translator path.
godocs construct jinja --translator <md-translator> --format md --model <md-model> <input-dir> <output-dir>
๐ Custom Options
The documentation process often needs some data that can't be obtained directly from the XML class reference generated by Godot. That's why more properties can be passed via a special godocs-options.json file.
You can write any data your documentation will potentially need inside this file and specify its path through the --options-file option in the jinja command. Godocs construct logic will then parse its data and make it available in the building context inside an options property.
If you use the default rst templates, here's the options that you'll want to specify:
name: The title of the documentation in the index filedescription: The description for the documentation in the index filetoc_depth: The depth of the maintoctreeof the documentation in the index file
๐งโ๐ป Developing
For development isolation, it is recommended to be inside a virtual environment, which can be accomplished by following the steps described at the end of the Installation section, quickly recaping:
python -m venv .venv
# On Windows:
.venv/Scripts/activate
# Or, on Unix:
source .venv/Scripts/activate
Now, the project comes with a pyproject.toml, which specifies its dependencies depending on the environment.
The main dependency of this package is the jinja2 tool. Besides that, this project has some dev dependencies, to allow building and testing. Finally, godocs is considered a peer dependency here, to allow users to use the version they want, based on their environment.
If you want to install the dependencies, you can use the following commands:
# For production only dependencies:
pip install .
# For development dependencies:
pip install .[dev]
# For peer dependencies:
pip install .[peer]
If you're going to develop, though, I'd recommend you to rather install the project itself in editable mode, which would allow you to make changes and test them out in real time, without having to rebuild and reinstall. Here's the command to achieve that:
pip install --editable .
๐งช Testing
This project uses pytest as its test framework, which means in order to execute tests, you should use the following command:
pytest
The test files are located under the tests directory, distributed under a structure that mirrors the source code arrangement.
๐ฆ Building
To build this project for production, the build dependency is needed, which is specified in the dev dependencies from pyproject.toml.
With that dependency installed (through the installation of the dev dependencies, or its manual installation), the following command can be used:
python -m build .
This will use the setuptools build backend in an isolated temporary environment to create the distributables.
When executed, there should be a dist folder with a .tar.gz archive and a .whl build.
๐ Deploying
To deploy this package, the following command can be used:
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file godocs_jinja-0.1.2.tar.gz.
File metadata
- Download URL: godocs_jinja-0.1.2.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f7dd809d968473c54ab70ac65870ddc2f646fb597c3efe75d5d04215352885c
|
|
| MD5 |
81411529e6372ac6c1845a84b57f442b
|
|
| BLAKE2b-256 |
ee2255580b203ec616b766bfffa5a0921ae38c0ec35fc936e4a26eb433329051
|
File details
Details for the file godocs_jinja-0.1.2-py3-none-any.whl.
File metadata
- Download URL: godocs_jinja-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfc90376aca1f3f990d2451b3f6099271da06bc04df66500cdb1e91bf167c10b
|
|
| MD5 |
2add4543180907e8463d688386578691
|
|
| BLAKE2b-256 |
0fc695a8896c668e890e6bc2ab5768f3b6c87275ab4e283511fc4c60ef91c3be
|