Skip to content

Commit

Permalink
fix: plotting TypeLoader supports editable install
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Mar 6, 2024
1 parent 0768ab5 commit 3c1812f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/DIRAC/Core/Utilities/ObjectLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def getObjects(self, modulePath, reFilter=None, parentClass=None, recurse=False,

def loadObjects(path, reFilter=None, parentClass=None):
"""
Note: this does not work for editable install because it hardcodes
DIRAC.__file__
It is better to use ObjectLoader().getObjects()
:param str path: the path to the syetem for example: DIRAC/AccountingSystem
:param object reFilter: regular expression used to found the class
:param object parentClass: class instance
Expand All @@ -192,6 +197,7 @@ def loadObjects(path, reFilter=None, parentClass=None):
objDir = os.path.join(os.path.dirname(os.path.dirname(DIRAC.__file__)), parentModule, *pathList)
if not os.path.isdir(objDir):
continue

for objFile in os.listdir(objDir):
if reFilter.match(objFile):
pythonClassName = objFile[:-3]
Expand Down
14 changes: 9 additions & 5 deletions src/DIRAC/Core/Utilities/Plotting/TypeLoader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
""" Utility for loading plotting types.
Works both for Accounting and Monitoring.
"""

import re

from DIRAC.Core.Utilities.ObjectLoader import loadObjects
from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader

from DIRAC.AccountingSystem.Client.Types.BaseAccountingType import BaseAccountingType
from DIRAC.MonitoringSystem.Client.Types.BaseType import BaseType
Expand All @@ -26,18 +27,21 @@ def __init__(self, plottingFamily="Accounting"):
"""c'tor"""
self.__loaded = {}
if plottingFamily == "Accounting":
self.__path = "AccountingSystem/Client/Types"
self.__path = "AccountingSystem.Client.Types"
self.__parentCls = BaseAccountingType
elif plottingFamily == "Monitoring":
self.__path = "MonitoringSystem/Client/Types"
self.__path = "MonitoringSystem.Client.Types"
self.__parentCls = BaseType
self.__reFilter = re.compile(r".*[a-z1-9]\.py$")

########################################################################
def getTypes(self):
"""
It returns all monitoring classes
"""
if not self.__loaded:
self.__loaded = loadObjects(self.__path, self.__reFilter, self.__parentCls)
allObjects = ObjectLoader().getObjects(self.__path, parentClass=self.__parentCls)["Value"]
for _objectModule, objectClass in allObjects.items():
if objectClass.__name__ not in self.__loaded and objectClass != self.__parentCls:
self.__loaded[objectClass.__name__] = objectClass

return self.__loaded

0 comments on commit 3c1812f

Please sign in to comment.