Skip to content

Commit c2144c1

Browse files
authored
Add PluginManager to simplify and centralize plugin type and plugin handling (#3736)
1 parent ecd25ee commit c2144c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+151
-181
lines changed

betty/ancestry/event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ async def linked_data_schema(cls, project: Project, /) -> JsonLdObject:
195195
schema.add_property(
196196
"type",
197197
PluginIdSchema(
198-
EventTypeDefinition.type(), await project.plugins(EventTypeDefinition)
198+
EventTypeDefinition.type(),
199+
await project.plugins.plugins(EventTypeDefinition),
199200
),
200201
)
201202
schema.add_property("eventStatus", String(title="Event status"))

betty/ancestry/file.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ async def linked_data_schema(cls, project: Project, /) -> JsonLdObject:
134134
"copyrightNotice",
135135
PluginIdSchema(
136136
CopyrightNoticeDefinition.type(),
137-
await project.plugins(CopyrightNoticeDefinition),
137+
await project.plugins.plugins(CopyrightNoticeDefinition),
138138
),
139139
False,
140140
)
141141
schema.add_property(
142142
"license",
143143
PluginIdSchema(
144-
LicenseDefinition.type(), await project.plugins(LicenseDefinition)
144+
LicenseDefinition.type(),
145+
await project.plugins.plugins(LicenseDefinition),
145146
),
146147
False,
147148
)

betty/ancestry/person.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async def linked_data_schema(cls, project: Project, /) -> JsonLdObject:
202202
schema.add_property(
203203
"gender",
204204
PluginIdSchema(
205-
GenderDefinition.type(), await project.plugins(GenderDefinition)
205+
GenderDefinition.type(), await project.plugins.plugins(GenderDefinition)
206206
),
207207
False,
208208
)

betty/ancestry/presence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def linked_data_schema(cls, project: Project, /) -> JsonLdObject:
9999
"role",
100100
PluginIdSchema(
101101
PresenceRoleDefinition.type(),
102-
await project.plugins(PresenceRoleDefinition),
102+
await project.plugins.plugins(PresenceRoleDefinition),
103103
),
104104
False,
105105
)

betty/app/__init__.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
from betty.multiprocessing import ProcessPoolExecutor
3434
from betty.plugin import Plugin, PluginDefinition
3535
from betty.plugin.ordered import sort_ordered_plugin_graph
36-
from betty.plugin.repository.provider.service import (
37-
ServiceLevelPluginRepositoryProvider,
38-
)
3936
from betty.portable.file import assert_load_file
4037
from betty.service.container import (
4138
ServiceFactory,
@@ -53,8 +50,6 @@
5350
import aiohttp
5451

5552
from betty.cache import Cache
56-
from betty.machine_name import MachineName
57-
from betty.plugin.repository import PluginRepository
5853
from betty.user import User
5954

6055
_PluginT = TypeVar("_PluginT", bound=Plugin, default=Plugin)
@@ -101,19 +96,12 @@ def __init__(
10196
self,
10297
cache_factory, # ty:ignore[invalid-argument-type]
10398
)
104-
self._plugin_repository_provider = ServiceLevelPluginRepositoryProvider(self)
10599

106100
@override
107101
@classmethod
108102
def configuration_cls(cls) -> type[AppConfiguration]:
109103
return AppConfiguration
110104

111-
@override
112-
async def plugins(
113-
self, plugin_type: type[_PluginDefinitionT] | MachineName, /
114-
) -> PluginRepository[_PluginDefinitionT]:
115-
return await self._plugin_repository_provider.plugins(plugin_type) # ty:ignore[invalid-return-type]
116-
117105
@classmethod
118106
@asynccontextmanager
119107
async def new_from_environment(cls) -> AsyncIterator[Self]:
@@ -220,7 +208,7 @@ async def http_client(self) -> aiohttp.ClientSession:
220208
"""
221209
The HTTP client.
222210
"""
223-
http_rate_limits = await self.plugins(RateLimitDefinition)
211+
http_rate_limits = await self.plugins.plugins(RateLimitDefinition)
224212
rate_limit_sorter = sort_ordered_plugin_graph(
225213
http_rate_limits, http_rate_limits
226214
)

betty/console/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def _create_list_commands_action_class(
160160
app: App, *, localizer: Localizer
161161
) -> type[argparse.Action]:
162162
command_definitions = sorted(
163-
await app.plugins(CommandDefinition),
163+
await app.plugins.plugins(CommandDefinition),
164164
key=lambda command_definition: command_definition.id,
165165
)
166166

@@ -228,7 +228,7 @@ async def _create_parser(app: App) -> argparse.ArgumentParser:
228228
help=localizer._("Show all available commands"),
229229
)
230230
subparsers = parser.add_subparsers(title=localizer._("Subcommands"))
231-
for command_plugin in await app.plugins(CommandDefinition):
231+
for command_plugin in await app.plugins.plugins(CommandDefinition):
232232
await _create_command_parser(app, subparsers, command_plugin, formatter_class)
233233
return parser
234234

