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

Add Custom File Path to Watcher which is outside the path of the main script #9655

Open
2 tasks done
akramsystems opened this issue Oct 12, 2024 · 3 comments
Open
2 tasks done
Labels
feature:config Related to config settings type:enhancement Requests for feature enhancements or new features

Comments

@akramsystems
Copy link

akramsystems commented Oct 12, 2024

PR open: #9655

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

Add a feature to allow watching a custom path in Streamlit, enabling the application to monitor all files within that directory and its subdirectories. Currently, Streamlit supports a blacklist for excluding paths but lacks an option to specify a custom path to be watched in full.

Example Scenario:

/home/user/
├── streamlit_project/
│   ├── main_app.py
│   ├── data/
│   │   └── local_data.csv
└── shared_data/
    └── external_data.csv

Why?

The current system only supports watching the directory of the main streamlit script or excluding certain files via a blacklist. In cases where projects have structured directories or additional assets in specific folders, it is important to have the flexibility to define custom paths for Streamlit to watch, ensuring that all relevant files are reloaded as needed. This would improve developer experience by allowing greater control over what Streamlit monitors for changes, preventing unnecessary reloads and improving workflow.

How?

The implementation introduces a new configuration option, server.customWatchPath, which allows users to specify a custom path for Streamlit to monitor. This path will be recursively watched for changes to any files within it. The main changes in this implementation are:

  1. Configurable Option: A new option, server.customWatchPath, is added in the config.py file. This allows users to define a custom directory for file watching through Streamlit's configuration system.

  2. Runtime and Path Watching: The runtime has been updated to store the custom_watch_path in the RuntimeConfig. The path watcher (EventBasedPathWatcher) has been extended to accept this custom path and watch it recursively for any file changes. If a custom watch path is provided, the watcher registers it and logs relevant debug information about the additional path being watched.

  3. Recursive Directory Watching: In local_sources_watcher.py, the _register_watcher method has been updated to handle directory watching, ensuring that all files within the custom path are monitored for changes. If the custom path is valid, it will be registered with the path watcher, and any file changes within the directory will trigger a file change event.

These changes allow for a flexible approach where users can monitor any directory, ensuring that all necessary files are captured without relying solely on the default Streamlit watch settings.

Additional Context

You can find other users expressing a similar needs in the streamlit discussion threads below:

Note:

Streamlit offers the ability to allow users to watch modules in the PYTHONPATH as seen in #845 , but this method requires modifying the PYTHONPATH, which some users may find undesirable. Allowing a custom path to be specified provides a more flexible solution without requiring any changes to the PYTHONPATH, ensuring a smoother experience for users who may have structured directories outside of the default Python paths.

@akramsystems akramsystems added the type:enhancement Requests for feature enhancements or new features label Oct 12, 2024
Copy link

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

@AliTranscrypts
Copy link

Awesome feature addition! Exactly what our company is looking for as we prototype.

@jrieke jrieke added the feature:config Related to config settings label Oct 14, 2024
@akramsystems
Copy link
Author

@jrieke i have a PR open here #9656 let me know if there is anything i can do to help with, in terms of either prioritizing this ticket or working on the PR, I appreciate you adding the tag keep up the amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:config Related to config settings type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

3 participants