Document api modules and require explicit imports of API submodules

This commit is contained in:
Dion Moult
2024-05-08 17:00:35 +10:00
parent 984b1212a6
commit 10d30b0de7
34 changed files with 358 additions and 51 deletions
@@ -27,7 +27,6 @@ relationships are all handled automatically.
import json
import numpy
import pkgutil
import inspect
import importlib
import ifcopenshell
@@ -328,50 +327,15 @@ def wrap_usecase(usecase_path, usecase):
return wrapper
# Expose all submodules. This means that the user can just type `import ifcopenshell.api`.
import ifcopenshell.api.aggregate as aggregate
import ifcopenshell.api.attribute as attribute
import ifcopenshell.api.boundary as boundary
import ifcopenshell.api.classification as classification
import ifcopenshell.api.constraint as constraint
import ifcopenshell.api.context as context
import ifcopenshell.api.control as control
import ifcopenshell.api.cost as cost
import ifcopenshell.api.document as document
import ifcopenshell.api.drawing as drawing
import ifcopenshell.api.geometry as geometry
import ifcopenshell.api.georeference as georeference
import ifcopenshell.api.grid as grid
import ifcopenshell.api.group as group
import ifcopenshell.api.layer as layer
import ifcopenshell.api.library as library
import ifcopenshell.api.material as material
import ifcopenshell.api.nest as nest
import ifcopenshell.api.owner as owner
import ifcopenshell.api.profile as profile
import ifcopenshell.api.project as project
import ifcopenshell.api.pset as pset
import ifcopenshell.api.pset_template as pset_template
import ifcopenshell.api.resource as resource
import ifcopenshell.api.root as root
import ifcopenshell.api.sequence as sequence
import ifcopenshell.api.spatial as spatial
import ifcopenshell.api.structural as structural
import ifcopenshell.api.style as style
import ifcopenshell.api.system as system
import ifcopenshell.api.type as type # Whoohoo!
import ifcopenshell.api.unit as unit
import ifcopenshell.api.void as void
def wrap_usecases(path, name):
"""This developer feature wraps an API module's usecases with listeners."""
import sys
import pkgutil
# Wrap all submodule usecases with listeners.
# This for loop also conveniently ensures that the above imports are comprehensive.
for loader, module_name, is_pkg in pkgutil.iter_modules(__path__, __name__ + "."):
# Check if it's a direct child (only one level deep)
if module_name.count(".") == __name__.count(".") + 1:
module_name = module_name.split(".")[-1]
module = globals()[module_name]
for usecase_name in vars(module):
usecase = getattr(module, usecase_name)
if callable(usecase):
usecase_path = f"{module_name}.{usecase_name}"
setattr(module, usecase_name, wrap_usecase(usecase_path, usecase))
module_name = name.split(".")[-1]
module = sys.modules[name]
for loader, usecase_name, is_pkg in pkgutil.iter_modules(path):
usecase = getattr(module, usecase_name)
if callable(usecase):
usecase_path = f"{module_name}.{usecase_name}"
setattr(module, usecase_name, wrap_usecase(usecase_path, usecase))