diff options
author | Erik Skultety <eskultet@redhat.com> | 2023-03-09 16:41:39 +0100 |
---|---|---|
committer | Erik Skultety <eskultet@redhat.com> | 2023-03-14 11:16:11 +0100 |
commit | 76747cc52f0761bb65ce67e7b4aed7c399d33713 (patch) | |
tree | 70c28c2cf956ed49ce81d5ecebb5282ba2d92873 | |
parent | 92af40e31a8cb5cd6dbc26263a387ad14a89f9cf (diff) | |
download | libvirt-ci-76747cc52f0761bb65ce67e7b4aed7c399d33713.zip libvirt-ci-76747cc52f0761bb65ce67e7b4aed7c399d33713.tar.gz libvirt-ci-76747cc52f0761bb65ce67e7b4aed7c399d33713.tar.bz2 |
lcitool: Replace pkg_resources with importlib.resources
According to setuptools documentation [1], any new usage of
pkg_resources for package discovery of resources is deprecated in
favour of importlib.resources. This patch follows the recommendation.
[1] https://setuptools.pypa.io/en/latest/pkg_resources.html
[2] https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename
Signed-off-by: Erik Skultety <eskultet@redhat.com>
-rw-r--r-- | lcitool/application.py | 3 | ||||
-rw-r--r-- | lcitool/config.py | 4 | ||||
-rw-r--r-- | lcitool/formatters.py | 8 | ||||
-rw-r--r-- | lcitool/install/install.py | 7 | ||||
-rw-r--r-- | lcitool/util.py | 3 |
5 files changed, 10 insertions, 15 deletions
diff --git a/lcitool/application.py b/lcitool/application.py index e1c55f0..48511b2 100644 --- a/lcitool/application.py +++ b/lcitool/application.py @@ -9,7 +9,6 @@ import sys import textwrap from pathlib import Path -from pkg_resources import resource_filename from tempfile import TemporaryDirectory, NamedTemporaryFile from lcitool import util, LcitoolError @@ -70,7 +69,7 @@ class Application: f"hosts_pattern={hosts_pattern} " f"projects_pattern={projects_pattern} gitrev={git_revision}") - base = resource_filename(__name__, "ansible") + base = util.package_resource(__package__, "ansible").as_posix() config = Config() targets = Targets(data_dir) inventory = Inventory(targets, config) diff --git a/lcitool/config.py b/lcitool/config.py index d42cda8..a4d8e09 100644 --- a/lcitool/config.py +++ b/lcitool/config.py @@ -9,7 +9,6 @@ import logging import yaml from pathlib import Path -from pkg_resources import resource_filename from lcitool import util, LcitoolError @@ -71,7 +70,8 @@ class Config: def _load_config(self): # Load the template config containing the defaults first, this must # always succeed. - default_config_path = resource_filename(__name__, "etc/config.yml") + default_config_path = util.package_resource(__package__, + "etc/config.yml") with open(default_config_path, "r") as fp: default_config = yaml.safe_load(fp) diff --git a/lcitool/formatters.py b/lcitool/formatters.py index 382ea6f..8e53ad6 100644 --- a/lcitool/formatters.py +++ b/lcitool/formatters.py @@ -9,8 +9,6 @@ import json import logging import shlex -from pkg_resources import resource_filename - from lcitool import util, LcitoolError from lcitool.packages import package_names_by_type @@ -66,9 +64,9 @@ class Formatter(metaclass=abc.ABCMeta): pass def _get_meson_cross(self, cross_abi): - cross_name = resource_filename(__name__, - f"cross/{cross_abi}.meson") - with open(cross_name, "r") as c: + cross_path = util.package_resource(__package__, + f"cross/{cross_abi}.meson") + with open(cross_path, "r") as c: return c.read().rstrip() def _generator_build_varmap(self, diff --git a/lcitool/install/install.py b/lcitool/install/install.py index 21d0533..579f0a4 100644 --- a/lcitool/install/install.py +++ b/lcitool/install/install.py @@ -6,7 +6,6 @@ import logging import subprocess from pathlib import Path -from pkg_resources import resource_filename from lcitool import util, LcitoolError from lcitool.config import Config @@ -136,9 +135,9 @@ class VirtInstall: # Unattended install scripts are being generated on the fly, based # on the templates present in lcitool/install/configs/ - filename = resource_filename("lcitool", - f"install/configs/{install_config}") - with open(filename, "r") as template: + cfg_path = util.package_resource(__package__, + f"configs/{install_config}") + with open(cfg_path, "r") as template: content = template.read() for option in unattended_options: content = content.replace( diff --git a/lcitool/util.py b/lcitool/util.py index 0267862..95dd5d2 100644 --- a/lcitool/util.py +++ b/lcitool/util.py @@ -15,7 +15,6 @@ import textwrap import yaml from pathlib import Path -from pkg_resources import resource_filename _tempdir = None @@ -278,7 +277,7 @@ class DataDir: if p.exists(): yield p - p = Path(resource_filename(__name__, resource_path), *names) + p = Path(package_resource(__package__, resource_path), *names) if p.exists(): yield p |