diff --git a/build_requirements.py b/build_requirements.py index e1ccb4ac..231d0b99 100644 --- a/build_requirements.py +++ b/build_requirements.py @@ -1,7 +1,7 @@ import sys -sys.path.append('./') -from custom_conf import * +sys.path.append("./") +from custom_conf import custom_extensions, custom_required_modules, redirects # The file contains helper functions and the mechanism to build the # .sphinx/requirements.txt file that is needed to set up the virtual diff --git a/conf.py b/conf.py index dfbd56d0..d6fc6dd0 100644 --- a/conf.py +++ b/conf.py @@ -133,3 +133,5 @@ if 'github_issues' in html_context and html_context['github_issues'] and not disable_feedback_button: html_js_files.append('github_issue_links.js') html_js_files.extend(custom_html_js_files) + +generate_ams_configuration() diff --git a/custom_conf.py b/custom_conf.py index e900d6fa..7ce0833e 100644 --- a/custom_conf.py +++ b/custom_conf.py @@ -210,7 +210,20 @@ ## Add any configuration that is not covered by the common conf.py file. # Define a :center: role that can be used to center the content of table cells. -rst_prolog = ''' +rst_prolog = """ .. role:: center :class: align-center -''' +""" + + +## Generate dynamic configuration using scripts +# Inject AMS configuration valuues and Node configuration values from the swagger +# specification hosted on Github. +def generate_ams_configuration(): + from scripts.ams_configuration import get_swagger_from_url, parse_swagger + + with open("scripts/requirements.txt", "r") as f: + for req in f.readlines(): + custom_required_modules.append(req) + ams_configuration_file = "reference/ams-configuration.md" + parse_swagger(get_swagger_from_url(), ams_configuration_file) diff --git a/scripts/template.md.j2 b/scripts/ams-configuration.md.j2 similarity index 100% rename from scripts/template.md.j2 rename to scripts/ams-configuration.md.j2 diff --git a/scripts/parse.py b/scripts/ams_configuration.py similarity index 87% rename from scripts/parse.py rename to scripts/ams_configuration.py index 0fffd6b4..49a1ec3d 100755 --- a/scripts/parse.py +++ b/scripts/ams_configuration.py @@ -2,6 +2,7 @@ import argparse import json +from typing import Dict import requests from jinja2 import Environment @@ -29,22 +30,29 @@ def main() -> int: "--output", dest="output_file", help="Destination of the rendered configuration file", - default="ams-configuration.md", + default="reference/ams-configuration.md", ) args = parser.parse_args() if args.swagger_path: with open(args.swagger_path, mode="r") as f: swagger = json.load(f) else: - response = requests.get(SWAGGER_URL) - swagger = response.json() + swagger = get_swagger_from_url() + parse_swagger(swagger, args.output_file) + +def get_swagger_from_url() -> Dict: + response = requests.get(SWAGGER_URL) + return response.json() + + +def parse_swagger(swagger, output_file): configs = _parse_config_schema(swagger) nodes = _parse_node_schema(swagger) env = Environment(loader=FileSystemLoader(".")) - templ = env.get_template("template.md.j2") + templ = env.get_template("scripts/template.md.j2") text = templ.render(configs=configs, nodes=nodes) - with open(args.output_file, mode="w+") as op: + with open(output_file, mode="w+") as op: op.write(text)