From 7c75698e0bc504d3c343769ddaf41c7e293e4a3e Mon Sep 17 00:00:00 2001 From: tarsil Date: Fri, 8 Mar 2024 09:20:34 +0000 Subject: [PATCH 1/2] Rollback SETTINGS_MODULE --- docs/release-notes.md | 4 ++-- docs/settings.md | 20 ++++++++++---------- docs/tenancy/contrib.md | 6 +++--- pyproject.toml | 2 +- saffier/conf/__init__.py | 11 ++++++++--- tests/conftest.py | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 61fd53b..7d0893c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -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 @@ -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). diff --git a/docs/settings.md b/docs/settings.md index b21503c..87e4d5a 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -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 @@ -88,7 +88,7 @@ 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 +$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier ``` Example: @@ -96,31 +96,31 @@ 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 diff --git a/docs/tenancy/contrib.md b/docs/tenancy/contrib.md index a26e8a1..bbdab51 100644 --- a/docs/tenancy/contrib.md +++ b/docs/tenancy/contrib.md @@ -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. @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 60d8e8e..6333b2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/saffier/conf/__init__.py b/saffier/conf/__init__.py index 484ea31..937f922 100644 --- a/saffier/conf/__init__.py +++ b/saffier/conf/__init__.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 922a9d5..bca0ba0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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") From 7fdb38f00aca344a47648177049f3ca11bdbfc92 Mon Sep 17 00:00:00 2001 From: tarsil Date: Fri, 8 Mar 2024 09:25:10 +0000 Subject: [PATCH 2/2] Fix requirement dependencies --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6333b2e..a38323c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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",