From 2d8ecd424ae446b76a6c0e79b966f39909c979f3 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:11:14 +0200 Subject: [PATCH 1/9] Switched mysql package --- src/cpl_core/cpl-core.json | 8 ++-- .../connection/database_connection.py | 38 +++++++++---------- src/cpl_core/database/database_settings.py | 8 ++-- .../database/src/appsettings.edrafts-pc.json | 3 +- tests/custom/database/src/model/db_context.py | 4 +- tests/custom/database/src/startup.py | 2 +- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/cpl_core/cpl-core.json b/src/cpl_core/cpl-core.json index c0971a86..b968200e 100644 --- a/src/cpl_core/cpl-core.json +++ b/src/cpl_core/cpl-core.json @@ -3,8 +3,8 @@ "Name": "cpl-core", "Version": { "Major": "2023", - "Minor": "4", - "Micro": "0.post5" + "Minor": "10", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -18,7 +18,6 @@ "Dependencies": [ "art>=5.9", "colorama>=0.4.6", - "mysql-connector>=2.2.9", "psutil>=5.9.4", "packaging>=23.0", "pynput>=1.7.6", @@ -26,7 +25,8 @@ "tabulate>=0.9.0", "termcolor>=2.2.0", "watchdog>=3.0.0", - "wheel>=0.40.0" + "wheel>=0.40.0", + "mysql-connector-python==8.1.0" ], "DevDependencies": [ "Sphinx==5.0.2", diff --git a/src/cpl_core/database/connection/database_connection.py b/src/cpl_core/database/connection/database_connection.py index 32ba2211..562618fc 100644 --- a/src/cpl_core/database/connection/database_connection.py +++ b/src/cpl_core/database/connection/database_connection.py @@ -25,27 +25,27 @@ class DatabaseConnection(DatabaseConnectionABC): def cursor(self) -> MySQLCursorBuffered: return self._cursor - def connect(self, database_settings: DatabaseSettings): + def connect(self, settings: DatabaseSettings): connection = sql.connect( - host=database_settings.host, - port=database_settings.port, - user=database_settings.user, - passwd=CredentialManager.decrypt(database_settings.password), - charset=database_settings.charset, - use_unicode=database_settings.use_unicode, - buffered=database_settings.buffered, - auth_plugin=database_settings.auth_plugin, + host=settings.host, + port=settings.port, + user=settings.user, + passwd=CredentialManager.decrypt(settings.password), + charset=settings.charset, + use_unicode=settings.use_unicode, + buffered=settings.buffered, + auth_plugin=settings.auth_plugin, ) - connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{database_settings.database}`;") + connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{settings.database}`;") self._database = sql.connect( - host=database_settings.host, - port=database_settings.port, - user=database_settings.user, - passwd=CredentialManager.decrypt(database_settings.password), - db=database_settings.database, - charset=database_settings.charset, - use_unicode=database_settings.use_unicode, - buffered=database_settings.buffered, - auth_plugin=database_settings.auth_plugin, + host=settings.host, + port=settings.port, + user=settings.user, + passwd=CredentialManager.decrypt(settings.password), + db=settings.database, + charset=settings.charset, + use_unicode=settings.use_unicode, + buffered=settings.buffered, + auth_plugin=settings.auth_plugin, ) self._cursor = self._database.cursor() diff --git a/src/cpl_core/database/database_settings.py b/src/cpl_core/database/database_settings.py index d6bac435..e1f774ed 100644 --- a/src/cpl_core/database/database_settings.py +++ b/src/cpl_core/database/database_settings.py @@ -13,10 +13,10 @@ class DatabaseSettings(ConfigurationModelABC): user: str = None, password: str = None, database: str = None, - charset: str = None, - use_unicode: bool = None, - buffered: bool = None, - auth_plugin: str = None, + charset: str = "utf8mb4", + use_unicode: bool = False, + buffered: bool = False, + auth_plugin: str = "caching_sha2_password", ): ConfigurationModelABC.__init__(self) diff --git a/tests/custom/database/src/appsettings.edrafts-pc.json b/tests/custom/database/src/appsettings.edrafts-pc.json index 66214fc1..78bff4d4 100644 --- a/tests/custom/database/src/appsettings.edrafts-pc.json +++ b/tests/custom/database/src/appsettings.edrafts-pc.json @@ -20,7 +20,6 @@ "Database": "sh_cpl", "Charset": "utf8mb4", "UseUnicode": "true", - "Buffered": "true", - "AuthPlugin": "mysql_native_password" + "Buffered": "true" } } \ No newline at end of file diff --git a/tests/custom/database/src/model/db_context.py b/tests/custom/database/src/model/db_context.py index 0d6fc017..73a28eb7 100644 --- a/tests/custom/database/src/model/db_context.py +++ b/tests/custom/database/src/model/db_context.py @@ -3,5 +3,5 @@ from cpl_core.database.context import DatabaseContext class DBContext(DatabaseContext): - def __init__(self, db_settings: DatabaseSettings): - DatabaseContext.__init__(self, db_settings) + def __init__(self): + DatabaseContext.__init__(self) diff --git a/tests/custom/database/src/startup.py b/tests/custom/database/src/startup.py index 0fa0daec..fbd1029a 100644 --- a/tests/custom/database/src/startup.py +++ b/tests/custom/database/src/startup.py @@ -21,7 +21,6 @@ class Startup(StartupABC): ) -> ConfigurationABC: configuration.add_environment_variables("PYTHON_") configuration.add_environment_variables("CPL_") - configuration.parse_console_arguments() configuration.add_json_file(f"appsettings.json") configuration.add_json_file(f"appsettings.{configuration.environment.environment_name}.json") configuration.add_json_file(f"appsettings.{configuration.environment.host_name}.json", optional=True) @@ -34,6 +33,7 @@ class Startup(StartupABC): self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC ) -> ServiceProviderABC: # Create and connect to database + self._configuration.parse_console_arguments(services) db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings) services.add_db_context(DBContext, db_settings) -- 2.45.2 From f357e97ce50cfcdf0455c2b4151a550e9ea9ac1f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:16:16 +0200 Subject: [PATCH 2/9] Build and formatted new version --- src/cpl_cli/_templates/build/__init__.py | 14 +++++++------- src/cpl_core/__init__.py | 4 ++-- src/cpl_core/application/__init__.py | 4 ++-- src/cpl_core/configuration/__init__.py | 4 ++-- src/cpl_core/console/__init__.py | 4 ++-- src/cpl_core/database/__init__.py | 4 ++-- src/cpl_core/database/connection/__init__.py | 4 ++-- src/cpl_core/database/context/__init__.py | 4 ++-- src/cpl_core/dependency_injection/__init__.py | 4 ++-- src/cpl_core/environment/__init__.py | 4 ++-- src/cpl_core/logging/__init__.py | 4 ++-- src/cpl_core/mailing/__init__.py | 4 ++-- src/cpl_core/pipes/__init__.py | 4 ++-- src/cpl_core/time/__init__.py | 4 ++-- src/cpl_core/utils/__init__.py | 4 ++-- src/cpl_translation/__init__.py | 15 ++++++++------- 16 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/cpl_cli/_templates/build/__init__.py b/src/cpl_cli/_templates/build/__init__.py index b0db4743..f8dc727c 100644 --- a/src/cpl_cli/_templates/build/__init__.py +++ b/src/cpl_cli/_templates/build/__init__.py @@ -11,16 +11,16 @@ CPL Command Line Interface """ -__title__ = "cpl_cli._templates.build" -__author__ = "Sven Heidemann" -__license__ = "MIT" -__copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__title__ = 'cpl_cli._templates.build' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 - 2023 sh-edraft.de' +__version__ = '2023.4.0.post3' from collections import namedtuple # imports: -VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='2023', minor='4', micro='0.post3') diff --git a/src/cpl_core/__init__.py b/src/cpl_core/__init__.py index 33ce0454..ed3ace4f 100644 --- a/src/cpl_core/__init__.py +++ b/src/cpl_core/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/application/__init__.py b/src/cpl_core/application/__init__.py index 5fcf7174..60d4c1b8 100644 --- a/src/cpl_core/application/__init__.py +++ b/src/cpl_core/application/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.application" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -29,4 +29,4 @@ from .startup_abc import StartupABC from .startup_extension_abc import StartupExtensionABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/configuration/__init__.py b/src/cpl_core/configuration/__init__.py index 781834b2..43ef5fb5 100644 --- a/src/cpl_core/configuration/__init__.py +++ b/src/cpl_core/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.configuration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -35,4 +35,4 @@ from .validator_abc import ValidatorABC from .variable_argument import VariableArgument VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/console/__init__.py b/src/cpl_core/console/__init__.py index f6199039..435f9e82 100644 --- a/src/cpl_core/console/__init__.py +++ b/src/cpl_core/console/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.console" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -28,4 +28,4 @@ from .foreground_color_enum import ForegroundColorEnum from .spinner_thread import SpinnerThread VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/database/__init__.py b/src/cpl_core/database/__init__.py index 5006ae8d..94d450f2 100644 --- a/src/cpl_core/database/__init__.py +++ b/src/cpl_core/database/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.database" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -26,4 +26,4 @@ from .database_settings import DatabaseSettings from .table_abc import TableABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/database/connection/__init__.py b/src/cpl_core/database/connection/__init__.py index a8df7d2b..ea268300 100644 --- a/src/cpl_core/database/connection/__init__.py +++ b/src/cpl_core/database/connection/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.database.connection" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .database_connection import DatabaseConnection from .database_connection_abc import DatabaseConnectionABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/database/context/__init__.py b/src/cpl_core/database/context/__init__.py index 62c55f1c..5be4020a 100644 --- a/src/cpl_core/database/context/__init__.py +++ b/src/cpl_core/database/context/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.database.context" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .database_context import DatabaseContext from .database_context_abc import DatabaseContextABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/dependency_injection/__init__.py b/src/cpl_core/dependency_injection/__init__.py index 14dbe033..866eb9b7 100644 --- a/src/cpl_core/dependency_injection/__init__.py +++ b/src/cpl_core/dependency_injection/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.dependency_injection" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -31,4 +31,4 @@ from .service_provider import ServiceProvider from .service_provider_abc import ServiceProviderABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/environment/__init__.py b/src/cpl_core/environment/__init__.py index 27d4f3fc..ebac8b19 100644 --- a/src/cpl_core/environment/__init__.py +++ b/src/cpl_core/environment/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.environment" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -26,4 +26,4 @@ from .environment_name_enum import EnvironmentNameEnum from .application_environment import ApplicationEnvironment VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/logging/__init__.py b/src/cpl_core/logging/__init__.py index ba80edce..dac21e04 100644 --- a/src/cpl_core/logging/__init__.py +++ b/src/cpl_core/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.logging" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -28,4 +28,4 @@ from .logging_settings import LoggingSettings from .logging_settings_name_enum import LoggingSettingsNameEnum VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/mailing/__init__.py b/src/cpl_core/mailing/__init__.py index 398e7dde..6330d10f 100644 --- a/src/cpl_core/mailing/__init__.py +++ b/src/cpl_core/mailing/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.mailing" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -28,4 +28,4 @@ from .email_client_settings import EMailClientSettings from .email_client_settings_name_enum import EMailClientSettingsNameEnum VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/pipes/__init__.py b/src/cpl_core/pipes/__init__.py index ed79ae71..969e85da 100644 --- a/src/cpl_core/pipes/__init__.py +++ b/src/cpl_core/pipes/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.pipes" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -26,4 +26,4 @@ from .ip_address_pipe import IPAddressPipe from .pipe_abc import PipeABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/time/__init__.py b/src/cpl_core/time/__init__.py index 514eeaea..7c3bc16a 100644 --- a/src/cpl_core/time/__init__.py +++ b/src/cpl_core/time/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.time" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .time_format_settings import TimeFormatSettings from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_core/utils/__init__.py b/src/cpl_core/utils/__init__.py index 19743778..f418f34b 100644 --- a/src/cpl_core/utils/__init__.py +++ b/src/cpl_core/utils/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_core.utils" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post5" +__version__ = "2023.10.0" from collections import namedtuple @@ -26,4 +26,4 @@ from .string import String from .pip import Pip VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post5") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_translation/__init__.py b/src/cpl_translation/__init__.py index 7dcc71b7..3c896cf9 100644 --- a/src/cpl_translation/__init__.py +++ b/src/cpl_translation/__init__.py @@ -11,11 +11,11 @@ CPL translation extension """ -__title__ = 'cpl_translation' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' -__version__ = '2023.4.0.post1' +__title__ = "cpl_translation" +__author__ = "Sven Heidemann" +__license__ = "MIT" +__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" +__version__ = "2023.4.0.post1" from collections import namedtuple @@ -25,6 +25,7 @@ from .translate_pipe import TranslatePipe from .translation_service import TranslationService from .translation_service_abc import TranslationServiceABC from .translation_settings import TranslationSettings + # build-ignore @@ -51,5 +52,5 @@ def init(): init() # build-ignore-end -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2023', minor='4', micro='0.post1') +VersionInfo = namedtuple("VersionInfo", "major minor micro") +version_info = VersionInfo(major="2023", minor="4", micro="0.post1") -- 2.45.2 From 1dd48899d74c84cebeb2df1e4a44f9ef6ab7802a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:41:34 +0200 Subject: [PATCH 3/9] Improved cpl-discords service loading for commands and events --- .../dependency_injection/service_provider.py | 8 ++--- .../service_provider_abc.py | 2 +- src/cpl_discord/cpl-discord.json | 4 +-- src/cpl_discord/service/discord_collection.py | 29 ++++++++----------- .../service/discord_collection_abc.py | 8 ----- src/cpl_discord/service/discord_service.py | 23 +++++---------- 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index ac1225db..870b4d27 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -157,12 +157,12 @@ class ServiceProvider(ServiceProviderABC): return implementation - def get_services(self, service_type: typing.Type[T], *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: implementations = [] - if typing.get_origin(service_type) != list: - raise Exception(f"Invalid type {service_type}! Expected list of type") + if typing.get_origin(service_type) == list: + raise Exception(f"Invalid type {service_type}! Expected single type not list of type") - implementations.extend(self._get_services(typing.get_args(service_type)[0])) + implementations.extend(self._get_services(service_type)) return implementations diff --git a/src/cpl_core/dependency_injection/service_provider_abc.py b/src/cpl_core/dependency_injection/service_provider_abc.py index dd195571..c5d6e7eb 100644 --- a/src/cpl_core/dependency_injection/service_provider_abc.py +++ b/src/cpl_core/dependency_injection/service_provider_abc.py @@ -76,7 +76,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_services(self, service_type: Type[T], *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: r"""Returns instance of given type Parameter diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index 25b40374..516dfd0f 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -3,8 +3,8 @@ "Name": "cpl-discord", "Version": { "Major": "2023", - "Minor": "4", - "Micro": "0.post3" + "Minor": "10", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_discord/service/discord_collection.py b/src/cpl_discord/service/discord_collection.py index a5b052da..f58219ae 100644 --- a/src/cpl_discord/service/discord_collection.py +++ b/src/cpl_discord/service/discord_collection.py @@ -1,11 +1,11 @@ -from typing import Type, Optional +from typing import Type +from cpl_core.console import Console, ForegroundColorEnum from cpl_core.dependency_injection import ServiceCollectionABC from cpl_discord.command.discord_command_abc import DiscordCommandABC from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum from cpl_discord.service.command_error_handler_service import CommandErrorHandlerService from cpl_discord.service.discord_collection_abc import DiscordCollectionABC -from cpl_query.extension.list import List class DiscordCollection(DiscordCollectionABC): @@ -13,26 +13,21 @@ class DiscordCollection(DiscordCollectionABC): DiscordCollectionABC.__init__(self) self._services = service_collection - self._events: dict[str, List] = {} - self._commands = List(type(DiscordCommandABC)) self.add_event(DiscordEventTypesEnum.on_command_error.value, CommandErrorHandlerService) def add_command(self, _t: Type[DiscordCommandABC]): + Console.set_foreground_color(ForegroundColorEnum.yellow) + Console.write_line( + f"{type(self).__name__}.add_command is deprecated. Instead, use ServiceCollection.add_transient directly!" + ) + Console.color_reset() self._services.add_transient(DiscordCommandABC, _t) - self._commands.append(_t) - - def get_commands(self) -> List[DiscordCommandABC]: - return self._commands def add_event(self, _t_event: Type, _t: Type): + Console.set_foreground_color(ForegroundColorEnum.yellow) + Console.write_line( + f"{type(self).__name__}.add_event is deprecated. Instead, use ServiceCollection.add_transient directly!" + ) + Console.color_reset() self._services.add_transient(_t_event, _t) - if _t_event not in self._events: - self._events[_t_event] = List(type(_t_event)) - - self._events[_t_event].append(_t) - - def get_events_by_base(self, _t_event: Type) -> Optional[List]: - if _t_event not in self._events: - return None - return self._events[_t_event] diff --git a/src/cpl_discord/service/discord_collection_abc.py b/src/cpl_discord/service/discord_collection_abc.py index bb444f6d..1b9dde62 100644 --- a/src/cpl_discord/service/discord_collection_abc.py +++ b/src/cpl_discord/service/discord_collection_abc.py @@ -13,14 +13,6 @@ class DiscordCollectionABC(ABC): def add_command(self, _t: Type[DiscordCommandABC]): pass - @abstractmethod - def get_commands(self) -> List[DiscordCommandABC]: - pass - @abstractmethod def add_event(self, _t_event: Type, _t: Type): pass - - @abstractmethod - def get_events_by_base(self, _t_event: Type): - pass diff --git a/src/cpl_discord/service/discord_service.py b/src/cpl_discord/service/discord_service.py index 8995803c..9ddb5a4a 100644 --- a/src/cpl_discord/service/discord_service.py +++ b/src/cpl_discord/service/discord_service.py @@ -4,11 +4,12 @@ from typing import Optional, Sequence, Union, Type import discord from discord import RawReactionActionEvent from discord.ext import commands -from discord.ext.commands import Context, CommandError, Cog, Command +from discord.ext.commands import Context, CommandError, Cog from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC from cpl_core.utils import String +from cpl_discord.command import DiscordCommandABC from cpl_discord.command.discord_commands_meta import DiscordCogMeta from cpl_discord.events.on_bulk_message_delete_abc import OnBulkMessageDeleteABC from cpl_discord.events.on_command_abc import OnCommandABC @@ -66,25 +67,17 @@ from cpl_discord.events.on_typing_abc import OnTypingABC from cpl_discord.events.on_user_update_abc import OnUserUpdateABC from cpl_discord.events.on_voice_state_update_abc import OnVoiceStateUpdateABC from cpl_discord.events.on_webhooks_update_abc import OnWebhooksUpdateABC -from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from cpl_discord.service.discord_service_abc import DiscordServiceABC class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): - def __init__(self, logger: LoggerABC, dc_collection: DiscordCollectionABC, services: ServiceProviderABC): + def __init__(self, logger: LoggerABC, services: ServiceProviderABC): DiscordServiceABC.__init__(self) self._logger = logger - self._collection = dc_collection self._services = services async def _handle_event(self, event: Type, *args, **kwargs): - event_collection = self._collection.get_events_by_base(event) - if event_collection is None: - return - - for event_type in event_collection: - event_instance = self._services.get_service(event_type) - + for event_instance in self._services.get_services(event): func_name = event.__name__ if func_name.endswith("ABC"): func_name = func_name.replace("ABC", "") @@ -104,11 +97,11 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): self._logger.error(__name__, f"{type(self).__name__} initialization failed", e) try: - for command_type in self._collection.get_commands(): - self._logger.trace(__name__, f"Register command {command_type.__name__}") - command: Cog = self._services.get_service(command_type) + for command in self._services.get_services(DiscordCommandABC): + self._logger.trace(__name__, f"Register command {type(command).__name__}") + command: Cog = command if command is None: - self._logger.warn(__name__, f"Instance of {command_type.__name__} not found") + self._logger.warn(__name__, f"Instance of {type(command).__name__} not found") continue await bot.add_cog(command) except Exception as e: -- 2.45.2 From b3fd122fcded07a8ad77536a0154b23d7dd06545 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:42:24 +0200 Subject: [PATCH 4/9] Build cpl-discord new version --- src/cpl_discord/.cpl/__init__.py | 4 ++-- src/cpl_discord/__init__.py | 4 ++-- src/cpl_discord/application/__init__.py | 4 ++-- src/cpl_discord/command/__init__.py | 4 ++-- src/cpl_discord/configuration/__init__.py | 4 ++-- src/cpl_discord/container/__init__.py | 4 ++-- src/cpl_discord/events/__init__.py | 4 ++-- src/cpl_discord/helper/__init__.py | 4 ++-- src/cpl_discord/service/__init__.py | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cpl_discord/.cpl/__init__.py b/src/cpl_discord/.cpl/__init__.py index 3d6efdb0..7d25e36e 100644 --- a/src/cpl_discord/.cpl/__init__.py +++ b/src/cpl_discord/.cpl/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py index 6683f441..5973a14b 100644 --- a/src/cpl_discord/__init__.py +++ b/src/cpl_discord/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -59,4 +59,4 @@ def get_discord_collection(services: "ServiceCollectionABC") -> "DiscordCollecti # build-ignore-end VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/application/__init__.py b/src/cpl_discord/application/__init__.py index 58f27536..2e0a1e05 100644 --- a/src/cpl_discord/application/__init__.py +++ b/src/cpl_discord/application/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.application" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .discord_bot_application_abc import DiscordBotApplicationABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py index 70bc2380..670078ea 100644 --- a/src/cpl_discord/command/__init__.py +++ b/src/cpl_discord/command/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.command" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC from .discord_commands_meta import DiscordCogMeta VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py index 9cdc0334..b4810359 100644 --- a/src/cpl_discord/configuration/__init__.py +++ b/src/cpl_discord/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.configuration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .discord_bot_settings import DiscordBotSettings VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/container/__init__.py b/src/cpl_discord/container/__init__.py index a2e9c715..f8051fba 100644 --- a/src/cpl_discord/container/__init__.py +++ b/src/cpl_discord/container/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.container" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -31,4 +31,4 @@ from .thread import Thread from .voice_channel import VoiceChannel VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py index 87de598f..1a8f5151 100644 --- a/src/cpl_discord/events/__init__.py +++ b/src/cpl_discord/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -69,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC from .on_webhooks_update_abc import OnWebhooksUpdateABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/helper/__init__.py b/src/cpl_discord/helper/__init__.py index 06523b11..c473fccf 100644 --- a/src/cpl_discord/helper/__init__.py +++ b/src/cpl_discord/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.helper" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .to_containers_converter import ToContainersConverter VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py index ea5539fc..4c0380bb 100644 --- a/src/cpl_discord/service/__init__.py +++ b/src/cpl_discord/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_discord.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post3" +__version__ = "2023.10.0" from collections import namedtuple @@ -29,4 +29,4 @@ from .discord_service import DiscordService from .discord_service_abc import DiscordServiceABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post3") +version_info = VersionInfo(major="2023", minor="10", micro="0") -- 2.45.2 From 7881294554b7be18ef3530d1f9f56e99756b25f8 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:55:24 +0200 Subject: [PATCH 5/9] Fixed types --- src/cpl_core/configuration/configuration_abc.py | 8 ++++---- src/cpl_core/dependency_injection/service_provider.py | 2 +- src/cpl_core/dependency_injection/service_provider_abc.py | 4 ++-- src/cpl_discord/service/discord_service.py | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpl_core/configuration/configuration_abc.py b/src/cpl_core/configuration/configuration_abc.py index 1f4c8e3e..16beb725 100644 --- a/src/cpl_core/configuration/configuration_abc.py +++ b/src/cpl_core/configuration/configuration_abc.py @@ -77,11 +77,11 @@ class ConfigurationABC(ABC): pass @abstractmethod - def add_configuration(self, key_type: Type[T], value: any): + def add_configuration(self, key_type: T, value: any): r"""Add configuration object Parameter: - key_type: Union[:class:`str`, :class:`type`] + key_type: :class:`cpl_core.type.T` Type of the value value: any Object of the value @@ -124,11 +124,11 @@ class ConfigurationABC(ABC): pass @abstractmethod - def get_configuration(self, search_type: Type[T]) -> Optional[T]: + def get_configuration(self, search_type: T) -> Optional[T]: r"""Returns value from configuration by given type Parameter: - search_type: Union[:class:`str`, Type[:class:`cpl_core.configuration.configuration_model_abc.ConfigurationModelABC`]] + search_type: :class:`cpl_core.type.T` Type to search for Returns: diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index 870b4d27..3b63eaa3 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -138,7 +138,7 @@ class ServiceProvider(ServiceProviderABC): sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context)) return sb.build() - def get_service(self, service_type: typing.Type[T], *args, **kwargs) -> Optional[T]: + def get_service(self, service_type: T, *args, **kwargs) -> Optional[T]: result = self._find_service(service_type) if result is None: diff --git a/src/cpl_core/dependency_injection/service_provider_abc.py b/src/cpl_core/dependency_injection/service_provider_abc.py index c5d6e7eb..3af4b5fe 100644 --- a/src/cpl_core/dependency_injection/service_provider_abc.py +++ b/src/cpl_core/dependency_injection/service_provider_abc.py @@ -61,7 +61,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_service(self, instance_type: Type[T], *args, **kwargs) -> Optional[T]: + def get_service(self, instance_type: T, *args, **kwargs) -> Optional[T]: r"""Returns instance of given type Parameter @@ -81,7 +81,7 @@ class ServiceProviderABC(ABC): Parameter --------- - instance_type: :class:`cpl_core.type.T` + service_type: :class:`cpl_core.type.T` The type of the searched instance Returns diff --git a/src/cpl_discord/service/discord_service.py b/src/cpl_discord/service/discord_service.py index 9ddb5a4a..82bcd35a 100644 --- a/src/cpl_discord/service/discord_service.py +++ b/src/cpl_discord/service/discord_service.py @@ -99,7 +99,6 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): try: for command in self._services.get_services(DiscordCommandABC): self._logger.trace(__name__, f"Register command {type(command).__name__}") - command: Cog = command if command is None: self._logger.warn(__name__, f"Instance of {type(command).__name__} not found") continue -- 2.45.2 From e7af5ce3228c7fe5b585b001d9f89772daeb7434 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 21:05:38 +0200 Subject: [PATCH 6/9] Fixed cpl-query typing --- src/cpl_query/__init__.py | 4 ++-- src/cpl_query/base/__init__.py | 4 ++-- src/cpl_query/cpl-query.json | 4 ++-- src/cpl_query/enumerable/__init__.py | 4 ++-- src/cpl_query/extension/__init__.py | 4 ++-- src/cpl_query/extension/list.py | 4 +--- src/cpl_query/iterable/__init__.py | 4 ++-- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/cpl_query/__init__.py b/src/cpl_query/__init__.py index bb13759e..08c95ea8 100644 --- a/src/cpl_query/__init__.py +++ b/src/cpl_query/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_query" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2021 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post1" +__version__ = "2023.10.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post1") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_query/base/__init__.py b/src/cpl_query/base/__init__.py index 2b10c00e..22d0f52d 100644 --- a/src/cpl_query/base/__init__.py +++ b/src/cpl_query/base/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_query.base" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2021 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post1" +__version__ = "2023.10.0" from collections import namedtuple @@ -28,4 +28,4 @@ from .queryable_abc import QueryableABC from .sequence import Sequence VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post1") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_query/cpl-query.json b/src/cpl_query/cpl-query.json index 3524aee1..a50bc50c 100644 --- a/src/cpl_query/cpl-query.json +++ b/src/cpl_query/cpl-query.json @@ -3,8 +3,8 @@ "Name": "cpl-query", "Version": { "Major": "2023", - "Minor": "4", - "Micro": "0.post1" + "Minor": "10", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_query/enumerable/__init__.py b/src/cpl_query/enumerable/__init__.py index 5d995c29..26b79116 100644 --- a/src/cpl_query/enumerable/__init__.py +++ b/src/cpl_query/enumerable/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_query.enumerable" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2021 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post1" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .enumerable import Enumerable from .enumerable_abc import EnumerableABC VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post1") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_query/extension/__init__.py b/src/cpl_query/extension/__init__.py index 1f6b54c1..82bedb80 100644 --- a/src/cpl_query/extension/__init__.py +++ b/src/cpl_query/extension/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_query.extension" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2021 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post1" +__version__ = "2023.10.0" from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .list import List VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post1") +version_info = VersionInfo(major="2023", minor="10", micro="0") diff --git a/src/cpl_query/extension/list.py b/src/cpl_query/extension/list.py index 0f397acb..3fdcbddf 100644 --- a/src/cpl_query/extension/list.py +++ b/src/cpl_query/extension/list.py @@ -1,12 +1,10 @@ -from typing import Iterator - from cpl_query.iterable.iterable import Iterable class List(Iterable): r"""Implementation of :class: `cpl_query.extension.iterable.Iterable`""" - def __init__(self, t: type = None, values: Iterator = None): + def __init__(self, t: type = None, values: Iterable = None): Iterable.__init__(self, t, values) def __getitem__(self, *args): diff --git a/src/cpl_query/iterable/__init__.py b/src/cpl_query/iterable/__init__.py index 20a51161..3aad6427 100644 --- a/src/cpl_query/iterable/__init__.py +++ b/src/cpl_query/iterable/__init__.py @@ -15,7 +15,7 @@ __title__ = "cpl_query.iterable" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2021 - 2023 sh-edraft.de" -__version__ = "2023.4.0.post1" +__version__ = "2023.10.0" from collections import namedtuple @@ -25,4 +25,4 @@ from .iterable_abc import IterableABC from .iterable import Iterable VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="2023", minor="4", micro="0.post1") +version_info = VersionInfo(major="2023", minor="10", micro="0") -- 2.45.2 From 41f974fe6e38fe61722ea4e0f6e8a7ed662de6ca Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 21:06:10 +0200 Subject: [PATCH 7/9] Fixed cpl-discord deps --- src/cpl_discord/cpl-discord.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index 516dfd0f..c9682daf 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -16,9 +16,9 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2023.4.0.post2", + "cpl-core>=2023.10.0", "discord.py>=2.3.0", - "cpl-query>=2023.4.0.post1" + "cpl-query>=2023.10.0" ], "DevDependencies": [ "cpl-cli>=2023.4.0.post3" -- 2.45.2 From 8ede2998fe48f7b9b7624dcc901bdba59ae4de5a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 21:14:49 +0200 Subject: [PATCH 8/9] Fixed configuration typing --- src/cpl_core/configuration/configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpl_core/configuration/configuration.py b/src/cpl_core/configuration/configuration.py index c3627cf5..72fafc2f 100644 --- a/src/cpl_core/configuration/configuration.py +++ b/src/cpl_core/configuration/configuration.py @@ -296,7 +296,7 @@ class Configuration(ConfigurationABC): self.add_configuration(sub, configuration) - def add_configuration(self, key_type: Type[T], value: any): + def add_configuration(self, key_type: T, value: any): self._config[key_type] = value def create_console_argument( -- 2.45.2 From c1b9c0fb4a444188ff3c34075abea7fbcb24c035 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 21:20:36 +0200 Subject: [PATCH 9/9] Added R as return type --- src/cpl_core/configuration/configuration.py | 8 ++++---- src/cpl_core/configuration/configuration_abc.py | 4 ++-- src/cpl_core/dependency_injection/service_collection.py | 6 +++--- .../dependency_injection/service_collection_abc.py | 6 +++--- src/cpl_core/dependency_injection/service_provider.py | 8 ++++---- src/cpl_core/dependency_injection/service_provider_abc.py | 8 ++++---- src/cpl_core/type.py | 1 + 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/cpl_core/configuration/configuration.py b/src/cpl_core/configuration/configuration.py index 72fafc2f..2e3baa0f 100644 --- a/src/cpl_core/configuration/configuration.py +++ b/src/cpl_core/configuration/configuration.py @@ -24,7 +24,7 @@ from cpl_core.dependency_injection.service_provider_abc import ServiceProviderAB from cpl_core.environment.application_environment import ApplicationEnvironment from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_core.environment.environment_name_enum import EnvironmentNameEnum -from cpl_core.type import T +from cpl_core.type import T, R from cpl_core.utils.json_processor import JSONProcessor @@ -316,7 +316,7 @@ class Configuration(ConfigurationABC): for arg in self._argument_types: call(arg) - def get_configuration(self, search_type: T) -> Optional[T]: + def get_configuration(self, search_type: T) -> Optional[R]: if type(search_type) is str: if search_type == ConfigurationVariableNameEnum.environment.value: return self._application_environment.environment_name @@ -357,7 +357,7 @@ class Configuration(ConfigurationABC): if exe.validators is not None: abort = False for validator_type in exe.validators: - validator: ValidatorABC = services.get_service(validator_type) + validator = services.get_service(validator_type) result = validator.validate() abort = not result if abort: @@ -366,7 +366,7 @@ class Configuration(ConfigurationABC): if abort: sys.exit() - cmd: ArgumentExecutableABC = services.get_service(exe.executable_type) + cmd = services.get_service(exe.executable_type) self._handle_pre_or_post_executables(True, exe, services) self._set_variable("ACTIVE_EXECUTABLE", exe.name) args = self.get_configuration("ARGS") diff --git a/src/cpl_core/configuration/configuration_abc.py b/src/cpl_core/configuration/configuration_abc.py index 16beb725..66bf3e35 100644 --- a/src/cpl_core/configuration/configuration_abc.py +++ b/src/cpl_core/configuration/configuration_abc.py @@ -6,7 +6,7 @@ from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.argument_abc import ArgumentABC from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC -from cpl_core.type import T +from cpl_core.type import T, R class ConfigurationABC(ABC): @@ -124,7 +124,7 @@ class ConfigurationABC(ABC): pass @abstractmethod - def get_configuration(self, search_type: T) -> Optional[T]: + def get_configuration(self, search_type: T) -> Optional[R]: r"""Returns value from configuration by given type Parameter: diff --git a/src/cpl_core/dependency_injection/service_collection.py b/src/cpl_core/dependency_injection/service_collection.py index 4f6be8c7..6b505765 100644 --- a/src/cpl_core/dependency_injection/service_collection.py +++ b/src/cpl_core/dependency_injection/service_collection.py @@ -61,15 +61,15 @@ class ServiceCollection(ServiceCollectionABC): self.add_transient(PipeABC, pipe) return self - def add_singleton(self, service_type: Type[T], service: T = None): + def add_singleton(self, service_type: T, service: T = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service) return self - def add_scoped(self, service_type: Type[T], service: Callable = None): + def add_scoped(self, service_type: T, service: T = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.scoped, service) return self - def add_transient(self, service_type: Type[T], service: T = None): + def add_transient(self, service_type: T, service: T = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.transient, service) return self diff --git a/src/cpl_core/dependency_injection/service_collection_abc.py b/src/cpl_core/dependency_injection/service_collection_abc.py index 62c1b5a8..8da9a519 100644 --- a/src/cpl_core/dependency_injection/service_collection_abc.py +++ b/src/cpl_core/dependency_injection/service_collection_abc.py @@ -46,7 +46,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_transient(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": + def add_transient(self, service_type: T, service: T = None) -> "ServiceCollectionABC": r"""Adds a service with transient lifetime Parameter: @@ -61,7 +61,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_scoped(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": + def add_scoped(self, service_type: T, service: T = None) -> "ServiceCollectionABC": r"""Adds a service with scoped lifetime Parameter: @@ -76,7 +76,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_singleton(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": + def add_singleton(self, service_type: T, service: T = None) -> "ServiceCollectionABC": r"""Adds a service with singleton lifetime Parameter: diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index 3b63eaa3..164012ba 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -12,7 +12,7 @@ from cpl_core.dependency_injection.service_descriptor import ServiceDescriptor from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeEnum from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC -from cpl_core.type import T +from cpl_core.type import T, R class ServiceProvider(ServiceProviderABC): @@ -80,7 +80,7 @@ class ServiceProvider(ServiceProviderABC): return implementations - def build_by_signature(self, sig: Signature) -> list[T]: + def build_by_signature(self, sig: Signature) -> list[R]: params = [] for param in sig.parameters.items(): parameter = param[1] @@ -138,7 +138,7 @@ class ServiceProvider(ServiceProviderABC): sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context)) return sb.build() - def get_service(self, service_type: T, *args, **kwargs) -> Optional[T]: + def get_service(self, service_type: T, *args, **kwargs) -> Optional[R]: result = self._find_service(service_type) if result is None: @@ -157,7 +157,7 @@ class ServiceProvider(ServiceProviderABC): return implementation - def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[R]]: implementations = [] if typing.get_origin(service_type) == list: diff --git a/src/cpl_core/dependency_injection/service_provider_abc.py b/src/cpl_core/dependency_injection/service_provider_abc.py index 3af4b5fe..dde58278 100644 --- a/src/cpl_core/dependency_injection/service_provider_abc.py +++ b/src/cpl_core/dependency_injection/service_provider_abc.py @@ -4,7 +4,7 @@ from inspect import Signature, signature from typing import Optional, Type from cpl_core.dependency_injection.scope_abc import ScopeABC -from cpl_core.type import T +from cpl_core.type import T, R class ServiceProviderABC(ABC): @@ -21,7 +21,7 @@ class ServiceProviderABC(ABC): cls._provider = provider @abstractmethod - def build_by_signature(self, sig: Signature) -> list[T]: + def build_by_signature(self, sig: Signature) -> list[R]: pass @abstractmethod @@ -61,7 +61,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_service(self, instance_type: T, *args, **kwargs) -> Optional[T]: + def get_service(self, instance_type: T, *args, **kwargs) -> Optional[R]: r"""Returns instance of given type Parameter @@ -76,7 +76,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[R]]: r"""Returns instance of given type Parameter diff --git a/src/cpl_core/type.py b/src/cpl_core/type.py index b186d5ad..394d5c67 100644 --- a/src/cpl_core/type.py +++ b/src/cpl_core/type.py @@ -1,3 +1,4 @@ from typing import TypeVar T = TypeVar("T") +R = TypeVar("R") -- 2.45.2