fix(deprecated): importlib.resources.read_text() is deprecated

This commit is contained in:
plotski
2023-12-02 18:00:08 +01:00
committed by Rémi Alvergnat
parent e947d1ba3d
commit cd36bad1a4
+16 -4
View File
@@ -7,12 +7,24 @@ import copy
import json
import os
import shlex
import sys
from argparse import ArgumentParser
try:
from importlib.resources import read_text
except ImportError:
from importlib_resources import read_text
# importlib.resources.read_text() is deprecated since Python 3.11.
# importlib.resources.files() is new in Python 3.9.
if sys.version_info >= (3, 9, 0):
from importlib.resources import files
def read_text(package, filename):
"""
Should behave like deprecated importlib.resources.read_text()
"""
return files(package).joinpath(filename).read_text()
else:
try:
from importlib.resources import read_text
except ImportError:
from importlib_resources import read_text
def build_argument_parser():