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

resolve path when registering watcher for module paths #8372

Conversation

zyxue
Copy link
Contributor

@zyxue zyxue commented Mar 25, 2024

Describe your changes

I am developing a streamlit app in Bazel, which creates many symlinks when building a project, e.g.

bazel-bin/projects/myapp/pages/0_Overview.py => foo/projects/myapp/pages/0_Overview.py
bazel-bin/projects/myapp/utils.py => => foo/projects/myapp/utils.py

I usually edit files in foo/ during development, and I found that when updating module file (utils.py), the change is not detected by streamlit and the browser does not refresh, automatically. However, updating the page file (e.g. 0_Overview.py) would lead to auto refresh. Then, after debugging, I think it's due to the inconsistency in resolutions of page and module paths.

Specifically, when streamlit is run and registering watchers, only the paths of page files get resolved (make absolute path and resolve symlink), the relevant code snippets are

for page_info in get_pages(self._main_script_path).values():
self._register_watcher(
page_info["script_path"],
module_name=None, # Only root scripts have their modules set to None
)

"script_path": str(main_script_path.resolve()),

script_path_str = str(script_path.resolve())

However, the module paths don't get resolved

self._register_watcher(path, name)

which explains the inconsistent auto refresh behavior and is what this PR updates. In essence, we only want to watch the change in the resolved paths, the content of the symlink path, which just holds a link to the source file, does not change.

GitHub Issue Link (if applicable)

Testing Plan

manually tested it's working.


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- thanks for the contribution @zyxue!

@vdonato vdonato merged commit a99fc86 into streamlit:develop Mar 26, 2024
43 of 47 checks passed
@zyxue zyxue deleted the resolve-path-when-register-watcher-for-module-paths branch March 26, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants