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 | |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 25 | import glob |
| 26 | |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 27 | # -- yaml2rst ---------------------------------------------------------------- |
| 28 | import os |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 29 | import pathlib |
| 30 | |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 31 | import yaml2rst |
| 32 | from yaml4rst.reformatter import YamlRstReformatter |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 33 | |
| 34 | for defaults_file in glob.glob("../../roles/*/defaults/main.yml"): |
| 35 | role_name = defaults_file.split("/")[-3] |
| 36 | |
| 37 | YamlRstReformatter._HEADER_END_LINES = { |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 38 | "yaml4rst": [ |
| 39 | "# Default variables", |
| 40 | "# :local:", |
| 41 | "# .. contents:: Sections", |
| 42 | "# .. include:: includes/all.rst", |
| 43 | "# .. include:: includes/role.rst", |
| 44 | "# .. include:: ../../../includes/global.rst", |
| 45 | "# -----------------", |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 46 | ], |
| 47 | } |
| 48 | |
| 49 | reformatter = YamlRstReformatter( |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 50 | preset="yaml4rst", |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 51 | template_path=os.path.join( |
| 52 | os.path.abspath(os.path.dirname(__file__)), |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 53 | "_templates", |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 54 | ), |
| 55 | config={ |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 56 | "ansible_full_role_name": f"vexxhost.atmosphere.{role_name}", |
| 57 | "ansible_role_name": role_name, |
| 58 | }, |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 59 | ) |
| 60 | reformatter.read_file(defaults_file) |
| 61 | reformatter.reformat() |
| 62 | reformatter.write_file( |
| 63 | output_file=defaults_file, |
| 64 | only_if_changed=True, |
| 65 | ) |
| 66 | |
| 67 | pathlib.Path(f"roles/{role_name}/defaults").mkdir(parents=True, exist_ok=True) |
| 68 | |
| 69 | rst_content = yaml2rst.convert_file( |
| 70 | defaults_file, |
| 71 | f"roles/{role_name}/defaults/main.rst", |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 72 | strip_regex=r"\s*(:?\[{3}|\]{3})\d?$", |
| 73 | yaml_strip_regex=r"^\s{66,67}#\s\]{3}\d?$", |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 74 | ) |
| 75 | |
| 76 | |
| 77 | # -- Project information ----------------------------------------------------- |
| 78 | |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 79 | project = "Atmosphere" |
| 80 | copyright = "2022, VEXXHOST, Inc." |
| 81 | author = "VEXXHOST, Inc." |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 82 | |
| 83 | |
| 84 | # -- General configuration --------------------------------------------------- |
| 85 | |
| 86 | # Add any Sphinx extension module names here, as strings. They can be |
| 87 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 88 | # ones. |
| 89 | extensions = [ |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 90 | "reno.sphinxext", |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 91 | ] |
| 92 | |
| 93 | # Add any paths that contain templates here, relative to this directory. |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 94 | templates_path = ["_templates"] |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 95 | |
| 96 | # List of patterns, relative to source directory, that match files and |
| 97 | # directories to ignore when looking for source files. |
| 98 | # This pattern also affects html_static_path and html_extra_path. |
| 99 | exclude_patterns = [] |
| 100 | |
| 101 | |
| 102 | # -- Options for HTML output ------------------------------------------------- |
| 103 | |
| 104 | # The theme to use for HTML and HTML Help pages. See the documentation for |
| 105 | # a list of builtin themes. |
| 106 | # |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 107 | html_theme = "sphinx_rtd_theme" |
Mohammed Naser | ab033e1 | 2022-03-13 21:07:28 -0400 | [diff] [blame] | 108 | |
| 109 | # Add any paths that contain custom static files (such as style sheets) here, |
| 110 | # relative to this directory. They are copied after the builtin static files, |
| 111 | # so a file named "default.css" will overwrite the builtin "default.css". |
Mohammed Naser | f3a14a3 | 2022-09-19 15:15:39 -0400 | [diff] [blame] | 112 | html_static_path = ["_static"] |