From 4df71fddeb2e454013ab846c98eb8fdf2520bba1 Mon Sep 17 00:00:00 2001 From: David Lai Date: Tue, 27 Jul 2021 02:14:07 +0800 Subject: [PATCH] handling archived lib when scanning rezplugins (#1108) e.g. when working with embedded python --- src/rez/plugin_managers.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rez/plugin_managers.py b/src/rez/plugin_managers.py index 87a52de7f..616edfa13 100644 --- a/src/rez/plugin_managers.py +++ b/src/rez/plugin_managers.py @@ -8,6 +8,7 @@ from rez.utils.logging_ import print_debug, print_warning from rez.vendor.six import six from rez.exceptions import RezPluginError +from zipimport import zipimporter import pkgutil import os.path import sys @@ -302,9 +303,22 @@ def rezplugins_module_paths(self): if not ispkg: continue - module_path = os.path.join(importer.path, name) - if os.path.isdir(os.path.join(module_path, "rezplugins")): - paths.append(module_path) + if isinstance(importer, zipimporter): + init_path = os.path.join(name, "rezplugins", "__init__.pyc") + try: + importer.get_data(init_path) + except (IOError, OSError): + continue + else: + module_path = os.path.join(importer.archive, name) + + else: + module_path = os.path.join(importer.path, name) + init_path = os.path.join(module_path, "rezplugins", "__init__.py") + if not os.path.isfile(init_path): + continue + + paths.append(module_path) return paths