Skip to content

Commit

Permalink
schema: allow CLOUD_INIT_SCHEMA_DIR env override for Paths.schema_dir
Browse files Browse the repository at this point in the history
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
  • Loading branch information
blackboxsw committed Jan 13, 2022
1 parent 3bf0220 commit 2b43a2e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion cloudinit/config/cc_apt_pipelining.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@


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()

Expand Down
20 changes: 13 additions & 7 deletions cloudinit/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion doc/rtd/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# General information about the project.
project = "cloud-init"
copyright = "2020, Canonical Ltd."
copyright = "2022, Canonical Ltd."

# -- General configuration ----------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 2b43a2e

Please sign in to comment.