From eafc6cb561afaa4b638fdbf075ac8ae6c729df54 Mon Sep 17 00:00:00 2001 From: Titusz Pan Date: Thu, 25 Jan 2024 22:26:54 +0100 Subject: [PATCH] Update api dump script to importlib --- tools/api.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/api.py b/tools/api.py index 018b2bd..8eb6149 100644 --- a/tools/api.py +++ b/tools/api.py @@ -2,7 +2,7 @@ import inspect from pprint import pprint import iscc_core -import imp +import importlib.util import os import ast from os.path import dirname, join @@ -13,14 +13,19 @@ def package_contents(package_name): - file, pathname, description = imp.find_module(package_name) - if file: - raise ImportError("Not a package: %r", package_name) - # Use a set because some may be both source and compiled. + spec = importlib.util.find_spec(package_name) + if spec is None: + raise ImportError("Package not found: %r" % package_name) + + if spec.submodule_search_locations is None: + raise ImportError("Not a package: %r" % package_name) + + package_path = spec.submodule_search_locations[0] + return set( [ - join(PKG_DIR, module) - for module in os.listdir(pathname) + os.path.join(package_path, module) + for module in os.listdir(package_path) if module.endswith(MODULE_EXTENSIONS) ] )