Skip to content

Commit

Permalink
feat: warn user when modules can be loaded twice.
Browse files Browse the repository at this point in the history
Solara by default assumes the name for `solara run <name>` is a
directory. However, when the name is also a package, which imports
module from the package, the package modules can be loaded twice.
Solara will execute the python files in the directory, while Python
will load the python files as modules from the package.
This can leads to unexpected behavior, such as reactive variables
existing twice.
  • Loading branch information
maartenbreddels committed Sep 11, 2023
1 parent 348ab5a commit fe65e7e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions solara/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def add_path():
# resolve the directory, because Path("file").parent.parent == "." != ".."
self.directory = self.path.resolve()
routes = solara.generate_routes_directory(self.path)

if any(name for name in sys.modules.keys() if name.startswith(self.name)):
logger.warn(
f"Directory {self.name} is also used as a package. This can cause modules to be loaded twice, and might "
"cause unexpected behavior. If you run solara from a different directory (e.g. the parent directory) you "
"can avoid this ambiguity."
)

elif self.name.endswith(".py"):
self.type = AppType.SCRIPT
add_path()
Expand Down

0 comments on commit fe65e7e

Please sign in to comment.