Reverb commited on
Commit
313ffe0
·
1 Parent(s): 85d4c34

Fix: make trellis2/__init__.py fully lazy to survive partial-module namespace

Browse files

The installed TRELLIS.2 wheels (o_voxel/flex_gemm) register a 'trellis2'
namespace in sys.modules before app.py runs, leaving it partially initialized.
The original eager 'from . import models' then fails because 'models' isn't
an attribute yet on the partial stub.

Replace the eager submodule imports with a lazy __getattr__ (the same pattern
used by all trellis2 submodule __init__.py files). All external access patterns
(from trellis2.pipelines import X, trellis2.modules.sparse.SparseTensor) still
work — Python's import machinery resolves absolute submodule paths independently
of the parent package's __init__.

Files changed (1) hide show
  1. TRELLIS.2/trellis2/__init__.py +16 -6
TRELLIS.2/trellis2/__init__.py CHANGED
@@ -1,6 +1,16 @@
1
- from . import models
2
- from . import modules
3
- from . import pipelines
4
- from . import renderers
5
- from . import representations
6
- from . import utils
 
 
 
 
 
 
 
 
 
 
 
1
+ import importlib
2
+
3
+ # Lazy-load all submodules to avoid circular-import errors when trellis2 is
4
+ # first imported from an environment where a partial trellis2 namespace already
5
+ # exists in sys.modules (e.g. registered as a dependency by o_voxel/flex_gemm).
6
+ _submodules = frozenset((
7
+ 'models', 'modules', 'pipelines',
8
+ 'renderers', 'representations', 'utils',
9
+ ))
10
+
11
+ def __getattr__(name):
12
+ if name in _submodules:
13
+ module = importlib.import_module(f'.{name}', __name__)
14
+ globals()[name] = module
15
+ return module
16
+ raise AttributeError(f"module 'trellis2' has no attribute {name!r}")