Use importlib instead of pkg_resources for ansible conf

Using importlib to read resource strings is said to be much faster
than pkg_resources[1].  See if we see a performance improvement.

Thanks to Clark Boylan for the suggestion.

[1] https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files

Change-Id: I0b7d16d14989918682e137a56da7b0c65b14c336
This commit is contained in:
James E. Blair 2024-03-11 15:36:13 -07:00 committed by Clark Boylan
parent 239a4b9142
commit 341e8d8ccd
1 changed files with 4 additions and 2 deletions

View File

@ -20,8 +20,8 @@ import shutil
import subprocess
import sys
import zuul.ansible
import importlib.resources
from pkg_resources import resource_string
from zuul.lib.config import get_default
@ -160,7 +160,9 @@ class AnsibleManager:
self.default_version = default_version
def load_ansible_config(self):
c = resource_string(__name__, 'ansible-config.conf').decode()
ref = importlib.resources.files('zuul').joinpath(
'lib/ansible-config.conf')
c = ref.read_bytes().decode()
config = configparser.ConfigParser()
config.read_string(c)