diff options
author | Chad Smith <chad.smith@canonical.com> | 2022-01-13 14:30:30 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2022-01-13 14:37:46 -0700 |
commit | 2b43a2ef3fb555b9e0b79b4e1bb43746e5ab7460 (patch) | |
tree | bb820a51415590e3a37906132c921dc2bd5494f4 | |
parent | 3bf02205ce47d53227a9f96035b6f3a56e52e0e6 (diff) | |
download | cloud-init-git-2b43a2ef3fb555b9e0b79b4e1bb43746e5ab7460.tar.gz |
schema: allow CLOUD_INIT_SCHEMA_DIR env override for Paths.schema_dir
To allow for building docs locally in the project-dir, get_schema
needs to source ./config/cloud-init-schema*json which is data files
outside of the typical python module paths.
get_schema will prefer CLOUD_INIT_SCHEMA_DIR environment
variable over Paths.schema_dir if provided.
Allow tox.ini to passenv CLOUD_INIT_SCHEMA_DIR into the tox env.
To generate docs from project directory:
CLOUD_INIT_SCHEMA_DIR=config tox -e doc
To validate schema docs from project directory:
CLOUD_INIT_SCHEMA_DIR=config PYTHONPATH=. python3 \
-m cloudinit.cmd.main devel schema --docs all
-rw-r--r-- | cloudinit/config/cc_apt_pipelining.py | 1 | ||||
-rw-r--r-- | cloudinit/config/schema.py | 20 | ||||
-rw-r--r-- | doc/rtd/conf.py | 2 | ||||
-rw-r--r-- | tox.ini | 2 |
4 files changed, 16 insertions, 9 deletions
diff --git a/cloudinit/config/cc_apt_pipelining.py b/cloudinit/config/cc_apt_pipelining.py index 556eb4c4..34b6ac0e 100644 --- a/cloudinit/config/cc_apt_pipelining.py +++ b/cloudinit/config/cc_apt_pipelining.py @@ -56,7 +56,6 @@ __doc__ = get_meta_doc(meta) def handle(_name, cfg, _cloud, log, _args): - apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", "os") apt_pipe_value = cfg.get("apt_pipelining", "os") apt_pipe_value_s = str(apt_pipe_value).lower().strip() diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py index 7e445043..185df518 100644 --- a/cloudinit/config/schema.py +++ b/cloudinit/config/schema.py @@ -420,10 +420,17 @@ def _get_property_type(property_dict: dict) -> str: jsonschema. """ property_type = property_dict.get("type") - if property_type is None and property_dict.get("enum"): - property_type = [ - str(_YAML_MAP.get(k, k)) for k in property_dict["enum"] - ] + if property_type is None: + if property_dict.get("enum"): + property_type = [ + str(_YAML_MAP.get(k, k)) for k in property_dict["enum"] + ] + elif property_dict.get("oneOf"): + property_type = [ + subschema["type"] + for subschema in property_dict.get("oneOf") + if subschema.get("type") + ] if isinstance(property_type, list): property_type = "/".join(property_type) items = property_dict.get("items", {}) @@ -629,9 +636,8 @@ def load_doc(requested_modules: list) -> str: def get_schema() -> dict: """Return jsonschema coalesced from all cc_* cloud-config modules.""" paths = read_cfg_paths() - schema_files = glob.glob( - os.path.join(paths.schema_dir, "cloud-init-schema-*") - ) + schema_dir = os.environ.get("CLOUD_INIT_SCHEMA_DIR", paths.schema_dir) + schema_files = glob.glob(os.path.join(schema_dir, "cloud-init-schema-*")) full_schema = None if len(schema_files) > 1: LOG.warning( diff --git a/doc/rtd/conf.py b/doc/rtd/conf.py index d2cb6ae1..bbaa44e3 100644 --- a/doc/rtd/conf.py +++ b/doc/rtd/conf.py @@ -18,7 +18,7 @@ sys.path.insert(0, os.path.abspath(".")) # General information about the project. project = "cloud-init" -copyright = "2020, Canonical Ltd." +copyright = "2022, Canonical Ltd." # -- General configuration ---------------------------------------------------- @@ -104,6 +104,8 @@ deps = commands = {envpython} -m sphinx {posargs:doc/rtd doc/rtd_html} doc8 doc/rtd +passenv= + CLOUD_INIT_SCHEMA_DIR [testenv:tip-flake8] commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/ setup.py} |