betty/console/command/commands/about.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from betty.console.project import add_project_argument
1414
from betty.definition.human_facing import HumanFacingDefinition
1515
from betty.locale.localizable.gettext import _
16-
from betty.plugin import plugin_types
1716
from betty.rich.user import RichUser
17+
from betty.service.level import universe
1818
from betty.service.level.factory import ServiceLevelDependentSelfFactory
1919
from betty.service.requirement.app import require_app
2020

@@ -96,10 +96,10 @@ async def _about_plugins(self, user: RichUser, project: Project | None) -> None:
9696
about_plugins.add_column(user.localizer._("ID"))
9797
about_plugins.add_column(user.localizer._("Label"))
9898
for plugin_type in sorted(
99-
plugin_types,
99+
universe.plugins.types,
100100
key=lambda plugin_type: plugin_type.type().label.localize(user.localizer),
101101
):
102-
repository = await services.plugins(plugin_type)
102+
repository = await services.plugins.plugins(plugin_type)
103103
for index, plugin in enumerate(
104104
sorted(repository, key=lambda plugin: plugin.id)
105105
):

betty/console/command/commands/extension_new_translation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def new_for_services(cls, *, app: App) -> Self:
4242

4343
@override
4444
async def configure(self, parser: argparse.ArgumentParser) -> CommandFunction:
45-
extensions = await self._app.plugins(ExtensionDefinition)
45+
extensions = await self._app.plugins.plugins(ExtensionDefinition)
4646
localizer = await self._app.localizer
4747
parser.add_argument(
4848
"extension",

betty/console/command/commands/extension_update_translations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def new_for_services(cls, *, app: App) -> Self:
4444

4545
@override
4646
async def configure(self, parser: argparse.ArgumentParser) -> CommandFunction:
47-
extensions = await self._app.plugins(ExtensionDefinition)
47+
extensions = await self._app.plugins.plugins(ExtensionDefinition)
4848
localizer = await self._app.localizer
4949

5050
parser.add_argument(

betty/console/project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from betty.project import Project
1919
from betty.project.config import ProjectConfiguration
2020
from betty.serde import SerializerDefinition
21-
from betty.service.level.universal import universe
21+
from betty.service.level import universe
2222
from betty.user import User
2323

2424

@@ -46,7 +46,7 @@ async def add_project_argument(
4646
help=localizer._(
4747
"The path to a Betty project directory or configuration file. Defaults to {default} in the current working directory."
4848
).format(
49-
default=f"betty.{'|'.join(extension[1:] for serializer in await app.plugins(SerializerDefinition) for extension in serializer.cls.media_type().extensions)}"
49+
default=f"betty.{'|'.join(extension[1:] for serializer in await app.plugins.plugins(SerializerDefinition) for extension in serializer.cls.media_type().extensions)}"
5050
),
5151
type=assertion_to_argument_type(assert_path(), localizer=localizer),
5252
)
@@ -82,7 +82,7 @@ async def _read_project_configuration(
8282
if provided_configuration_file_path_str is None:
8383
try_configuration_file_paths = [
8484
project_directory_path / f"betty{extension}"
85-
for serializer in await universe.plugins(SerializerDefinition)
85+
for serializer in await universe.plugins.plugins(SerializerDefinition)
8686
for extension in serializer.cls.media_type().extensions
8787
]
8888
for try_configuration_file_path in try_configuration_file_paths:

0 commit comments

Comments
 (0)