From 341e8d8ccd3354655f7ae83938361a985639a7cd Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 11 Mar 2024 15:36:13 -0700 Subject: [PATCH] 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 --- zuul/lib/ansible.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zuul/lib/ansible.py b/zuul/lib/ansible.py index 9d104cfe42..c5b6d9d88d 100644 --- a/zuul/lib/ansible.py +++ b/zuul/lib/ansible.py @@ -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)