Skip to content

Commit 53b0328

Browse files
committed
getenv
1 parent 2d466e2 commit 53b0328

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/lightning_utilities/core/imports.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ def get_dependency_min_version_spec(package_name: str, dependency_name: str) ->
137137
)
138138

139139

140-
def requires(*module_path: str) -> Callable:
140+
def requires(*module_path: str, raise_exception: bool = True) -> Callable:
141141
"""Wrapper for early import failure with some nice exception message.
142142
143143
Example:
144144
145-
>>> @requires("libpath")
145+
>>> @requires("libpath", raise_exception=bool(int(os.getenv("LIGHTING_TESTING", "0"))))
146146
... def my_cwd():
147147
... from pathlib import Path
148148
... return Path(__file__).parent
@@ -162,12 +162,11 @@ def decorator(func: Callable) -> Callable:
162162
def wrapper(*args: Any, **kwargs: Any) -> Any:
163163
unavailable_modules = [module for module in module_path if not module_available(module)]
164164
if any(unavailable_modules):
165-
is_lit_testing = bool(int(os.getenv("LIGHTING_TESTING", "0")))
166165
msg = f"Required dependencies not available. Please run `pip install {' '.join(unavailable_modules)}`"
167-
if is_lit_testing:
168-
warnings.warn(msg)
169-
else:
166+
if raise_exception:
170167
raise ModuleNotFoundError(msg)
168+
else:
169+
warnings.warn(msg)
171170
return func(*args, **kwargs)
172171

173172
return wrapper

0 commit comments

Comments
 (0)