Skip to content

Commit

Permalink
Big file reorganisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Oct 5, 2023
1 parent 9b7efa0 commit a4b7f19
Show file tree
Hide file tree
Showing 27 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion clientele/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions clientele/generators/README.md
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@
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,
write_to_init,
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
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 0 additions & 6 deletions clientele/settings.py
Original file line number Diff line number Diff line change
@@ -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(".")]
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a4b7f19

Please sign in to comment.