Skip to content

Commit

Permalink
Merge pull request #135 from tarsil/fix/settings_module
Browse files Browse the repository at this point in the history
Rollback SETTINGS_MODULE
  • Loading branch information
tarsil authored Mar 8, 2024
2 parents 0ee722d + 7fdb38f commit d5fb255
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ field with `auto_now`.

### Fixed

- Fix default for `SETTINGS_MODULE` if nothing is provided.
- Fix default for `SAFFIER_SETTINGS_MODULE` if nothing is provided.

## 1.3.0

Expand Down Expand Up @@ -65,7 +65,7 @@ SAFFIER_SETTINGS_MODULE=...
**From version 1.3.0 is**:

```python
SETTINGS_MODULE=...
SAFFIER_SETTINGS_MODULE=...
```

The rest remains as it. More information about [how to use it in the official documentation](https://settings.dymmond.com/#how-to-use-it_1).
Expand Down
20 changes: 10 additions & 10 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ This is exactly what happened.

The way of using the settings object within a Saffier use of the ORM is via:

* **SETTINGS_MODULE** environment variable.
* **SAFFIER_SETTINGS_MODULE** environment variable.

All the settings are **[pydantic BaseSettings](https://pypi.org/project/pydantic-settings/)** objects which makes it easier to use and override
when needed.

### SETTINGS_MODULE
### SAFFIER_SETTINGS_MODULE

Saffier by default uses is looking for a `SETTINGS_MODULE` environment variable to run and
Saffier by default uses is looking for a `SAFFIER_SETTINGS_MODULE` environment variable to run and
apply the given settings to your instance.

If no `SETTINGS_MODULE` is found, Saffier then uses its own internal settings which are
If no `SAFFIER_SETTINGS_MODULE` is found, Saffier then uses its own internal settings which are
widely applied across the system.

#### Custom settings
Expand Down Expand Up @@ -88,39 +88,39 @@ Using the example [above](#custom-settings) and the location `myproject/configs/
settings should be called like this:

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier <COMMAND>
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier <COMMAND>
```

Example:

**Starting the default shell**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell
```

**Starting the PTPython shell**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell --kernel ptpython
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell --kernel ptpython
```

**Creating the migrations folder**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier init
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier init
```

**Generating migrations**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier makemigrations
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier makemigrations
```

**Appying migrations**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier migrate
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier migrate
```

And the list goes on and on, you get the gist. To understand which commands are available, check
Expand Down
6 changes: 3 additions & 3 deletions docs/tenancy/contrib.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module of **Saffier** which means you would only needed to override the needed v
Every model that required to be applied on a `tenant` (schema) level, you require to inherit from
the [TenantModel](#tenantmodel) and pass the `is_tenant=True` parameter in the `Meta` class.

To use this module, you will need to have your [SETTINGS_MODULE](../settings.md#settings_module)
To use this module, you will need to have your [SAFFIER_SETTINGS_MODULE](../settings.md#settings_module)
set as well. More on this in the [TenancySettings](#tenancysettings).

More on this in the [example](#example) provided.
Expand Down Expand Up @@ -108,7 +108,7 @@ Now there are two ways that you can approach this.
* `domain_name: str = "localhost"` - Used by the [Domain](#domain) model.
* `auth_user_model: Optional[str] = None` - Used by the [TenantUser](#tenantuser) model.

2. **You inherit the `TenancySettings` object and override the values needed and use it as your [SETTINGS_MODULE](../settings.md#settings_module)**.
2. **You inherit the `TenancySettings` object and override the values needed and use it as your [SAFFIER_SETTINGS_MODULE](../settings.md#settings_module)**.

```python
from saffier.contrib.multi_tenancy import TenancySettings
Expand Down Expand Up @@ -265,7 +265,7 @@ The settings can be stored in a location like `myapp/configs/saffier/settings.py
**Make the settings globally available to Saffier**.

```shell
$ export SETTINGS_MODULE=myapp.configs.saffier.settings.EdgySettings
$ export SAFFIER_SETTINGS_MODULE=myapp.configs.saffier.settings.EdgySettings
```

Exporting as an environment variable will make sure Saffier will use your settings instead of the
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = [
"alembic>=1.11.3,<2.0.0",
"anyio>=4.0.0,<5",
"click>=8.1.3,<9.0.0",
"dymmond-settings>=1.0.2",
"dymmond-settings>=1.0.3",
"loguru>=0.6.0,<0.10.0",
"databasez>=0.7.2",
"orjson >=3.8.5,<4.0.0",
Expand Down Expand Up @@ -79,6 +79,7 @@ test = [
"asyncpg>=0.27.0,<1",
"asyncmy>=0.2.7,<0.3.0",
"esmerald>=2.0.0",
"httpx>=0.25.0,<0.30.0",
"pytest>=7.1.3,<9.0.0",
"pytest-cov>=2.12.0,<5.0.0",
"pytest-asyncio >=0.19.0",
Expand Down
11 changes: 8 additions & 3 deletions saffier/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import os

if not os.environ.get("SETTINGS_MODULE"):
os.environ.setdefault("SETTINGS_MODULE", "saffier.conf.global_settings.SaffierSettings")
from dymmond_settings import settings as settings
os.environ.setdefault("OVERRIDE_SETTINGS_MODULE_VARIABLE", "SAFFIER_SETTINGS_MODULE")

if not os.environ.get("SAFFIER_SETTINGS_MODULE"):
os.environ.setdefault(
"SAFFIER_SETTINGS_MODULE", "saffier.conf.global_settings.SaffierSettings"
)

from dymmond_settings import settings as settings # noqa
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

os.environ.setdefault("SETTINGS_MODULE", "tests.settings.TestSettings")
os.environ.setdefault("SAFFIER_SETTINGS_MODULE", "tests.settings.TestSettings")


@pytest.fixture(scope="module")
Expand Down

0 comments on commit d5fb255

Please sign in to comment.