Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
76bd1ba
update
tchaton Nov 8, 2022
a753b8a
update
tchaton Nov 8, 2022
147e037
Merge branch 'master' into enable_debug_mode
tchaton Nov 8, 2022
5a8a779
Merge branch 'master' into enable_debug_mode
tchaton Nov 8, 2022
447adc2
update
tchaton Nov 8, 2022
5d9cd51
Merge branch 'enable_debug_mode' of https://github.com/Lightning-AI/l…
tchaton Nov 8, 2022
f63c47d
update
tchaton Nov 8, 2022
a67632c
update
tchaton Nov 8, 2022
50efaaf
update
tchaton Nov 8, 2022
ad64687
update
tchaton Nov 8, 2022
eedd770
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
1ff6571
update
tchaton Nov 9, 2022
6cc05ce
Merge branch 'enable_debug_mode' of https://github.com/Lightning-AI/l…
tchaton Nov 9, 2022
b75524f
update
tchaton Nov 9, 2022
c63307e
update
tchaton Nov 9, 2022
0b2a7d7
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
872bceb
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
9f10b88
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
a2f541f
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
fab998b
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
cbbbeab
update
tchaton Nov 9, 2022
2137290
update
tchaton Nov 9, 2022
ce322bd
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
81de9cf
update
tchaton Nov 9, 2022
6674ba1
update
tchaton Nov 9, 2022
a78db6e
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
ecdec6d
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
53897a7
update
tchaton Nov 9, 2022
ef4edd7
Merge branch 'enable_debug_mode' of https://github.com/Lightning-AI/l…
tchaton Nov 9, 2022
1c4c243
update
tchaton Nov 9, 2022
2b926df
Merge branch 'master' into enable_debug_mode
tchaton Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/app_boring/app_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def configure_layout(self):
return {"name": "Boring Tab", "content": self.dict["dst_w"].url + "/file" if "dst_w" in self.dict else ""}


app = L.LightningApp(BoringApp(), debug=True)
app = L.LightningApp(BoringApp(), log_level="debug")
2 changes: 1 addition & 1 deletion examples/app_commands_and_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def configure_api(self):
]


app = LightningApp(FlowCommands(), debug=True)
app = LightningApp(FlowCommands(), log_level="debug")
2 changes: 1 addition & 1 deletion examples/app_mount/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def run(self):
self.work_1.run()


app = L.LightningApp(Flow(), debug=True)
app = L.LightningApp(Flow(), log_level="debug")
2 changes: 1 addition & 1 deletion examples/app_template_streamlit_ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def configure_layout(self):
return [{"name": "StreamLitUI", "content": self.streamlit_ui}]


app = LightningApp(HelloWorld(), debug=True)
app = LightningApp(HelloWorld(), log_level="debug")
2 changes: 1 addition & 1 deletion examples/app_v0/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def configure_layout(self):
return [tab1, tab2, tab3]


app = L.LightningApp(V0App(), debug=True)
app = L.LightningApp(V0App(), log_level="debug")
2 changes: 1 addition & 1 deletion examples/app_works_on_default_machine/app_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def configure_layout(self):
return [{"name": w.name, "content": w} for i, w in enumerate(self.works())]


app = LightningApp(Flow(), debug=True)
app = LightningApp(Flow(), log_level="debug")
17 changes: 13 additions & 4 deletions src/lightning_app/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from lightning_app.storage import Drive, Path
from lightning_app.storage.path import _storage_root_dir
from lightning_app.utilities import frontend
from lightning_app.utilities.app_helpers import _delta_to_app_state_delta, _LightningAppRef, Logger
from lightning_app.utilities.app_helpers import _delta_to_app_state_delta, _LightningAppRef, debugger_is_active, Logger
from lightning_app.utilities.commands.base import _process_requests
from lightning_app.utilities.component import _convert_paths_after_init, _validate_root_flow
from lightning_app.utilities.enum import AppStage, CacheCallsKeys
Expand All @@ -52,7 +52,7 @@ def __init__(
self,
root: Union["LightningFlow", "LightningWork"],
flow_cloud_compute: Optional["lightning_app.CloudCompute"] = None,
debug: bool = False,
log_level: str = "info",
info: frontend.AppInfo = None,
root_path: str = "",
):
Expand All @@ -70,7 +70,7 @@ def __init__(
root: The root ``LightningFlow`` or ``LightningWork`` component, that defines all the app's nested
components, running infinitely. It must define a `run()` method that the app can call.
flow_cloud_compute: The default Cloud Compute used for flow, Rest API and frontend's.
debug: Whether to activate the Lightning Logger debug mode.
log_level: Whether to activate the Lightning Logger debug mode.
This can be helpful when reporting bugs on Lightning repo.
info: Provide additional info about the app which will be used to update html title,
description and image meta tags and specify any additional tags as list of html strings.
Expand Down Expand Up @@ -150,8 +150,11 @@ def __init__(
# is only available after all Flows and Works have been instantiated.
_convert_paths_after_init(self.root)

if log_level not in ("debug", "info"):
raise Exception(f"Log Level should be in ['debug', 'info']. Found {log_level}")

# Lazily enable debugging.
if debug or DEBUG_ENABLED:
if log_level == "debug" or DEBUG_ENABLED:
if not DEBUG_ENABLED:
os.environ["LIGHTNING_DEBUG"] = "2"
_console.setLevel(logging.DEBUG)
Expand All @@ -162,6 +165,12 @@ def __init__(
# this should happen once for all apps before the ui server starts running.
frontend.update_index_file(FRONTEND_DIR, info=info, root_path=root_path)

if debugger_is_active() and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))):
os.environ["LIGHTNING_DISPATCHED"] = "1"
from lightning_app.runners import MultiProcessRuntime

