Skip to content

Commit

Permalink
refactor: setup generate schema
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Dec 26, 2024
1 parent d0761fb commit 7196c51
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ repos:
name: Generate Config Schemas
language: system
entry: uv run generate-config-schema # Require venv activated
files: '^src/check_phat_nguoi/models/.*$'
files: '^src/check_phat_nguoi/models/'
types: [file, python]
verbose: true
stages:
- pre-commit
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ uv sync # no need uv venv
uv run pre-commit install

uv run check-phat-nguoi
uv run generate-schema

# Just for single schema generation
uv run generate-config-schema
```

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies = ["pydantic>=2.10.4", "requests>=2.32.3"]

[project.scripts]
check-phat-nguoi = "check_phat_nguoi:main"
generate-config-schema = "generate_config_schema:main"
generate-config-schema = "generate_schemas:generate_config_schema"
generate-schema = "generate_schemas:main"

[build-system]
requires = ["hatchling"]
Expand Down
3 changes: 3 additions & 0 deletions src/check_phat_nguoi/models/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ class ConfigModel(BaseModel):
log_level: LogLevelModel = LogLevelModel.warning


print("coo")


__all__ = ["ConfigModel"]
11 changes: 0 additions & 11 deletions src/generate_config_schema/__init__.py

This file was deleted.

9 changes: 9 additions & 0 deletions src/generate_schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from generate_schemas.modules import generate_config_schema


def main() -> None:
print("Generating config schema...")
generate_config_schema()


__all__ = ["generate_config_schema"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from generate_config_schema import main
from generate_schemas import main

if __name__ == "__main__":
main()
Expand Down
3 changes: 3 additions & 0 deletions src/generate_schemas/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from generate_schemas.modules.config import generate_config_schema

__all__ = ["generate_config_schema"]
13 changes: 13 additions & 0 deletions src/generate_schemas/modules/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from json import dumps

from pydantic import TypeAdapter

from check_phat_nguoi.models.config import ConfigModel
from generate_schemas.utils.constant import CONFIG_SCHEMA_PATH


def generate_config_schema():
adapter = TypeAdapter(ConfigModel)
with open(CONFIG_SCHEMA_PATH, "w", encoding="utf8") as file:
file.write(dumps(adapter.json_schema(), indent=2))
print(f"Created {CONFIG_SCHEMA_PATH} successfully!")
1 change: 1 addition & 0 deletions src/generate_schemas/utils/constant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SCHEMA_PATH: str = "schemas/config.json"

0 comments on commit 7196c51

Please sign in to comment.