Repository navigation
Enhances lazy export to automatically parses absolute external package export, and relative wild export. - #4882
Conversation
Greptile SummaryThis PR refactors the Key changes and observations:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["lazy_export() called"] --> B{packages= arg?}
B -- yes --> C[Emit DeprecationWarning\nadd to fallback_packages]
B -- no --> D{.pyi stub exists?}
C --> D
D -- yes --> E["_parse_stub(stub_file)"]
E --> F["filtered_path\nfallback_packages from\n'from pkg import *'\nrelative_wildcards from\n'from .mod import *'"]
F --> G["lazy.attach_stub()\n→ stub_getattr, stub_dir, __all__"]
G --> H{relative_wildcards?}
H -- yes --> I["eagerly importlib.import_module()\npopulate mod.__dict__ + __all__\n⚠️ no ImportError guard"]
H -- no --> J{fallback_packages?}
I --> J
D -- no --> K["__all__ = []"]
K --> J
J -- yes --> L["define _pkg_getattr / _pkg_dir\nclosures (with try/except)"]
L --> M{has_stub?}
M -- yes --> N["__getattr__ chains\nstub → pkg fallback\n__dir__ merges both"]
M -- no --> O["__getattr__ = _pkg_getattr\n__dir__ = _pkg_dir"]
J -- no --> P{has_stub?}
P -- yes --> Q["__getattr__ = stub_getattr\n__dir__ = stub_dir"]
P -- no --> R["__getattr__ raises AttributeError\n__dir__ returns []"]
N --> S["setattr mod: __getattr__, __dir__, __all__"]
O --> S
Q --> S
R --> S
Last reviewed commit: 71be9fd |
| for rel_mod_name in relative_wildcards: | ||
| fq_name = f"{package_name}.{rel_mod_name}" | ||
| sub = importlib.import_module(fq_name) | ||
| exported = getattr(sub, "__all__", [n for n in dir(sub) if not n.startswith("_")]) | ||
| for name in exported: | ||
| mod.__dict__[name] = getattr(sub, name) | ||
| if name not in __all__: | ||
| __all__.append(name) |
There was a problem hiding this comment.
No error handling for ImportError in eager relative-wildcard loop
relative_wildcards submodules are eagerly imported at lazy_export() call time with no try/except. If any listed submodule fails to import (e.g. an optional dependency is missing, or the submodule itself has an import-time error), this will immediately propagate an unhandled ImportError, causing the caller's import to fail hard.
Contrast this with the _pkg_getattr / _pkg_dir closures further below (lines 148–166), which explicitly continue on ImportError / ModuleNotFoundError. The same defensive treatment should apply here:
for rel_mod_name in relative_wildcards:
fq_name = f"{package_name}.{rel_mod_name}"
try:
sub = importlib.import_module(fq_name)
except (ImportError, ModuleNotFoundError):
continue
exported = getattr(sub, "__all__", [n for n in dir(sub) if not n.startswith("_")])
for name in exported:
mod.__dict__[name] = getattr(sub, name)
if name not in __all__:
__all__.append(name)| if "lazy_export" not in source: | ||
| continue | ||
|
|
||
| tree = ast.parse(source, filename=str(path)) |
There was a problem hiding this comment.
ast.parse called without SyntaxError guard at module level
_find_lazy_export_calls() is executed at module import time (line 57). If any __init__.py in the scanned tree contains a syntax error, ast.parse will raise SyntaxError, which will propagate out of the function and prevent _VIOLATIONS from ever being assigned. This would crash pytest during collection with a confusing NameError / unhandled exception rather than a clean test failure.
| tree = ast.parse(source, filename=str(path)) | |
| try: | |
| tree = ast.parse(source, filename=str(path)) | |
| except SyntaxError: | |
| continue |
| @@ -1,7 +1,7 @@ | |||
| [package] | |||
|
|
|||
| # Note: Semantic Versioning is used: https://semver.org/ | |||
| version = "1.5.1" | |||
| version = "1.5.3" | |||
|
|
|||
| # Description | |||
There was a problem hiding this comment.
Version bump skips 1.5.2
The CHANGELOG.rst on the base branch already documents a 1.5.2 (2026-03-05) release entry, yet extension.toml on the base branch is still at 1.5.1. This PR therefore bumps directly from 1.5.1 → 1.5.3, skipping 1.5.2 entirely. If 1.5.2 was intentionally never published, the CHANGELOG entry should be removed or merged into 1.5.3; otherwise the published package will miss version 1.5.2, which can confuse downstream consumers.
68c3613 to
5fe25cf
Compare
AntoineRichard
left a comment
There was a problem hiding this comment.
I'm really not certain doing things like this is a good idea:
from .rewards import joint_pos_target_l2
from isaaclab.envs.mdp import *In general, we could just import the mdps we want, I don't see why we need a from isaaclab.envs.mdp import * here. It's extra lazy. This code knows perfectly well which term it wants.
|
LGTM |
5fe25cf to
79a97c3
Compare
f407d7b to
38f9e62
Compare
Description
This PR makes lazy export even nicer
Refactored lazy_export() in isaaclab.utils.module to auto-infer fallback packages from absolute wildcard imports (from pkg import *) and eagerly resolve relative wildcard re-exports (from .mod import *) found in .pyi stubs. The packages= argument is deprecated.
Added from isaaclab.envs.mdp import * to all 14 task MDP init.pyi stubs, fixing broken type hints for base MDP symbols (e.g. mdp.time_out, mdp.joint_pos).
Simplified all task MDP init.py files from lazy_export(packages=[...]) to lazy_export().
Created two missing .pyi stubs for isaaclab.devices.openxr.retargeters modules.
Added test_lazy_export_stubs.py — a static analysis test that discovers all lazy_export() call sites and ensures none pass arguments.
Fixes # (issue)
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there