Skip to content

Commit 3bfa513

Browse files
committed
Include module version and location in logging
1 parent fd0625e commit 3bfa513

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/blueapi/core/context.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from collections.abc import Callable
44
from dataclasses import InitVar, dataclass, field, fields, is_dataclass
5-
from importlib import import_module
5+
from importlib import import_module, metadata
66
from inspect import Parameter, isclass, signature
77
from types import ModuleType, NoneType, UnionType
88
from typing import Any, Generic, TypeVar, Union, get_args, get_origin, get_type_hints
@@ -217,23 +217,33 @@ def find_device(self, addr: str | list[str]) -> Device | None:
217217
def with_config(self, config: EnvironmentConfig) -> None:
218218
if config.metadata is not None:
219219
self.run_engine.md |= config.metadata.model_dump()
220+
package_map = metadata.packages_distributions()
220221
for source in config.sources:
221222
mod = import_module(source.module)
222223

224+
root_pkg = package_map[source.module.split(".")[0]][0]
225+
version = metadata.version(root_pkg)
226+
loc = mod.__spec__ and mod.__spec__.origin
227+
summary = f"{root_pkg}[version: {version}, location: {loc}]"
228+
223229
match source:
224230
case PlanSource():
225-
LOGGER.info("Including plans from %s", source.module)
231+
LOGGER.info("Including plans from %s (%s)", source.module, summary)
226232
self.with_plan_module(mod)
227233
case DeviceSource():
228-
LOGGER.info("Including devices from %s", source.module)
234+
LOGGER.info(
235+
"Including devices from %s (%s)", source.module, summary
236+
)
229237
LOGGER.warning(
230238
"'devices' environment kind is deprecated - please convert "
231239
"configuration to use deviceManager"
232240
)
233241
self.with_device_module(mod)
234242
case DodalSource(mock=mock):
235243
LOGGER.info(
236-
"Including devices from 'dodal' source %s", source.module
244+
"Including devices from 'dodal' source %s (%s)",
245+
source.module,
246+
summary,
237247
)
238248
LOGGER.warning(
239249
"'dodal' environment kind is deprecated - please convert "
@@ -242,9 +252,10 @@ def with_config(self, config: EnvironmentConfig) -> None:
242252
self.with_dodal_module(mod, mock=mock)
243253
case DeviceManagerSource(mock=mock, name=name):
244254
LOGGER.info(
245-
"Including devices from 'deviceManager' source %s:%s",
255+
"Including devices from 'deviceManager' source %s:%s (%s)",
246256
source.module,
247257
name,
258+
summary,
248259
)
249260
manager = getattr(mod, name)
250261
if not isinstance(manager, DeviceManager):

0 commit comments

Comments
 (0)