Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Jan 13, 2025

Describe your changes

Adds support for loading secret and config files relative to the main script.

E.g. if you run streamlit run my_app/app.py, it will load config & secret toml files in the following order:

  1. in the user directory: ~/.streamlit/config.toml
  2. relative to the working directory: ./my_project/.streamlit/config.toml
  3. relative to the script file: ./my_project/my_app/.streamlit/config.toml

GitHub Issue Link (if applicable)

Testing Plan

  • Updated unit tests.
  • Added e2e test.

Contribution License Agreement

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

@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jan 13, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented Apr 29, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-10173/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-10173.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot May 19, 2025 16:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for per-script .streamlit config and secret files by tracking the main script path and extending the file lookup and watcher logic.

  • Pass the main script path into the config system and include script-level files in both loading and file watchers.
  • Introduce get_main_script_streamlit_file_path to build paths under a script’s .streamlit folder.
  • Replace the static CONFIG_FILENAMES list with a dynamic get_config_files() and update the secrets/files option to be dynamic and multi-valued.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
lib/streamlit/web/bootstrap.py Set config._main_script_path and use get_config_files() in installers
lib/streamlit/file_util.py Add get_main_script_streamlit_file_path helper
lib/streamlit/config_option.py Add explicit multiple parameter to ConfigOption
lib/streamlit/config.py Introduce _main_script_path, get_config_files(), and refactor secrets.files
Comments suppressed due to low confidence (3)

lib/streamlit/file_util.py:164

  • This function uses the os module but there’s no import shown; ensure import os is present at the top to avoid a NameError.
Path(os.path.abspath(os.path.dirname(main_script_path)))

lib/streamlit/config_option.py:188

  • Auto-inference of multiple based on default_val was removed, so any list-typed options without multiple=True will now be single-valued; audit existing list defaults to ensure they pass multiple=True where needed.
self.multiple = multiple

lib/streamlit/config.py:1283

  • There’s a stray triple-quote here outside of a docstring or comment block, which could lead to a syntax error; verify that the _secrets_files docstring is properly closed.
"""

@sfc-gh-lmasuch sfc-gh-lmasuch changed the title [Prototype] Add support for config & secret files on main-script level [WIP] Add support for config & secret files on main-script level May 27, 2025
@lukasmasuch lukasmasuch changed the title [WIP] Add support for config & secret files on main-script level Add support for config & secret files on main-script level May 27, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review May 27, 2025 15:51
@lukasmasuch lukasmasuch requested a review from Copilot May 27, 2025 15:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for loading configuration and secret TOML files relative to the main script, and it updates the file resolution order for config and secret files. Key changes include:

  • Updating CLI execution paths and patch targets in tests to use the new bootstrap/run and check_credentials functions.
  • Introducing helper functions (e.g. get_main_script_streamlit_file_path) and a module-level main script path to resolve file locations correctly.
  • Changing ConfigOption’s handling of multiple values by requiring an explicit flag rather than inferring from the default value.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/tests/streamlit/web/cli_test.py Updated patches to align tests with new bootstrap and check_credentials calls.
lib/tests/streamlit/config_test.py Added explicit multiple=True flag in tests for config options.
lib/streamlit/web/cli.py Refactored main_run and main_hello to centralize config loading in _main_run.
lib/streamlit/web/bootstrap.py Replaced CONFIG_FILENAMES with a call to get_config_files and updated sys path logic.
lib/streamlit/file_util.py Added a new helper to resolve .streamlit paths relative to the main script.
lib/streamlit/config_option.py Modified multiple-values handling by using an explicit parameter.
lib/streamlit/config.py Added _main_script_path, refactored secrets and config file loading logic.
e2e_playwright/config/* Added end-to-end tests to ensure script-level config and secret file support.

@lukasmasuch lukasmasuch enabled auto-merge (squash) June 5, 2025 00:34
@lukasmasuch lukasmasuch merged commit b9bcddd into develop Jun 5, 2025
36 checks passed
@lukasmasuch lukasmasuch deleted the prototype/main-script-config-files branch June 5, 2025 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan for config.toml file relative to main app file before defaulting to working directory

4 participants