From 94b95f153cc0b6ef1ff15876a4821f15ad4a8dd6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 Mar 2023 13:37:02 +0100 Subject: testwheel.py: Cache the result of pip list Pick-to: master Task-number: PYSIDE-2247 Change-Id: I6460973524f36c4dbfae99fd75a177e43a99a310 Reviewed-by: Adrian Herrmann Reviewed-by: Shyamnath Premnadh --- scripts/packagetesting/testwheel.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/packagetesting/testwheel.py b/scripts/packagetesting/testwheel.py index 9aad708..ba9ca1d 100644 --- a/scripts/packagetesting/testwheel.py +++ b/scripts/packagetesting/testwheel.py @@ -4,6 +4,7 @@ from argparse import ArgumentParser, RawTextHelpFormatter +from functools import cache from pathlib import Path import os import shutil @@ -61,6 +62,23 @@ def list_modules(): print(f"\nInstalled_modules ({len(installed_modules)}): {module_string}\n") +@cache +def get_installed_modules(): + """Return installed modules""" + result = [] + _, lines = run_process([sys.executable, "-m", "pip", "list"]) + for l in lines: + tokens = l.split(' ') + if len(tokens) >= 1: + result.append(tokens[0].lower()) + return result + + +def has_module(name): + """Checks for a module""" + return name.lower() in get_installed_modules() + + def pyside2_examples(): """List of examples to be tested (PYSIDE 2)""" return ['widgets/mainwindows/mdi/mdi.py', @@ -138,16 +156,6 @@ def run_example(root, path): print(f'{path} returned {exit_code}\n\n') -def has_module(name): - """Checks for a module""" - code, lines = run_process([sys.executable, "-m", "pip", "list"]) - for l in lines: - tokens = l.split(' ') - if len(tokens) >= 1 and tokens[0].lower() == name.lower(): - return True - return False - - def test_deploy(example): """Test pyside6-deploy.""" base_name = example.name -- cgit v1.2.1