Skip to content

Commit

Permalink
rename constants to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Oct 3, 2023
1 parent 1164888 commit 1ddfc3e
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log


## 0.7.0

* `constants.py` has been renamed to `config.py` to better reflect how it is used.

## 0.6.3

* Packaged application installs in the correct location. Resolving [#6](https://github.com/phalt/clientele/issues/6)
Expand Down
2 changes: 1 addition & 1 deletion clientele/client_template/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import httpx # noqa

from . import constants as c # noqa
from . import config as c # noqa


class APIException(Exception):
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions clientele/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def generate_manifest(self):

def generate(self) -> None:
copy_tree(src=CLIENT_TEMPLATE_ROOT, dst=self.output_dir)
if not exists(f"{self.output_dir}/constants.py"):
if not exists(f"{self.output_dir}/config.py"):
copyfile(
f"{CONSTANTS_ROOT}/constants_template.py",
f"{self.output_dir}/constants.py",
f"{CONSTANTS_ROOT}/config_template.py",
f"{self.output_dir}/config.py",
)
self.generate_manifest()
self.schemas_generator.generate_schema_classes()
Expand Down
2 changes: 1 addition & 1 deletion clientele/generators/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generate_http_content(self) -> None:
client_type=client_type,
)
console.log(
f"[yellow]Please see {self.output_dir}constants.py to set authentication variables"
f"[yellow]Please see {self.output_dir}config.py to set authentication variables"
)
elif info["type"] == "oauth2":
template = templates.get_template("bearer_client.jinja2")
Expand Down
2 changes: 1 addition & 1 deletion clientele/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
)
TEMPLATES_ROOT = dirname(dirname(abspath(__file__))) + "/clientele/templates/"
CONSTANTS_ROOT = dirname(dirname(abspath(__file__))) + "/clientele/"
VERSION = "0.6.3"
VERSION = "0.7.0"

templates = Environment(loader=PackageLoader("clientele", "templates"))
12 changes: 6 additions & 6 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Run it now and you will see this output:
my_client/
__init__.py
client.py
constants.py
config.py
http.py
MANIFEST
schemas.py
Expand Down Expand Up @@ -179,9 +179,9 @@ class ExampleEnum(str, Enum):
One of the problems with auto-generated clients is that you often need to configure them, and
if you try and regenerate the client at some point then your configuration gets wiped clean and you have to do it all over again.

Clientele solves this problem by providing an entry point for configuration that will never be overwritten - `constants.py`.
Clientele solves this problem by providing an entry point for configuration that will never be overwritten - `config.py`.

When you first generate the project, you will see a file called `constants.py` and it will offer configuration functions a bit like this:
When you first generate the project, you will see a file called `config.py` and it will offer configuration functions a bit like this:

```python
"""
Expand Down Expand Up @@ -228,10 +228,10 @@ Then clientele will provide you information on the environment variables you nee
make this work during the generation. For example:

```sh
Please see my_client/constants.py to set authentication variables
Please see my_client/config.py to set authentication variables
```

The `constants.py` file will have entry points for you to configure, for example, HTTP Bearer authentication will need the `get_bearer_token` function to be updated, something like this:
The `config.py` file will have entry points for you to configure, for example, HTTP Bearer authentication will need the `get_bearer_token` function to be updated, something like this:

```py

Expand All @@ -247,7 +247,7 @@ def get_bearer_token() -> str:

### Additional headers

If you want to pass specific headers with all requests made by the client, you can configure the `additional_headers` function in `constants.py` to do this.
If you want to pass specific headers with all requests made by the client, you can configure the `additional_headers` function in `config.py` to do this.

```py
def additional_headers() -> dict:
Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Once installed you can run `clientele version` to make sure you have the latest

```sh
> clientele version
clientele 0.6.3
clientele 0.7.0
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "clientele"
version = "0.6.3"
version = "0.7.0"
description = "Generate loveable Python HTTP API Clients"
authors = ["Paul Hallett <paulandrewhallett@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/async_test_client/MANIFEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipx install clientele

API VERSION: 0.1.0
OPENAPI VERSION: 3.0.2
CLIENTELE VERSION: 0.6.3
CLIENTELE VERSION: 0.7.0

Generated using this command:

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/async_test_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import httpx # noqa

from . import constants as c # noqa
from . import config as c # noqa


class APIException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_async_generated_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from httpx import Response
from respx import MockRouter

from .async_test_client import client, constants, http, schemas
from .async_test_client import client, config, http, schemas

BASE_URL = constants.api_base_url()
BASE_URL = config.api_base_url()


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client/MANIFEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipx install clientele

API VERSION: 0.1.0
OPENAPI VERSION: 3.0.2
CLIENTELE VERSION: 0.6.3
CLIENTELE VERSION: 0.7.0

Generated using this command:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def additional_headers() -> dict:
"""
Modify this function ot provide additional headers to all
Modify this function to provide additional headers to all
HTTP requests made by this client.
"""
return {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import httpx # noqa

from . import constants as c # noqa
from . import config as c # noqa


class APIException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generated_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from httpx import Response
from respx import MockRouter

from .test_client import client, constants, http, schemas
from .test_client import client, config, http, schemas

BASE_URL = constants.api_base_url()
BASE_URL = config.api_base_url()


@pytest.mark.respx(base_url=BASE_URL)
Expand Down

0 comments on commit 1ddfc3e

Please sign in to comment.