MultiProcessRuntime(self).dispatch()

def get_component_by_name(self, component_name: str):
"""Returns the instance corresponding to the given component name."""
from lightning_app.structures import Dict as LightningDict
Expand Down
2 changes: 1 addition & 1 deletion src/lightning_app/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def run(self):
def run_work_isolated(work, *args, start_server: bool = False, **kwargs):
"""This function is used to run a work a single time with multiprocessing runtime."""
MultiProcessRuntime(
LightningApp(_SingleWorkFlow(work, args, kwargs), debug=True),
LightningApp(_SingleWorkFlow(work, args, kwargs), log_level="debug"),
start_server=start_server,
).dispatch()
# pop the stopped status.
Expand Down
5 changes: 5 additions & 0 deletions src/lightning_app/utilities/app_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,8 @@ def _load_state_dict(root_flow: "LightningFlow", state: Dict[str, Any], strict:

def is_static_method(klass_or_instance, attr) -> bool:
return isinstance(inspect.getattr_static(klass_or_instance, attr), staticmethod)


def debugger_is_active() -> bool:
"""Return if the debugger is currently active."""
return hasattr(sys, "gettrace") and sys.gettrace() is not None
2 changes: 2 additions & 0 deletions tests/tests_app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"template_react_ui": "https://github.com/Lightning-AI/lightning-template-react.git",
}

os.environ["LIGHTNING_DISPATCHED"] = "1"


def pytest_sessionstart(*_):
"""Pytest hook that get called after the Session object has been created and before performing collection and
Expand Down
10 changes: 5 additions & 5 deletions tests/tests_app/core/test_lightning_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def run(self):
@pytest.mark.parametrize("runtime_cls", [MultiProcessRuntime])
def test_app_state_api(runtime_cls):
"""This test validates the AppState can properly broadcast changes from work within its own process."""
app = LightningApp(_A(), debug=True)
app = LightningApp(_A(), log_level="debug")
runtime_cls(app, start_server=True).dispatch()
assert app.root.work_a.var_a == -1
_set_work_context()
Expand Down Expand Up @@ -110,7 +110,7 @@ def run(self):
@pytest.mark.parametrize("runtime_cls", [SingleProcessRuntime])
def test_app_state_api_with_flows(runtime_cls, tmpdir):
"""This test validates the AppState can properly broadcast changes from flows."""
app = LightningApp(A2(), debug=True)
app = LightningApp(A2(), log_level="debug")
runtime_cls(app, start_server=True).dispatch()
assert app.root.var_a == -1

Expand Down Expand Up @@ -185,7 +185,7 @@ def maybe_apply_changes(self):
def test_app_stage_from_frontend(runtime_cls):
"""This test validates that delta from the `api_delta_queue` manipulating the ['app_state']['stage'] would
start and stop the app."""
app = AppStageTestingApp(FlowA(), debug=True)
app = AppStageTestingApp(FlowA(), log_level="debug")
app.stage = AppStage.BLOCKING
runtime_cls(app, start_server=True).dispatch()

Expand All @@ -197,7 +197,7 @@ def test_update_publish_state_and_maybe_refresh_ui():
- receives a notification to refresh the UI and makes a GET Request (streamlit).
"""

app = AppStageTestingApp(FlowA(), debug=True)
app = AppStageTestingApp(FlowA(), log_level="debug")
publish_state_queue = _MockQueue("publish_state_queue")
api_response_queue = _MockQueue("api_response_queue")

Expand All @@ -224,7 +224,7 @@ class InfiniteQueue(_MockQueue):
def get(self, timeout: int = 0):
return self._queue[0]

