-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨[#64] add setup configuration documentation generation #97
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
open_api_framework/management/commands/generate_setup_config_docs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.template import loader | ||
|
||
from open_api_framework.utils import get_configuraton_step_context | ||
|
||
|
||
def render_step_info(step_name: str) -> str: | ||
template = loader.get_template( | ||
"open_api_framework/components/setup_config_step.rst" | ||
) | ||
|
||
context = get_configuraton_step_context(step_name) | ||
return template.render(context) | ||
|
||
|
||
def convert_setup_configuration_steps_to_rst( | ||
project_name: str, config_steps: list[str] | ||
) -> str: | ||
template = loader.get_template("open_api_framework/setup_configuration.rst") | ||
return template.render( | ||
{"project_name": project_name, "setup_configuraiton_steps": config_steps} | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Generate documentation for all used envvars" | ||
|
||
def add_arguments(self, parser): | ||
super().add_arguments(parser) | ||
|
||
parser.add_argument( | ||
"--file", | ||
help="Name and path of the file to which the documentation will be written.", | ||
nargs="?", | ||
default="docs/setup_configuration.rst", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
file_path = options["file"] | ||
|
||
configuration_steps = getattr(settings, "SETUP_CONFIGURATION_STEPS", []) | ||
|
||
project_name = getattr(settings, "PROJECT_NAME", settings.PROJECT_DIRNAME) | ||
|
||
with open(file_path, "w") as f: | ||
f.write( | ||
convert_setup_configuration_steps_to_rst( | ||
project_name, configuration_steps | ||
) | ||
) |
9 changes: 9 additions & 0 deletions
9
open_api_framework/templates/open_api_framework/components/setup_config_step.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% load doc_tags %} | ||
{% spaceless %} | ||
{{ step_title }} | ||
{{ step_title|repeat_char:"-"}} | ||
|
||
{{ step_description }} | ||
|
||
.. setup-config-example:: {{ step_path }} | ||
{% endspaceless %} |
47 changes: 47 additions & 0 deletions
47
open_api_framework/templates/open_api_framework/setup_configuration.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% load doc_tags %}.. _installation_configuration_cli: | ||
|
||
===================={{ project_name|repeat_char:"="}} | ||
{{ project_name }} configuration (CLI) | ||
===================={{ project_name|repeat_char:"="}} | ||
|
||
After deploying {{ project_name }}, it needs to be configured to be fully functional. | ||
The django management command ``setup_configuration`` assist with this configuration. | ||
You can get the full command documentation with: | ||
|
||
.. code-block:: bash | ||
|
||
python ./src/manage.py setup_configuration --help | ||
|
||
.. warning:: This command is declarative - if configuration is manually changed after | ||
running the command and you then run the exact same command again, the manual | ||
changes will be reverted. | ||
|
||
Preparation | ||
=========== | ||
|
||
The command executes the list of pluggable configuration steps, and each step | ||
requires specific configuration information, that should be prepared. | ||
Here is the description of all available configuration steps and the configuration | ||
format, used by each step. | ||
|
||
{% for step_path in setup_configuraiton_steps %} | ||
{% render_setup_configuraiton_step step_path %} | ||
{% endfor %} | ||
|
||
|
||
Execution | ||
========= | ||
|
||
{{ project_name }} configuration | ||
{{ project_name|repeat_char:"-"}}-------------- | ||
|
||
With the full command invocation, everything is configured at once. Each configuration step | ||
is idempotent, so any manual changes made via the admin interface will be updated if the command | ||
is run afterwards. | ||
|
||
.. code-block:: bash | ||
|
||
python ./src/manage.py setup_configuration --yaml-file /path/to/config.yaml | ||
|
||
.. note:: Due to a cache-bug in the underlying framework, you need to restart all | ||
replicas for part of this change to take effect everywhere. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think config steps should have a description/summary variable and verbose_name should be a name that is verbose rather than a summary as it currently seems to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in use the current verbose name value as a description and change the verbose_name to a more readable format of the step name:
TokenAuthConfigurationStep
==> "Token Authentication Configuration"