Skip to content

Commit

Permalink
Make config.py a template
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Oct 4, 2023
1 parent ac47678 commit 12e5cb6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## 0.7.0

* `constants.py` has been renamed to `config.py` to better reflect how it is used.
* If you are using Python 3.10 or later, the `typing.Unions` types will generate as the short hand `|` instead. This required a big rework of the code to enable templating.
* Updated some templated files to use the templates engine.
* `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.
* Clientele will now automatically run [black](https://black.readthedocs.io/en/stable/) code formatter once a client is generated or regenerated.
* Clientele will now generate absolute paths to refer to adjacent files in the generated client, instead of relative paths. This assumes you are running the `clientele` command in the root directory of your project.
Expand Down
15 changes: 9 additions & 6 deletions clientele/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
from clientele.generators.schemas import SchemasGenerator
from clientele.settings import (
CLIENT_TEMPLATE_ROOT,
CONSTANTS_ROOT,
VERSION,
PY_VERSION,
templates,
)
from clientele.writer import write_to_manifest, write_to_http, write_to_client
from clientele.writer import (
write_to_manifest,
write_to_http,
write_to_client,
write_to_config,
)
from clientele.utils import get_client_project_directory_path

console = Console()
Expand Down Expand Up @@ -73,10 +77,9 @@ def generate_templates_files(self):
)
copy_tree(src=CLIENT_TEMPLATE_ROOT, dst=self.output_dir)
if not exists(f"{self.output_dir}/config.py"):
copyfile(
f"{CONSTANTS_ROOT}/config_template.py",
f"{self.output_dir}/config.py",
)
template = templates.get_template("config_py.jinja2")
content = template.render()
write_to_config(content, output_dir=self.output_dir)
# client file
if exists(f"{self.output_dir}/client.py"):
remove(f"{self.output_dir}/client.py")
Expand Down
1 change: 0 additions & 1 deletion clientele/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
dirname(dirname(abspath(__file__))) + "/clientele/client_template/"
)
TEMPLATES_ROOT = dirname(dirname(abspath(__file__))) + "/clientele/templates/"
CONSTANTS_ROOT = dirname(dirname(abspath(__file__))) + "/clientele/"
VERSION = "0.7.0"

templates = Environment(loader=PackageLoader("clientele", "templates"))
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions clientele/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def write_to_manifest(content: str, output_dir: str) -> None:
_write_to(path, content)


def write_to_config(content: str, output_dir: str) -> None:
path = Path(output_dir) / "config.py"
_write_to(path, content)


def _write_to(
path: Path,
content: str,
Expand Down
5 changes: 3 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## 0.7.0

* `constants.py` has been renamed to `config.py` to better reflect how it is used.
* If you are using Python 3.10 or later, the `typing.Unions` types will generate as the short hand `|` instead. This required a big rework of the code to enable templating.
* Updated some templated files to use the templates engine.
* `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.
* Clientele will now automatically run [black](https://black.readthedocs.io/en/stable/) code formatter once a client is generated or regenerated.
* Clientele will now generate absolute paths to refer to adjacent files in the generated client, instead of relative paths. This assumes you are running the `clientele` command in the root directory of your project.
Expand Down

0 comments on commit 12e5cb6

Please sign in to comment.