app = AppStageTestingApp(FlowA(), debug=True)
app = AppStageTestingApp(FlowA(), log_level="debug")
app._update_layout()
app.stage = AppStage.BLOCKING
publish_state_queue = InfiniteQueue("publish_state_queue")
Expand Down
10 changes: 5 additions & 5 deletions tests/tests_app/core/test_lightning_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def run(self):
@pytest.mark.parametrize("runtime_cls", [SingleProcessRuntime])
def test_simple_app(component_cls, runtime_cls, tmpdir):
comp = component_cls()
app = LightningApp(comp, debug=True)
app = LightningApp(comp, log_level="debug")
assert app.root == comp
expected = {
"app_state": ANY,
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_get_component_by_name_raises():

@pytest.mark.parametrize("runtime_cls", [SingleProcessRuntime, MultiProcessRuntime])
def test_nested_component(runtime_cls):
app = LightningApp(A(), debug=True)
app = LightningApp(A(), log_level="debug")
runtime_cls(app, start_server=False).dispatch()
assert app.root.w_a.c == 1
assert app.root.b.w_b.c == 1
Expand Down Expand Up @@ -361,7 +361,7 @@ def _apply_restarting(self):
@pytest.mark.parametrize("runtime_cls", [SingleProcessRuntime, MultiProcessRuntime])
def test_app_restarting_move_to_blocking(runtime_cls, tmpdir):
"""Validates sending restarting move the app to blocking again."""
app = SimpleApp2(CounterFlow(), debug=True)
app = SimpleApp2(CounterFlow(), log_level="debug")
runtime_cls(app, start_server=False).dispatch()


Expand Down Expand Up @@ -395,7 +395,7 @@ def run_once(self):
@mock.patch("lightning_app.frontend.stream_lit.StreamlitFrontend.stop_server")
def test_app_starts_with_complete_state_copy(_, __):
"""Test that the LightningApp captures the initial state in a separate copy when _run() gets called."""
app = AppWithFrontend(FlowWithFrontend(), debug=True)
app = AppWithFrontend(FlowWithFrontend(), log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()
assert app.run_once_call_count == 3

Expand Down Expand Up @@ -992,7 +992,7 @@ def test_debug_mode_logging():

from lightning_app.core.app import _console

app = LightningApp(A4(), debug=True)
app = LightningApp(A4(), log_level="debug")
assert _console.level == logging.DEBUG
assert os.getenv("LIGHTNING_DEBUG") == "2"

Expand Down
4 changes: 2 additions & 2 deletions tests/tests_app/storage/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def run(self):

def test_multiprocess_path_in_work_and_flow(tmpdir):
root = SourceToDestFlow(tmpdir)
app = LightningApp(root, debug=True)
app = LightningApp(root, log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()


Expand Down Expand Up @@ -551,7 +551,7 @@ def run(self):
def test_path_get_overwrite(tmpdir):
"""Test that .get(overwrite=True) overwrites the entire directory and replaces all files."""
root = OverwriteFolderFlow(tmpdir)
app = LightningApp(root, debug=True)
app = LightningApp(root, log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()


Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app/storage/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run(self):
def test_payload_works(tmpdir):
"""This tests validates the payload api can be used to transfer return values from a work to another."""
with mock.patch("lightning_app.storage.path._storage_root_dir", lambda: pathlib.Path(tmpdir)):
app = LightningApp(Flow(), debug=True)
app = LightningApp(Flow(), log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()

os.remove("value_all")
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app/structures/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,6 @@ def run(self):


def test_structures_with_payload():
app = LightningApp(FlowPayload(), debug=True)
app = LightningApp(FlowPayload(), log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()
os.remove("payload")
2 changes: 1 addition & 1 deletion tests/tests_app/utilities/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __call__(self):

@mock.patch("lightning_app.runners.backends.mp_process.WorkRunner", WorkRunnerPatch)
def test_proxy_timeout():
app = LightningApp(FlowTimeout(), debug=True)
app = LightningApp(FlowTimeout(), log_level="debug")
MultiProcessRuntime(app, start_server=False).dispatch()

call_hash = app.root.work._calls[CacheCallsKeys.LATEST_CALL_HASH]
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app_examples/collect_failures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def run(self):


if __name__ == "__main__":
app = LightningApp(RootFlow(), debug=True)
app = LightningApp(RootFlow(), log_level="debug")
2 changes: 2 additions & 0 deletions tests/tests_app_examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from lightning_app.utilities.packaging.app_config import _APP_CONFIG_FILENAME
from lightning_app.utilities.state import AppState

os.environ["LIGHTNING_DISPATCHED"] = "1"


def pytest_sessionfinish(session, exitstatus):
"""Pytest hook that get called after whole test run finished, right before returning the exit status to the
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app_examples/custom_work_dependencies/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def run(self):
self._exit()


app = LightningApp(CustomWorkBuildConfigChecker(), debug=True)
app = LightningApp(CustomWorkBuildConfigChecker(), log_level="debug")
2 changes: 1 addition & 1 deletion tests/tests_app_examples/idle_timeout/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def run(self):
self._exit()


app = LightningApp(RootFlow(), debug=True)
app = LightningApp(RootFlow(), log_level="debug")