Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hot reloading logic in execute_module.py #116

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions mesop/cli/execute_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ def get_app_modules(

submodules: set[str] = set()
for module in loaded_module_names:
module_segments = module.split(".")

# Special case for mesop/example_index.py, which would normally consider
# everything in `mesop` a sub-package/sub-module, however reloading modules
# like runtime causes weird bugs. Thus, we only reload "app" modules and
# not any core framework modules.
module_segments = module.split(".")
if (
module_segments[0] == "mesop"
and not (
if module_segments[0] == "mesop":
if (
module_segments[:2] == ["mesop", "example_index"]
or module_segments[:2] == ["mesop", "examples"]
# Reset labs (b/c io.py needs to re-register stateclass)
or module_segments[:2] == ["mesop", "labs"]
or "e2e" in module_segments
)
):
continue
if (
):
submodules.add(module)
# We also want to hot reload user "app" modules.
elif (
module.split(".")[: len(main_module_prefix_segments)]
== main_module_prefix_segments
):
Expand Down
31 changes: 31 additions & 0 deletions mesop/cli/execute_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ def test_get_app_modules():
)


def test_get_external_app_modules():
assert get_app_modules(
"external_app.app",
loaded_module_names=set(
[
"random",
"numpy",
"pandas",
"external_app.styles",
"external_app.components",
"mesop",
"mesop.runtime",
"mesop.example_index",
"mesop.examples",
"mesop.examples.index",
"mesop.components.radio.radio",
"mesop.components.radio.e2e.radio_app",
]
),
) == set(
[
"external_app.styles",
"external_app.components",
"mesop.example_index",
"mesop.examples",
"mesop.examples.index",
"mesop.components.radio.e2e.radio_app",
]
)


if __name__ == "__main__":
import pytest

Expand Down
Loading