Skip to content

refactor: relocate json schemas out of the python package - #7062

Open
baha-bouali wants to merge 2 commits into
canonical:mainfrom
baha-bouali:relocate-schemas
Open

baha-bouali wants to merge 2 commits into
canonical:mainfrom
baha-bouali:relocate-schemas

Conversation

@baha-bouali

Copy link
Copy Markdown

The JSON schemas are data, not Python code, and some of them are not
specific to config modules. Move them from cloudinit/config/schemas/
to a top-level schemas/ directory, and install them as architecture
independent data under /cloud-init/schemas.

Because the schemas no longer sit beside the code that reads them,
get_schema_dir() can no longer derive their location from file
alone. Meson records the configured install path in a generated
cloudinit/meson_paths.py, following the existing meson_versions.py
pattern. When that file is absent, as in a source checkout, the
source tree layout is used instead.

The cloudinit/config/schemas/init.py was never required and is
dropped.

Fixes GH-4688

Additional Context

Three notes for reviewers:

  1. Directory name. I used schemas/ to match the install location
    agreed in refactor : Relocate json schemas #4991 (/usr/share/cloud-init/schemas).

  2. The issue predates meson. It lists setup.py, which no longer
    exists after Pep632 support meson build #6326. The install is done in meson.build instead.

  3. The $id URL changes. versions.schema.cloud-config.json now
    points at .../main/schemas/. The old
    .../main/cloudinit/config/schemas/ URLs will 404 once this merges,
    so a follow-up PR to SchemaStore is needed. I'd open a follow-up once
    this lands.

Test Steps

Unit tests, including three new cases covering source checkout,
installed system, and a recorded path that no longer exists:

tox -e py3 -- tests/unittests/config/test_schema.py

The install layout cannot be covered by unit tests, so verify it
manually:

meson setup builddir
DESTDIR=/tmp/stage meson install -C builddir

# schemas installed as data:
find /tmp/stage -path '*share/cloud-init/schemas*' -name '*.json'

# and no longer inside the python package:
find /tmp/stage -path '*dist-packages/cloudinit*' -name '*.json'

Then confirm a real install resolves them, with the source tree off
sys.path:

cd /tmp && PYTHONPATH=<prefix>/lib/python3/dist-packages python3 -c \
  "from cloudinit.config.schema import get_schema_dir, get_schema; \
   print(get_schema_dir()); assert get_schema()"

cloud-init schema -c user-data.yaml also still validates normally
from a checkout.

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@github-actions github-actions Bot added the documentation This Pull Request changes documentation label Aug 31, 2026
Remove fallback explanation for schema directory retrieval.
@baha-bouali

Copy link
Copy Markdown
Author

@holmanb just a gentle ping, can you take a look at this whenever you have a chance.

@github-actions

Copy link
Copy Markdown

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging blackboxsw, and he will ensure that someone takes a look soon.

(If the pull request is closed and you would like to continue working on it, please do tag blackboxsw to reopen it.)

@github-actions github-actions Bot added the stale-pr Pull request is stale; will be auto-closed soon label Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation This Pull Request changes documentation stale-pr Pull request is stale; will be auto-closed soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement]: Relocate json schemas somewhere more sensible

1 participant