Skip to content

Commit

Permalink
add script to generate Schemastore's schema for rockcraft.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
linostar committed Jan 18, 2024
1 parent b3bc4d7 commit a8c230a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
craft_application>=1.2.1
craft_cli>=2.5.0
craft_parts>=1.26.1
59 changes: 59 additions & 0 deletions .github/scripts/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Creation of schema for rockcraft.yaml."""
import json
import sys
from typing import TYPE_CHECKING

from craft_parts import Part

sys.path.append("rockcraft")

from rockcraft import errors # noqa: E402
from rockcraft.models.project import Project # noqa: E402

if TYPE_CHECKING:
import argparse


def generate_project_schema() -> str:
"""Generate the schema."""
project = Project(
name="placeholder",
version="1.0",
summary="summary",
description="description",
base="[email protected]",
parts=[],
license="MIT",
platforms={"amd64": None},
)
project_schema = project.schema(by_alias=True)

part = Part(name="placeholder", data={})
part_schema = part.spec.schema(by_alias=True)

project_schema["properties"]["parts"]["additionalProperties"] = {
"$ref": "#/definitions/Part"
}
project_schema["definitions"]["Part"] = part_schema

return json.dumps(project_schema, indent=2)


if __name__ == "__main__":
print(generate_project_schema())

0 comments on commit a8c230a

Please sign in to comment.