Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame^] | 1 | # Copyright (c) 2022 VEXXHOST, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | # -- Path setup -------------------------------------------------------------- |
| 16 | |
| 17 | # If extensions (or modules to document with autodoc) are in another directory, |
| 18 | # add these directories to sys.path here. If the directory is relative to the |
| 19 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
| 20 | # |
| 21 | # import os |
| 22 | # import sys |
| 23 | # sys.path.insert(0, os.path.abspath('.')) |
| 24 | |
| 25 | # -- yaml2rst ---------------------------------------------------------------- |
| 26 | import os |
| 27 | import glob |
| 28 | import yaml2rst |
| 29 | from yaml4rst.reformatter import YamlRstReformatter |
| 30 | import pathlib |
| 31 | |
| 32 | for defaults_file in glob.glob("../../roles/*/defaults/main.yml"): |
| 33 | role_name = defaults_file.split("/")[-3] |
| 34 | |
| 35 | YamlRstReformatter._HEADER_END_LINES = { |
| 36 | 'yaml4rst': [ |
| 37 | '# Default variables', |
| 38 | '# :local:', |
| 39 | '# .. contents:: Sections', |
| 40 | '# .. include:: includes/all.rst', |
| 41 | '# .. include:: includes/role.rst', |
| 42 | '# .. include:: ../../../includes/global.rst', |
| 43 | '# -----------------', |
| 44 | ], |
| 45 | } |
| 46 | |
| 47 | reformatter = YamlRstReformatter( |
| 48 | preset='yaml4rst', |
| 49 | template_path=os.path.join( |
| 50 | os.path.abspath(os.path.dirname(__file__)), |
| 51 | '_templates', |
| 52 | ), |
| 53 | config={ |
| 54 | 'ansible_full_role_name': f"vexxhost.atmosphere.{role_name}", |
| 55 | 'ansible_role_name': role_name, |
| 56 | } |
| 57 | ) |
| 58 | reformatter.read_file(defaults_file) |
| 59 | reformatter.reformat() |
| 60 | reformatter.write_file( |
| 61 | output_file=defaults_file, |
| 62 | only_if_changed=True, |
| 63 | ) |
| 64 | |
| 65 | pathlib.Path(f"roles/{role_name}/defaults").mkdir(parents=True, exist_ok=True) |
| 66 | |
| 67 | rst_content = yaml2rst.convert_file( |
| 68 | defaults_file, |
| 69 | f"roles/{role_name}/defaults/main.rst", |
| 70 | strip_regex=r'\s*(:?\[{3}|\]{3})\d?$', |
| 71 | yaml_strip_regex=r'^\s{66,67}#\s\]{3}\d?$', |
| 72 | ) |
| 73 | |
| 74 | |
| 75 | # -- Project information ----------------------------------------------------- |
| 76 | |
| 77 | project = 'Atmosphere' |
| 78 | copyright = '2022, VEXXHOST, Inc.' |
| 79 | author = 'VEXXHOST, Inc.' |
| 80 | |
| 81 | |
| 82 | # -- General configuration --------------------------------------------------- |
| 83 | |
| 84 | # Add any Sphinx extension module names here, as strings. They can be |
| 85 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 86 | # ones. |
| 87 | extensions = [ |
| 88 | 'reno.sphinxext', |
| 89 | ] |
| 90 | |
| 91 | # Add any paths that contain templates here, relative to this directory. |
| 92 | templates_path = ['_templates'] |
| 93 | |
| 94 | # List of patterns, relative to source directory, that match files and |
| 95 | # directories to ignore when looking for source files. |
| 96 | # This pattern also affects html_static_path and html_extra_path. |
| 97 | exclude_patterns = [] |
| 98 | |
| 99 | |
| 100 | # -- Options for HTML output ------------------------------------------------- |
| 101 | |
| 102 | # The theme to use for HTML and HTML Help pages. See the documentation for |
| 103 | # a list of builtin themes. |
| 104 | # |
| 105 | html_theme = 'sphinx_rtd_theme' |
| 106 | |
| 107 | # Add any paths that contain custom static files (such as style sheets) here, |
| 108 | # relative to this directory. They are copied after the builtin static files, |
| 109 | # so a file named "default.css" will overwrite the builtin "default.css". |
| 110 | html_static_path = ['_static'] |