|
5 | 5 | """
|
6 | 6 | Base class for all agent modules
|
7 | 7 | """
|
8 |
| -from __future__ import absolute_import |
9 |
| -from __future__ import division |
10 |
| -from __future__ import print_function |
11 |
| - |
12 |
| -__RCSID__ = "$Id$" |
13 |
| - |
14 | 8 | import os
|
15 | 9 | import threading
|
16 | 10 | import time
|
17 | 11 | import signal
|
| 12 | +import importlib |
| 13 | +import inspect |
18 | 14 |
|
19 | 15 | import DIRAC
|
20 | 16 | from DIRAC import S_OK, S_ERROR, gConfig, gLogger, rootPath
|
|
29 | 25 | from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
|
30 | 26 |
|
31 | 27 |
|
32 |
| -class AgentModule(object): |
| 28 | +class AgentModule: |
33 | 29 | """Base class for all agent modules
|
34 | 30 |
|
35 | 31 | This class is used by the AgentReactor Class to steer the execution of
|
@@ -151,13 +147,20 @@ def __init__(self, agentName, loadName, baseAgentName=False, properties={}):
|
151 | 147 | self.__monitorLastStatsUpdate = -1
|
152 | 148 | self.monitor = None
|
153 | 149 | self.__initializeMonitor()
|
154 |
| - self.__initialized = False |
| 150 | + self.__initialized = False |
155 | 151 |
|
156 | 152 | def __getCodeInfo(self):
|
157 |
| - docVar = "__doc__" |
158 |
| - try: |
| 153 | + |
| 154 | + try: |
| 155 | + self.__codeProperties["version"] = importlib.metadata.version( |
| 156 | + inspect.getmodule(self).__package__.split(".")[0] |
| 157 | + ) |
| 158 | + except Exception: |
| 159 | + self.log.exception(f"Failed to find version for {self!r}") |
| 160 | + self.__codeProperties["version"] = "unset" |
| 161 | + try: |
159 | 162 | self.__agentModule = __import__(self.__class__.__module__, globals(), locals(), "__doc__")
|
160 |
| - except Exception as excp: |
| 163 | + except Exception as excp: |
161 | 164 | self.log.exception("Cannot load agent module", lException=excp)
|
162 | 165 | try:
|
163 | 166 | self.__codeProperties["description"] = getattr(self.__agentModule, "__doc__")
|
|
0 commit comments