From 4ab9ac59ac5e61bda7cc2344fa0d68edaa792510 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Thu, 25 Jan 2024 14:36:07 +0000 Subject: [PATCH 01/11] first prototype --- piccolo/apps/migrations/piccolo_app.py | 9 +++++ piccolo/apps/migrations/tables.py | 18 +++++++++- piccolo/conf/apps.py | 47 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/piccolo/apps/migrations/piccolo_app.py b/piccolo/apps/migrations/piccolo_app.py index 614a974fc..53e252781 100644 --- a/piccolo/apps/migrations/piccolo_app.py +++ b/piccolo/apps/migrations/piccolo_app.py @@ -16,4 +16,13 @@ Command(callable=forwards, aliases=["f", "forward"]), Command(callable=new, aliases=["n", "create"]), ], + options={ + # By default the migration table is created in the public schema - you + # can override this if you want the migration table to be created in + # a different schema. + "schema": None, + # You can override the name of the migration table if it clashes + # with an existing table in the database. + "tablename": None, + }, ) diff --git a/piccolo/apps/migrations/tables.py b/piccolo/apps/migrations/tables.py index 91906be4f..d76b466be 100644 --- a/piccolo/apps/migrations/tables.py +++ b/piccolo/apps/migrations/tables.py @@ -4,10 +4,26 @@ from piccolo.columns import Timestamp, Varchar from piccolo.columns.defaults.timestamp import TimestampNow +from piccolo.conf.apps import Finder from piccolo.table import Table +TABLENAME = Finder().get_app_option( + app_name="migrations", + option_name="tablename", +) -class Migration(Table): + +SCHEMA = Finder().get_app_option( + app_name="migrations", + option_name="tablename", +) + + +class Migration( + Table, + tablename=TABLENAME, + schema=SCHEMA, +): name = Varchar(length=200) app_name = Varchar(length=200) ran_on = Timestamp(default=TimestampNow()) diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index c311e1569..ec754a310 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -154,6 +154,34 @@ class AppConfig: the Piccolo CLI. For example, with a Piccolo app called ``'article'``, and a command called ``new``, it can be called on the command line using ``piccolo article new``. + :param options: + This allows the app's behaviour to be customised by setting values in + ``piccolo_conf.py``. Define any options you want, for example if we + have an app for booking tickets:: + + { + "max_tickets_per_user": 10 + } + + To override this value in ``piccolo_conf.py`` do the following:: + + APP_OPTIONS = { + "my_app": { + "max_tickets_per_user": 15 + } + } + + The app can retrieve the value as follows: + + from piccolo.conf.apps import Finder + + max_tickets_per_user = Finder().get_app_option( + "my_app", + "max_tickets_per_user" + ) + + In this example, ``15`` is returned. If it hadn't been overriden in + ``piccolo_conf.py`` then the default value of ``10`` would returned. """ @@ -164,6 +192,7 @@ class AppConfig: commands: t.List[t.Union[t.Callable, Command]] = field( default_factory=list ) + options: t.Dict[str, t.Any] = field(default_factory=dict) def __post_init__(self) -> None: if isinstance(self.migrations_folder_path, pathlib.Path): @@ -419,6 +448,24 @@ def get_app_registry(self) -> AppRegistry: piccolo_conf_module = self.get_piccolo_conf_module() return getattr(piccolo_conf_module, "APP_REGISTRY") + def get_app_option(self, app_name: str, option_name: str) -> t.Any: + """ + Returns the value for ``option_name`` for the given app. It first looks + for overrides in ``piccolo_conf.py``, and if not found, returns the + default value. + + """ + piccolo_conf_module = self.get_piccolo_conf_module() + app_options = getattr(piccolo_conf_module, "APP_OPTIONS", {}) + value = app_options.get(app_name, {}).get(option_name, ...) + + if value is not ...: + return value + + return self.get_app_config(app_name=app_name).options.get( + option_name, ... + ) + def get_engine( self, module_name: t.Optional[str] = None ) -> t.Optional[Engine]: From 3c753a624543fa3c6410dcfa3b42789fe21157c5 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Thu, 25 Jan 2024 14:48:39 +0000 Subject: [PATCH 02/11] put app options in the `AppRegistry` instead --- piccolo/conf/apps.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index ec754a310..9b8ae97ca 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -165,11 +165,14 @@ class AppConfig: To override this value in ``piccolo_conf.py`` do the following:: - APP_OPTIONS = { - "my_app": { - "max_tickets_per_user": 15 + APP_REGISTRY = AppRegistry( + apps=["my_app"], + app_options={ + "my_app": { + "max_tickets_per_user": 15 + } } - } + ) The app can retrieve the value as follows: @@ -257,8 +260,14 @@ class AppRegistry: """ - def __init__(self, apps: t.Optional[t.List[str]] = None): + def __init__( + self, + apps: t.Optional[t.List[str]] = None, + options: t.Optional[t.Dict[str, t.Dict[str, t.Any]]] = None, + ): self.apps = apps or [] + self.options = options or {} + self.app_configs: t.Dict[str, AppConfig] = {} app_names = [] @@ -455,9 +464,10 @@ def get_app_option(self, app_name: str, option_name: str) -> t.Any: default value. """ - piccolo_conf_module = self.get_piccolo_conf_module() - app_options = getattr(piccolo_conf_module, "APP_OPTIONS", {}) - value = app_options.get(app_name, {}).get(option_name, ...) + app_registry = self.get_app_registry() + value = app_registry.app_options.get(app_name, {}).get( + option_name, ... + ) if value is not ...: return value From e91534d2b0a84744768f801b139f58617c5a4920 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Thu, 25 Jan 2024 14:53:52 +0000 Subject: [PATCH 03/11] rename `options` to `app_options` --- piccolo/conf/apps.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index 9b8ae97ca..ed661613e 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -263,10 +263,10 @@ class AppRegistry: def __init__( self, apps: t.Optional[t.List[str]] = None, - options: t.Optional[t.Dict[str, t.Dict[str, t.Any]]] = None, + app_options: t.Optional[t.Dict[str, t.Dict[str, t.Any]]] = None, ): self.apps = apps or [] - self.options = options or {} + self.app_options = app_options or {} self.app_configs: t.Dict[str, AppConfig] = {} app_names = [] @@ -462,7 +462,6 @@ def get_app_option(self, app_name: str, option_name: str) -> t.Any: Returns the value for ``option_name`` for the given app. It first looks for overrides in ``piccolo_conf.py``, and if not found, returns the default value. - """ app_registry = self.get_app_registry() value = app_registry.app_options.get(app_name, {}).get( @@ -472,9 +471,11 @@ def get_app_option(self, app_name: str, option_name: str) -> t.Any: if value is not ...: return value - return self.get_app_config(app_name=app_name).options.get( - option_name, ... - ) + app_config = app_registry.get_app_config(app_name=app_name) + if app_config is None: + raise ValueError("The app name isn't recognised.") + + return app_config.options.get(option_name, ...) def get_engine( self, module_name: t.Optional[str] = None From 558a972eb62402f85ffaaee57640910cb5f02430 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Thu, 25 Jan 2024 15:47:12 +0000 Subject: [PATCH 04/11] add tests --- piccolo/conf/apps.py | 9 +++++++-- tests/conf/test_apps.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index ed661613e..3d4043a1c 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -464,18 +464,23 @@ def get_app_option(self, app_name: str, option_name: str) -> t.Any: default value. """ app_registry = self.get_app_registry() + + # See if the option was overridden: value = app_registry.app_options.get(app_name, {}).get( option_name, ... ) - if value is not ...: return value + # Get the default value: app_config = app_registry.get_app_config(app_name=app_name) if app_config is None: raise ValueError("The app name isn't recognised.") - return app_config.options.get(option_name, ...) + if option_name not in app_config.options: + raise ValueError("The option name isn't recognised.") + + return app_config.options[option_name] def get_engine( self, module_name: t.Optional[str] = None diff --git a/tests/conf/test_apps.py b/tests/conf/test_apps.py index 907064e1f..943755ef7 100644 --- a/tests/conf/test_apps.py +++ b/tests/conf/test_apps.py @@ -2,6 +2,7 @@ import pathlib from unittest import TestCase +from unittest.mock import MagicMock, patch from piccolo.apps.user.tables import BaseUser from piccolo.conf.apps import AppConfig, AppRegistry, Finder, table_finder @@ -304,3 +305,42 @@ def test_sort_app_configs(self): self.assertListEqual( [i.app_name for i in sorted_app_configs], ["app_2", "app_1"] ) + + @patch("piccolo.conf.apps.Finder.get_app_registry") + def test_get_app_option(self, get_app_registry: MagicMock): + """ + Make sure we can retrieve app options. + """ + schema = "schema_1" + app_registry = AppRegistry( + apps=["piccolo.apps.migrations.piccolo_app"], + app_options={"migrations": {"schema": schema}}, + ) + get_app_registry.return_value = app_registry + + # Make sure we can successfully retrieve an option. + option = Finder().get_app_option( + app_name="migrations", option_name="schema" + ) + self.assertEqual(option, schema) + + # Make sure the default value is returned if the option wasn't + # overridden. + option = Finder().get_app_option( + app_name="migrations", option_name="tablename" + ) + self.assertEqual(option, None) + + # Make sure an error is raised if the app isn't recognised. + with self.assertRaises(ValueError) as e: + Finder().get_app_option( + app_name="some_app", option_name="some_option" + ) + self.assertEqual(str(e.exception), "The app name isn't recognised.") + + # Make sure an error is raised if the option isn't recognised. + with self.assertRaises(ValueError) as e: + Finder().get_app_option( + app_name="migrations", option_name="some_option" + ) + self.assertEqual(str(e.exception), "The option name isn't recognised.") From 4c2cbb2b6e274e3828401565711973ae8fe025e3 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:29:36 +0000 Subject: [PATCH 05/11] use toml for options instead --- piccolo/apps/migrations/piccolo_app.py | 9 --- piccolo/apps/migrations/tables.py | 12 +-- piccolo/conf/apps.py | 56 -------------- piccolo/conf/overrides.py | 101 +++++++++++++++++++++++++ piccolo_overrides.toml | 1 + requirements/requirements.txt | 1 + tests/conf/data/test_overrides.toml | 2 + tests/conf/test_apps.py | 40 ---------- tests/conf/test_overrides.py | 27 +++++++ 9 files changed, 135 insertions(+), 114 deletions(-) create mode 100644 piccolo/conf/overrides.py create mode 100644 piccolo_overrides.toml create mode 100644 tests/conf/data/test_overrides.toml create mode 100644 tests/conf/test_overrides.py diff --git a/piccolo/apps/migrations/piccolo_app.py b/piccolo/apps/migrations/piccolo_app.py index 53e252781..614a974fc 100644 --- a/piccolo/apps/migrations/piccolo_app.py +++ b/piccolo/apps/migrations/piccolo_app.py @@ -16,13 +16,4 @@ Command(callable=forwards, aliases=["f", "forward"]), Command(callable=new, aliases=["n", "create"]), ], - options={ - # By default the migration table is created in the public schema - you - # can override this if you want the migration table to be created in - # a different schema. - "schema": None, - # You can override the name of the migration table if it clashes - # with an existing table in the database. - "tablename": None, - }, ) diff --git a/piccolo/apps/migrations/tables.py b/piccolo/apps/migrations/tables.py index d76b466be..18104e21d 100644 --- a/piccolo/apps/migrations/tables.py +++ b/piccolo/apps/migrations/tables.py @@ -4,19 +4,13 @@ from piccolo.columns import Timestamp, Varchar from piccolo.columns.defaults.timestamp import TimestampNow -from piccolo.conf.apps import Finder +from piccolo.conf.overrides import get_override from piccolo.table import Table -TABLENAME = Finder().get_app_option( - app_name="migrations", - option_name="tablename", -) +TABLENAME = get_override(key="PICCOLO_MIGRATION_TABLENAME", default=None) -SCHEMA = Finder().get_app_option( - app_name="migrations", - option_name="tablename", -) +SCHEMA = get_override(key="PICCOLO_MIGRATION_SCHEMA", default=None) class Migration( diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index 3d4043a1c..3e842301e 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -154,37 +154,6 @@ class AppConfig: the Piccolo CLI. For example, with a Piccolo app called ``'article'``, and a command called ``new``, it can be called on the command line using ``piccolo article new``. - :param options: - This allows the app's behaviour to be customised by setting values in - ``piccolo_conf.py``. Define any options you want, for example if we - have an app for booking tickets:: - - { - "max_tickets_per_user": 10 - } - - To override this value in ``piccolo_conf.py`` do the following:: - - APP_REGISTRY = AppRegistry( - apps=["my_app"], - app_options={ - "my_app": { - "max_tickets_per_user": 15 - } - } - ) - - The app can retrieve the value as follows: - - from piccolo.conf.apps import Finder - - max_tickets_per_user = Finder().get_app_option( - "my_app", - "max_tickets_per_user" - ) - - In this example, ``15`` is returned. If it hadn't been overriden in - ``piccolo_conf.py`` then the default value of ``10`` would returned. """ @@ -457,31 +426,6 @@ def get_app_registry(self) -> AppRegistry: piccolo_conf_module = self.get_piccolo_conf_module() return getattr(piccolo_conf_module, "APP_REGISTRY") - def get_app_option(self, app_name: str, option_name: str) -> t.Any: - """ - Returns the value for ``option_name`` for the given app. It first looks - for overrides in ``piccolo_conf.py``, and if not found, returns the - default value. - """ - app_registry = self.get_app_registry() - - # See if the option was overridden: - value = app_registry.app_options.get(app_name, {}).get( - option_name, ... - ) - if value is not ...: - return value - - # Get the default value: - app_config = app_registry.get_app_config(app_name=app_name) - if app_config is None: - raise ValueError("The app name isn't recognised.") - - if option_name not in app_config.options: - raise ValueError("The option name isn't recognised.") - - return app_config.options[option_name] - def get_engine( self, module_name: t.Optional[str] = None ) -> t.Optional[Engine]: diff --git a/piccolo/conf/overrides.py b/piccolo/conf/overrides.py new file mode 100644 index 000000000..87edba12d --- /dev/null +++ b/piccolo/conf/overrides.py @@ -0,0 +1,101 @@ +import logging +import os +import typing as t + +try: + import tomllib # type: ignore +except ImportError: + import tomli as tomllib + + +logger = logging.getLogger(__name__) + + +class OverrideLoader: + """ + The user can optionally add a ``piccolo_overrides.toml`` file at the root + of their project (wherever the Python interpreter will be started). + + This can be used to modify some of the internal workings of Piccolo. + Examples are the tablename and schema of the ``Migration`` table. + + The reason we don't have these values in ``piccolo_conf.py`` is we want the + values to be static. Also, they could be required at any point by Piccolo, + before the app has fully loaded all of the Python code, so having a static + file helps prevent circular imports. + + """ + + _toml_contents: t.Optional[t.Dict[str, t.Any]] + + def __init__( + self, + toml_file_name: str = "piccolo_overrides.toml", + folder_path: t.Optional[str] = None, + ): + self.toml_file_name = toml_file_name + self._toml_contents = None + self.folder_path = folder_path or os.getcwd() + + def get_toml_contents(self) -> t.Dict[str, t.Any]: + """ + Returns the contents of the TOML file. + """ + if self._toml_contents is None: + toml_file_path = os.path.join( + self.folder_path, + self.toml_file_name, + ) + + if os.path.exists(toml_file_path): + with open(toml_file_path, "rb") as f: + self._toml_contents = tomllib.load(f) + else: + raise FileNotFoundError("The toml file wasn't found.") + + return self._toml_contents + + def get_override(self, key: str, default: t.Any = None) -> t.Any: + """ + Returns the corresponding value from the TOML file if found, otherwise + the default value is returned instead. + """ + try: + toml_contents = self.get_toml_contents() + except FileNotFoundError: + logger.debug(f"{self.toml_file_name} wasn't found") + return default + else: + value = toml_contents.get(key, ...) + + if value is ...: + return default + + logger.debug(f"Loaded {key} from toml file.") + return value + + def validate(self): + """ + Can be used to manually check the TOML file can be loaded:: + + from piccolo.conf.overrides import OverrideLoader + + >>> OverrideLoader().validate() + + """ + try: + self.get_toml_contents() + except Exception as e: + raise e + else: + print("Successfully loaded TOML file!") + + +DEFAULT_LOADER = OverrideLoader() + + +def get_override(key: str, default: t.Any = None) -> t.Any: + """ + A convenience, instead of ``DEFAULT_LOADER.get_override``. + """ + return DEFAULT_LOADER.get_override(key=key, default=default) diff --git a/piccolo_overrides.toml b/piccolo_overrides.toml new file mode 100644 index 000000000..15c13bd07 --- /dev/null +++ b/piccolo_overrides.toml @@ -0,0 +1 @@ +PICCOLO_MIGRATION_SCHEMA = "test" diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 0a5ee6244..378540f70 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -5,3 +5,4 @@ targ>=0.3.7 inflection>=0.5.1 typing-extensions>=4.3.0 pydantic[email]==2.* +tomli;python_version<="3.10" diff --git a/tests/conf/data/test_overrides.toml b/tests/conf/data/test_overrides.toml new file mode 100644 index 000000000..591d31afa --- /dev/null +++ b/tests/conf/data/test_overrides.toml @@ -0,0 +1,2 @@ +# Used by test_overrides.py +MY_TEST_VALUE = "hello world" diff --git a/tests/conf/test_apps.py b/tests/conf/test_apps.py index 943755ef7..907064e1f 100644 --- a/tests/conf/test_apps.py +++ b/tests/conf/test_apps.py @@ -2,7 +2,6 @@ import pathlib from unittest import TestCase -from unittest.mock import MagicMock, patch from piccolo.apps.user.tables import BaseUser from piccolo.conf.apps import AppConfig, AppRegistry, Finder, table_finder @@ -305,42 +304,3 @@ def test_sort_app_configs(self): self.assertListEqual( [i.app_name for i in sorted_app_configs], ["app_2", "app_1"] ) - - @patch("piccolo.conf.apps.Finder.get_app_registry") - def test_get_app_option(self, get_app_registry: MagicMock): - """ - Make sure we can retrieve app options. - """ - schema = "schema_1" - app_registry = AppRegistry( - apps=["piccolo.apps.migrations.piccolo_app"], - app_options={"migrations": {"schema": schema}}, - ) - get_app_registry.return_value = app_registry - - # Make sure we can successfully retrieve an option. - option = Finder().get_app_option( - app_name="migrations", option_name="schema" - ) - self.assertEqual(option, schema) - - # Make sure the default value is returned if the option wasn't - # overridden. - option = Finder().get_app_option( - app_name="migrations", option_name="tablename" - ) - self.assertEqual(option, None) - - # Make sure an error is raised if the app isn't recognised. - with self.assertRaises(ValueError) as e: - Finder().get_app_option( - app_name="some_app", option_name="some_option" - ) - self.assertEqual(str(e.exception), "The app name isn't recognised.") - - # Make sure an error is raised if the option isn't recognised. - with self.assertRaises(ValueError) as e: - Finder().get_app_option( - app_name="migrations", option_name="some_option" - ) - self.assertEqual(str(e.exception), "The option name isn't recognised.") diff --git a/tests/conf/test_overrides.py b/tests/conf/test_overrides.py new file mode 100644 index 000000000..d55107c4e --- /dev/null +++ b/tests/conf/test_overrides.py @@ -0,0 +1,27 @@ +import os +from unittest import TestCase + +from piccolo.conf.overrides import OverrideLoader + + +class TestOverrideLoader(TestCase): + def test_get_override(self): + """ + Make sure we can get overrides from a TOML file. + """ + loader = OverrideLoader( + toml_file_name="test_overrides.toml", + folder_path=os.path.join(os.path.dirname(__file__), "data"), + ) + self.assertEqual( + loader.get_override( + key="MY_TEST_VALUE", + ), + "hello world", + ) + + self.assertIsNone( + loader.get_override( + key="WRONG_KEY", + ) + ) From 42db861bbf7d441a408d49134a215225304dc878 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:30:44 +0000 Subject: [PATCH 06/11] remove unused code --- piccolo/conf/apps.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/piccolo/conf/apps.py b/piccolo/conf/apps.py index 3e842301e..c311e1569 100644 --- a/piccolo/conf/apps.py +++ b/piccolo/conf/apps.py @@ -164,7 +164,6 @@ class AppConfig: commands: t.List[t.Union[t.Callable, Command]] = field( default_factory=list ) - options: t.Dict[str, t.Any] = field(default_factory=dict) def __post_init__(self) -> None: if isinstance(self.migrations_folder_path, pathlib.Path): @@ -229,14 +228,8 @@ class AppRegistry: """ - def __init__( - self, - apps: t.Optional[t.List[str]] = None, - app_options: t.Optional[t.Dict[str, t.Dict[str, t.Any]]] = None, - ): + def __init__(self, apps: t.Optional[t.List[str]] = None): self.apps = apps or [] - self.app_options = app_options or {} - self.app_configs: t.Dict[str, AppConfig] = {} app_names = [] From f95ad541af5d113336fd9348718705aa06c9bb81 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:31:30 +0000 Subject: [PATCH 07/11] update docstring --- piccolo/conf/overrides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piccolo/conf/overrides.py b/piccolo/conf/overrides.py index 87edba12d..564af595b 100644 --- a/piccolo/conf/overrides.py +++ b/piccolo/conf/overrides.py @@ -17,7 +17,7 @@ class OverrideLoader: of their project (wherever the Python interpreter will be started). This can be used to modify some of the internal workings of Piccolo. - Examples are the tablename and schema of the ``Migration`` table. + Examples are the ``tablename`` and ``schema`` of the ``Migration`` table. The reason we don't have these values in ``piccolo_conf.py`` is we want the values to be static. Also, they could be required at any point by Piccolo, From e11fbc2bb260736d41f9303d7dc322bf25be93aa Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:32:23 +0000 Subject: [PATCH 08/11] reorder init method --- piccolo/conf/overrides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piccolo/conf/overrides.py b/piccolo/conf/overrides.py index 564af595b..4b11fda1d 100644 --- a/piccolo/conf/overrides.py +++ b/piccolo/conf/overrides.py @@ -34,8 +34,8 @@ def __init__( folder_path: t.Optional[str] = None, ): self.toml_file_name = toml_file_name - self._toml_contents = None self.folder_path = folder_path or os.getcwd() + self._toml_contents = None def get_toml_contents(self) -> t.Dict[str, t.Any]: """ From 1ae5ddcf4d59d055d89e954f78b8ef96790d4477 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:33:52 +0000 Subject: [PATCH 09/11] `toml` -> `TOML` --- piccolo/conf/overrides.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/piccolo/conf/overrides.py b/piccolo/conf/overrides.py index 4b11fda1d..21ad0b92d 100644 --- a/piccolo/conf/overrides.py +++ b/piccolo/conf/overrides.py @@ -51,7 +51,7 @@ def get_toml_contents(self) -> t.Dict[str, t.Any]: with open(toml_file_path, "rb") as f: self._toml_contents = tomllib.load(f) else: - raise FileNotFoundError("The toml file wasn't found.") + raise FileNotFoundError("The TOML file wasn't found.") return self._toml_contents @@ -71,7 +71,7 @@ def get_override(self, key: str, default: t.Any = None) -> t.Any: if value is ...: return default - logger.debug(f"Loaded {key} from toml file.") + logger.debug(f"Loaded {key} from TOML file.") return value def validate(self): From 50b5516651f053931240364590682a316f6b1316 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 15:57:02 +0000 Subject: [PATCH 10/11] fix mypy warning --- piccolo/conf/overrides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piccolo/conf/overrides.py b/piccolo/conf/overrides.py index 21ad0b92d..7c3e62290 100644 --- a/piccolo/conf/overrides.py +++ b/piccolo/conf/overrides.py @@ -5,7 +5,7 @@ try: import tomllib # type: ignore except ImportError: - import tomli as tomllib + import tomli as tomllib # type: ignore logger = logging.getLogger(__name__) From 565b28144c52afec712aa35a8c60009967a32001 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 26 Jan 2024 16:03:01 +0000 Subject: [PATCH 11/11] Delete piccolo_overrides.toml --- piccolo_overrides.toml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 piccolo_overrides.toml diff --git a/piccolo_overrides.toml b/piccolo_overrides.toml deleted file mode 100644 index 15c13bd07..000000000 --- a/piccolo_overrides.toml +++ /dev/null @@ -1 +0,0 @@ -PICCOLO_MIGRATION_SCHEMA = "test"