generated from Hochfrequenz/python_template_repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c3643d
commit 3dd79a9
Showing
8 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from bo4e_cli.commands.entry import app | ||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .diff import sub_app_diff | ||
from .edit import edit | ||
from .entry import app | ||
from .generate import generate | ||
from .pull import pull | ||
|
||
app.add_typer(sub_app_diff, name="diff") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pathlib import Path | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
sub_app_diff = typer.Typer() | ||
|
||
|
||
@sub_app_diff.command("schemas") | ||
def diff_schemas( | ||
*, | ||
input_dir_base: Annotated[Path, typer.Argument()], | ||
input_dir_comp: Annotated[Path, typer.Argument()], | ||
output_file: Annotated[Path, typer.Option(help="The JSON-file to save the differences to.", show_default=False)], | ||
): | ||
""" | ||
Compare the JSON-schemas in the two input directories and save the differences to the output file. | ||
The output file will contain the differences in JSON-format. It will also contain information about the | ||
compared versions. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pathlib import Path | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
from bo4e_cli.commands.entry import app | ||
|
||
|
||
@app.command() | ||
def edit( | ||
*, | ||
input_dir: Annotated[Path, typer.Option(help="The directory to read the JSON-schemas from.", show_default=False)], | ||
output_dir: Annotated[ | ||
Path, typer.Option(help="The directory to save the edited JSON-schemas to.", show_default=False) | ||
], | ||
config: Annotated[ | ||
Optional[Path], typer.Option(help="The configuration file to use for editing the JSON-schemas.") | ||
] = None, | ||
set_default_version: Annotated[ | ||
bool, | ||
typer.Option( | ||
help="Automatically set or overrides the default version for '_version' fields with the version from " | ||
".version file. This is especially useful if you want to define additional models which should " | ||
"always have the correct version." | ||
), | ||
] = True, | ||
clear_output: Annotated[bool, typer.Option(help="Clear the output directory before saving the schemas.")] = True, | ||
): | ||
""" | ||
Edit the JSON-schemas in the input directory and save the edited schemas to the output directory. | ||
The schemas in the input directory won't be changed. If no configuration file is provided, the schemas will be | ||
copied to the output directory unchanged. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import typer | ||
|
||
app = typer.Typer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from enum import StrEnum | ||
from pathlib import Path | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
from bo4e_cli.commands.entry import app | ||
|
||
|
||
class GenerateType(StrEnum): | ||
""" | ||
A custom type for the generate command. | ||
""" | ||
|
||
PYTHON_PYDANTIC_V1 = "python-pydantic-v1" | ||
PYTHON_PYDANTIC_V2 = "python-pydantic-v2" | ||
PYTHON_SQL_MODEL = "python-sql-model" | ||
|
||
|
||
@app.command() | ||
def generate( | ||
*, | ||
input_dir: Annotated[Path, typer.Option(help="The directory to read the JSON-schemas from.", show_default=False)], | ||
output_dir: Annotated[Path, typer.Option(help="The directory to save the generated code to.", show_default=False)], | ||
output_type: Annotated[GenerateType, typer.Option(help="The type of code to generate.", show_default=False)], | ||
clear_output: Annotated[ | ||
bool, typer.Option(help="Clear the output directory before saving the generated code.") | ||
] = True, | ||
): | ||
""" | ||
Generate the BO4E models from the JSON-schemas in the input directory and save them in the output directory. | ||
Several output types are available, see --output-type. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pathlib import Path | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
from bo4e_cli.commands.entry import app | ||
|
||
|
||
@app.command() | ||
def pull( | ||
*, | ||
output_dir: Annotated[Path, typer.Option(help="The directory to save the JSON-schemas to.", show_default=False)], | ||
version_tag: Annotated[ | ||
str, | ||
typer.Option( | ||
help="The BO4E-version tag to pull the data for. " | ||
"They will be pulled from https://github.com/bo4e/BO4E-Schemas." | ||
), | ||
] = "latest", | ||
update_refs: Annotated[ | ||
bool, | ||
typer.Option( | ||
help="Automatically update the references in the schemas. " | ||
"Online references to BO4E-schemas will be replaced by relative paths." | ||
), | ||
] = True, | ||
clear_output: Annotated[bool, typer.Option(help="Clear the output directory before saving the schemas.")] = True, | ||
token: Annotated[ | ||
Optional[str], | ||
typer.Option( | ||
help="A GitHub Access token to authenticate with the GitHub API. " | ||
"Use this if you have problems with the rate limit. " | ||
"Alternatively, you can set the environment variable GITHUB_ACCESS_TOKEN.", | ||
envvar="GITHUB_ACCESS_TOKEN", | ||
), | ||
] = None, | ||
): | ||
""" | ||
Pull all BO4E-JSON-schemas of a specific version. | ||
Beside the json-files a .version file will be created in utf-8 format at root of the output directory. | ||
This file is needed for other commands. | ||
""" | ||
pass |