Skip to content

Commit 442e8db

Browse files
committed
Include module version and location in logging
1 parent fd0625e commit 442e8db

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/blueapi/core/context.py

Lines changed: 18 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,35 @@ 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+
if root_pkg := package_map.get(source.module.split(".")[0]):
225+
version = metadata.version(root_pkg[0])
226+
loc = mod.__spec__ and mod.__spec__.origin
227+
summary = f"{root_pkg[0]}[version: {version}, location: {loc}]"
228+
else:
229+
summary = ""
230+
223231
match source:
224232
case PlanSource():
225-
LOGGER.info("Including plans from %s", source.module)
233+
LOGGER.info("Including plans from %s (%s)", source.module, summary)
226234
self.with_plan_module(mod)
227235
case DeviceSource():
228-
LOGGER.info("Including devices from %s", source.module)
236+
LOGGER.info(
237+
"Including devices from %s (%s)", source.module, summary
238+
)
229239
LOGGER.warning(
230240
"'devices' environment kind is deprecated - please convert "
231241
"configuration to use deviceManager"
232242
)
233243
self.with_device_module(mod)
234244
case DodalSource(mock=mock):
235245
LOGGER.info(
236-
"Including devices from 'dodal' source %s", source.module
246+
"Including devices from 'dodal' source %s (%s)",
247+
source.module,
248+
summary,
237249
)
238250
LOGGER.warning(
239251
"'dodal' environment kind is deprecated - please convert "
@@ -242,9 +254,10 @@ def with_config(self, config: EnvironmentConfig) -> None:
242254
self.with_dodal_module(mod, mock=mock)
243255
case DeviceManagerSource(mock=mock, name=name):
244256
LOGGER.info(
245-
"Including devices from 'deviceManager' source %s:%s",
257+
"Including devices from 'deviceManager' source %s:%s (%s)",
246258
source.module,
247259
name,
260+
summary,
248261
)
249262
manager = getattr(mod, name)
250263
if not isinstance(manager, DeviceManager):

0 commit comments

Comments
 (0)