diff --git a/CHANGELOG.md b/CHANGELOG.md index 059c369..a16a9d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.7.0 * Updated all files to use the templates engine. +* Generator files have been reorganised in clientele to support future templates. * `constants.py` has been renamed to `config.py` to better reflect how it is used. It is not generated from a template like the other files. * If you are using Python 3.10 or later, the `typing.Unions` types will generate as the short hand `|` instead. * To regenerate a client (and to prevent accidental overrides) you must now pass `--regen t` or `-r t` to the `generate` command. This is automatically added to the line in `MANIFEST.md` to help. diff --git a/clientele/cli.py b/clientele/cli.py index 74155bb..d4031ca 100644 --- a/clientele/cli.py +++ b/clientele/cli.py @@ -84,7 +84,7 @@ def generate(url, file, output, asyncio, regen): console = Console() - from clientele.generator import Generator + from clientele.generators.standard.generator import Generator assert url or file, "Must pass either a URL or a file" diff --git a/clientele/generators/README.md b/clientele/generators/README.md new file mode 100644 index 0000000..6bd9ef9 --- /dev/null +++ b/clientele/generators/README.md @@ -0,0 +1,7 @@ +# Generators + +In the future, this will be the directory for all the possible generators that clientele supports. + +## Standard + +The standard generator diff --git a/clientele/generators/standard/__init__.py b/clientele/generators/standard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clientele/generator.py b/clientele/generators/standard/generator.py similarity index 91% rename from clientele/generator.py rename to clientele/generators/standard/generator.py index 25583b0..3004ca6 100644 --- a/clientele/generator.py +++ b/clientele/generators/standard/generator.py @@ -6,16 +6,12 @@ from openapi_core import Spec from rich.console import Console -from clientele.generators.clients import ClientsGenerator -from clientele.generators.http import HTTPGenerator -from clientele.generators.schemas import SchemasGenerator -from clientele.settings import ( - PY_VERSION, - VERSION, +from clientele.generators.standard.generators.clients import ClientsGenerator +from clientele.generators.standard.generators.http import HTTPGenerator +from clientele.generators.standard.generators.schemas import SchemasGenerator +from clientele.generators.standard.utils import get_client_project_directory_path +from clientele.generators.standard.writer import ( templates, -) -from clientele.utils import get_client_project_directory_path -from clientele.writer import ( write_to_client, write_to_config, write_to_http, @@ -23,13 +19,19 @@ write_to_manifest, write_to_schemas, ) +from clientele.settings import ( + PY_VERSION, + VERSION, +) console = Console() class Generator: """ - Top-level generator. + The standard Clientele generator. + + Produces a Python HTTP Client library. """ spec: Spec diff --git a/clientele/generators/standard/generators/__init__.py b/clientele/generators/standard/generators/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clientele/generators/clients.py b/clientele/generators/standard/generators/clients.py similarity index 97% rename from clientele/generators/clients.py rename to clientele/generators/standard/generators/clients.py index a129425..65f30a7 100644 --- a/clientele/generators/clients.py +++ b/clientele/generators/standard/generators/clients.py @@ -5,10 +5,9 @@ from pydantic import BaseModel from rich.console import Console -from clientele.generators.http import HTTPGenerator -from clientele.generators.schemas import SchemasGenerator -from clientele.settings import templates -from clientele.utils import ( +from clientele.generators.standard.generators.http import HTTPGenerator +from clientele.generators.standard.generators.schemas import SchemasGenerator +from clientele.generators.standard.utils import ( class_name_titled, clean_prop, create_query_args, @@ -18,7 +17,7 @@ schema_ref, union_for_py_ver, ) -from clientele.writer import write_to_client +from clientele.generators.standard.writer import templates, write_to_client console = Console() diff --git a/clientele/generators/http.py b/clientele/generators/standard/generators/http.py similarity index 97% rename from clientele/generators/http.py rename to clientele/generators/standard/generators/http.py index a7c397d..2166928 100644 --- a/clientele/generators/http.py +++ b/clientele/generators/standard/generators/http.py @@ -3,8 +3,7 @@ from openapi_core import Spec from rich.console import Console -from clientele.settings import templates -from clientele.writer import write_to_http +from clientele.generators.standard.writer import templates, write_to_http console = Console() diff --git a/clientele/generators/schemas.py b/clientele/generators/standard/generators/schemas.py similarity index 98% rename from clientele/generators/schemas.py rename to clientele/generators/standard/generators/schemas.py index 65fe842..8922f9f 100644 --- a/clientele/generators/schemas.py +++ b/clientele/generators/standard/generators/schemas.py @@ -3,15 +3,14 @@ from openapi_core import Spec from rich.console import Console -from clientele.settings import templates -from clientele.utils import ( +from clientele.generators.standard.utils import ( class_name_titled, clean_prop, get_schema_from_ref, get_type, schema_ref, ) -from clientele.writer import write_to_schemas +from clientele.generators.standard.writer import templates, write_to_schemas console = Console() diff --git a/clientele/templates/async_methods.jinja2 b/clientele/generators/standard/templates/async_methods.jinja2 similarity index 100% rename from clientele/templates/async_methods.jinja2 rename to clientele/generators/standard/templates/async_methods.jinja2 diff --git a/clientele/templates/basic_client.jinja2 b/clientele/generators/standard/templates/basic_client.jinja2 similarity index 100% rename from clientele/templates/basic_client.jinja2 rename to clientele/generators/standard/templates/basic_client.jinja2 diff --git a/clientele/templates/bearer_client.jinja2 b/clientele/generators/standard/templates/bearer_client.jinja2 similarity index 100% rename from clientele/templates/bearer_client.jinja2 rename to clientele/generators/standard/templates/bearer_client.jinja2 diff --git a/clientele/templates/client.jinja2 b/clientele/generators/standard/templates/client.jinja2 similarity index 100% rename from clientele/templates/client.jinja2 rename to clientele/generators/standard/templates/client.jinja2 diff --git a/clientele/templates/client_py.jinja2 b/clientele/generators/standard/templates/client_py.jinja2 similarity index 100% rename from clientele/templates/client_py.jinja2 rename to clientele/generators/standard/templates/client_py.jinja2 diff --git a/clientele/templates/config_py.jinja2 b/clientele/generators/standard/templates/config_py.jinja2 similarity index 100% rename from clientele/templates/config_py.jinja2 rename to clientele/generators/standard/templates/config_py.jinja2 diff --git a/clientele/templates/get_method.jinja2 b/clientele/generators/standard/templates/get_method.jinja2 similarity index 100% rename from clientele/templates/get_method.jinja2 rename to clientele/generators/standard/templates/get_method.jinja2 diff --git a/clientele/templates/http_py.jinja2 b/clientele/generators/standard/templates/http_py.jinja2 similarity index 100% rename from clientele/templates/http_py.jinja2 rename to clientele/generators/standard/templates/http_py.jinja2 diff --git a/clientele/templates/manifest.jinja2 b/clientele/generators/standard/templates/manifest.jinja2 similarity index 100% rename from clientele/templates/manifest.jinja2 rename to clientele/generators/standard/templates/manifest.jinja2 diff --git a/clientele/templates/post_method.jinja2 b/clientele/generators/standard/templates/post_method.jinja2 similarity index 100% rename from clientele/templates/post_method.jinja2 rename to clientele/generators/standard/templates/post_method.jinja2 diff --git a/clientele/templates/schema_class.jinja2 b/clientele/generators/standard/templates/schema_class.jinja2 similarity index 100% rename from clientele/templates/schema_class.jinja2 rename to clientele/generators/standard/templates/schema_class.jinja2 diff --git a/clientele/templates/schema_helpers.jinja2 b/clientele/generators/standard/templates/schema_helpers.jinja2 similarity index 100% rename from clientele/templates/schema_helpers.jinja2 rename to clientele/generators/standard/templates/schema_helpers.jinja2 diff --git a/clientele/templates/schemas_py.jinja2 b/clientele/generators/standard/templates/schemas_py.jinja2 similarity index 100% rename from clientele/templates/schemas_py.jinja2 rename to clientele/generators/standard/templates/schemas_py.jinja2 diff --git a/clientele/templates/sync_methods.jinja2 b/clientele/generators/standard/templates/sync_methods.jinja2 similarity index 100% rename from clientele/templates/sync_methods.jinja2 rename to clientele/generators/standard/templates/sync_methods.jinja2 diff --git a/clientele/utils.py b/clientele/generators/standard/utils.py similarity index 100% rename from clientele/utils.py rename to clientele/generators/standard/utils.py diff --git a/clientele/writer.py b/clientele/generators/standard/writer.py similarity index 86% rename from clientele/writer.py rename to clientele/generators/standard/writer.py index 11dc48e..c80b2e8 100644 --- a/clientele/writer.py +++ b/clientele/generators/standard/writer.py @@ -1,5 +1,11 @@ from pathlib import Path +from jinja2 import Environment, PackageLoader + +templates = Environment( + loader=PackageLoader("clientele", "generators/standard/templates/") +) + def write_to_schemas(content: str, output_dir: str) -> None: path = Path(output_dir) / "schemas.py" diff --git a/clientele/settings.py b/clientele/settings.py index 8fd03c8..efb4d39 100644 --- a/clientele/settings.py +++ b/clientele/settings.py @@ -1,13 +1,7 @@ import platform -from os.path import abspath, dirname -from jinja2 import Environment, PackageLoader - -TEMPLATES_ROOT = dirname(dirname(abspath(__file__))) + "/clientele/templates/" VERSION = "0.7.0" -templates = Environment(loader=PackageLoader("clientele", "templates")) - def split_ver(): return [int(v) for v in platform.python_version().split(".")] diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 059c369..a16a9d8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.7.0 * Updated all files to use the templates engine. +* Generator files have been reorganised in clientele to support future templates. * `constants.py` has been renamed to `config.py` to better reflect how it is used. It is not generated from a template like the other files. * If you are using Python 3.10 or later, the `typing.Unions` types will generate as the short hand `|` instead. * To regenerate a client (and to prevent accidental overrides) you must now pass `--regen t` or `-r t` to the `generate` command. This is automatically added to the line in `MANIFEST.md` to help.