Skip to content

Commit

Permalink
Add invoke command to generate repository schema for the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Mar 18, 2024
1 parent 3a4ae89 commit 4bb1236
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ python_sdk/dist/*

# Test reports
**/*.csv

# Generated files
generated/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://schema.infrahub.app/python-sdk/repository-config/develop.json
---

check_definitions:
Expand Down
3 changes: 2 additions & 1 deletion tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from invoke import Collection, Context, task

from . import backend, demo, docs, main, performance, sdk, sync, test
from . import backend, demo, docs, main, performance, schema, sdk, sync, test

ns = Collection()
ns.add_collection(sdk)
Expand All @@ -11,6 +11,7 @@
ns.add_collection(backend)
ns.add_collection(demo)
ns.add_collection(main)
ns.add_collection(schema)
ns.add_collection(sync)
ns.add_collection(test)

Expand Down
32 changes: 32 additions & 0 deletions tasks/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from pathlib import Path

from invoke.context import Context
from invoke.tasks import task

from .utils import REPO_BASE

SDK_DIRECTORY = f"{REPO_BASE}/generated/python-sdk"
INFRAHUB_DIRECTORY = f"{REPO_BASE}/generated/python-sdk"


@task
def generate_jsonschema(context: Context):
"""Generate JSON schemas into ./generated"""

generate_sdk_repository_config()


def generate_sdk_repository_config():
from infrahub_sdk.schema import InfrahubRepositoryConfig

repository_dir = f"{SDK_DIRECTORY}/repository-config"
Path(repository_dir).mkdir(parents=True, exist_ok=True)
schema = InfrahubRepositoryConfig.schema_json(indent=4)

write(filename=f"{repository_dir}/develop.json", content=schema)


def write(filename: str, content: str) -> None:
with open(filename, "w", encoding="utf-8") as fobj:
fobj.write(content)
print(f"Wrote to {filename}")

0 comments on commit 4bb1236

Please sign in to comment.