From 0eaa7de6a7b4754638640e5caaec0de9832e4dbb Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 18 May 2022 12:51:01 +0100 Subject: [PATCH] strutils: Defer import of pyparsing This is a slow import and the single user of it, the 'split_by_commas' helper, does not appear to have any users outside of python-glareclient (which is a dead project). We might want to remove the user at some point, but for now simply defer loading of the library. Change-Id: I91d0c6eec5333a660f995a9d1436e4b068693900 Signed-off-by: Stephen Finucane --- oslo_utils/strutils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/oslo_utils/strutils.py b/oslo_utils/strutils.py index 0bb9fc56..ae5cfc05 100644 --- a/oslo_utils/strutils.py +++ b/oslo_utils/strutils.py @@ -23,8 +23,6 @@ import re import unicodedata import urllib -import pyparsing as pp - from oslo_utils._i18n import _ from oslo_utils import encodeutils @@ -577,8 +575,13 @@ def split_by_commas(value): .. versionadded:: 3.17 """ - word = (pp.QuotedString(quoteChar='"', escChar='\\') | - pp.Word(pp.printables, excludeChars='",')) + # pyparsing is a slow import; defer loading until we need it + import pyparsing as pp + + word = ( + pp.QuotedString(quoteChar='"', escChar='\\') | + pp.Word(pp.printables, excludeChars='",') + ) grammar = pp.stringStart + pp.delimitedList(word) + pp.stringEnd try: