diff --git a/src/DIRAC/Core/Base/Client.py b/src/DIRAC/Core/Base/Client.py index 5fa4e4ba2bb..b3fd1da4e96 100644 --- a/src/DIRAC/Core/Base/Client.py +++ b/src/DIRAC/Core/Base/Client.py @@ -9,6 +9,7 @@ __RCSID__ = "$Id$" import ast +import sys from functools import partial try: @@ -22,7 +23,13 @@ def __get__(self, instance, owner): return partial(self.func, instance, *(self.args or ()), **(self.keywords or {})) -import importlib_resources +from importlib_resources import files + +if sys.version_info.major > 3: + from importlib_resources import as_file # pylint: disable=no-member +else: + from importlib_resources import path as as_file + import six from DIRAC.Core.Tornado.Client.ClientSelector import RPCClientSelector @@ -167,9 +174,8 @@ def addFunctions(clientCls): attrDict = dict(clientCls.__dict__) for extension in extensionsByPriority(): try: - path = importlib_resources.path( - "%s.%sSystem.Service" % (extension, systemName), - "%s.py" % handlerModuleName, + path = as_file( + files("%s.%sSystem.Service" % (extension, systemName)).joinpath("%s.py" % handlerModuleName) ) fullHandlerClassPath = "%s.%s" % (extension, handlerClassPath) with path as fp: diff --git a/src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py b/src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py index 809b33f119e..17011d2f854 100644 --- a/src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py +++ b/src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py @@ -8,6 +8,7 @@ from __future__ import print_function import datetime +import sys from pylab import setp from matplotlib.colors import Normalize import matplotlib.cm as cm @@ -181,7 +182,10 @@ def draw(self): cb = ColorbarBase( cax, cmap=self.cmap, norm=self.norms, boundaries=self.cbBoundaries, values=self.cbValues, ticks=self.cbTicks ) - cb.draw_all() + if sys.version_info.major < 3: + cb.draw_all() # pylint: disable=no-member + else: + self.figure.draw_without_rendering() # cb = self.ax.colorbar( self.mapper, format="%d%%", # orientation='horizontal', fraction=0.04, pad=0.1, aspect=40 ) # setp( cb.outline, linewidth=.5 ) diff --git a/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py b/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py index 4208aa35140..83542596521 100644 --- a/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py +++ b/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py @@ -72,10 +72,11 @@ import re import shutil import stat +import sys import time from collections import defaultdict +from importlib_resources import files -import importlib_resources import six import subprocess32 as subprocess from diraccfg import CFG @@ -845,7 +846,7 @@ def getComponentCfg( for ext in extensions: cfgTemplateModule = "%s.%sSystem" % (ext, system) try: - cfgTemplate = importlib_resources.read_text(cfgTemplateModule, "ConfigTemplate.cfg") + cfgTemplate = files(cfgTemplateModule).joinpath("ConfigTemplate.cfg").read_text(encoding="utf-8") except (ImportError, OSError): continue gLogger.notice("Loading configuration template from", cfgTemplateModule) @@ -2195,7 +2196,7 @@ def installDatabase(self, dbName): systemName = databases[filename] moduleName = ".".join([extension, systemName, "DB"]) gLogger.debug("Installing %s from %s" % (filename, moduleName)) - dbSql = importlib_resources.read_text(moduleName, filename) + dbSql = files(moduleName).joinpath(filename).read_text(encoding="utf-8") # just check result = self.execMySQL("SHOW STATUS") @@ -2295,7 +2296,7 @@ def _createMySQLCMDLines(self, dbSql): sourcedDBbFileName = line.split(" ")[1].replace("\n", "") gLogger.info("Found file to source: %s" % sourcedDBbFileName) module, filename = sourcedDBbFileName.rsplit("/", 1) - dbSourced = importlib_resources.read_text(module.replace("/", "."), filename) + dbSourced = files(module.replace("/", ".")).joinpath(filename).read_text(encoding="utf-8") for lineSourced in dbSourced.split("\n"): if lineSourced.strip(): cmdLines.append(lineSourced.strip())