Skip to content

Commit

Permalink
Update api dump script to importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Jan 25, 2024
1 parent 33f36ff commit eafc6cb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
]
)
Expand Down

0 comments on commit eafc6cb

Please sign in to comment.