Skip to content

Commit 5307ef6

Browse files
committed
Make plugin status readonly
1 parent 7b2fb4c commit 5307ef6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

trinity/extensibility/plugin.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def trinity_config(self) -> TrinityConfig:
127127
class BasePlugin(ABC):
128128

129129
context: PluginContext = None
130-
status: PluginStatus = PluginStatus.NOT_READY
130+
131+
_status: PluginStatus = PluginStatus.NOT_READY
131132

132133
@property
133134
@abstractmethod
@@ -160,7 +161,14 @@ def running(self) -> bool:
160161
"""
161162
Return ``True`` if the ``status`` is ``PluginStatus.STARTED``, otherwise return ``False``.
162163
"""
163-
return self.status is PluginStatus.STARTED
164+
return self._status is PluginStatus.STARTED
165+
166+
@property
167+
def status(self) -> PluginStatus:
168+
"""
169+
Return the current :class:`~trinity.extensibility.plugin.PluginStatus` of the plugin.
170+
"""
171+
return self._status
164172

165173
def set_context(self, context: PluginContext) -> None:
166174
"""
@@ -173,7 +181,7 @@ def ready(self) -> None:
173181
Set the ``status`` to ``PluginStatus.READY`` and delegate to
174182
:meth:`~trinity.extensibility.plugin.BasePlugin.on_ready`
175183
"""
176-
self.status = PluginStatus.READY
184+
self._status = PluginStatus.READY
177185
self.on_ready()
178186

179187
def on_ready(self) -> None:
@@ -198,12 +206,12 @@ def start(self) -> None:
198206
:class:`~lahja.eventbus.EventBus` and hence allow other plugins to act accordingly.
199207
"""
200208

201-
if self.status in INVALID_START_STATUS:
209+
if self._status in INVALID_START_STATUS:
202210
raise InvalidPluginStatus(
203211
f"Can not start plugin when the plugin status is {self.status}"
204212
)
205213

206-
self.status = PluginStatus.STARTED
214+
self._status = PluginStatus.STARTED
207215
self.do_start()
208216
self.event_bus.broadcast(
209217
PluginStartedEvent(type(self))
@@ -238,7 +246,7 @@ def stop(self) -> None:
238246
plugin to stop and setting ``running`` to ``False``.
239247
"""
240248
self.do_stop()
241-
self.status = PluginStatus.STOPPED
249+
self._status = PluginStatus.STOPPED
242250

243251

244252
class BaseAsyncStopPlugin(BasePlugin):
@@ -259,7 +267,7 @@ async def stop(self) -> None:
259267
plugin to stop asynchronously and setting ``running`` to ``False``.
260268
"""
261269
await self.do_stop()
262-
self.status = PluginStatus.STOPPED
270+
self._status = PluginStatus.STOPPED
263271

264272

265273
class BaseMainProcessPlugin(BasePlugin):
@@ -288,7 +296,7 @@ def start(self) -> None:
288296
"""
289297
Prepare the plugin to get started and eventually call ``do_start`` in a separate process.
290298
"""
291-
self.status = PluginStatus.STARTED
299+
self._status = PluginStatus.STARTED
292300
self._process = ctx.Process(
293301
target=self._prepare_start,
294302
)

0 commit comments

Comments
 (0)