Skip to content

Conversation

@nthmost
Copy link
Contributor

@nthmost nthmost commented Nov 15, 2019

Issue: #163

Description:

This branch addresses a bug that highlighted a more general issue in the code, which is that most options created in config.py can't be productively set by the user in a script during streamlit run script.py.

Right now, since these options cannot reach the machinery of Streamlit that would change the behavior desired by the user, they are silently failing or causing unexpected problems when used inside of a user script.

The better behavior would be to raise an exception with an explanation for all options set in a script that are "unscriptable".

This PR adds a scriptable attribute to the ConfigOption class, which allows each option to configure its own "scriptability" with the _create_option function.

The scriptable flag is then checked at runtime during st.set_option, failing the script (if False) with StreamlitAPIException and a useful message about how to set the option properly.


Contribution License Agreement

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

@nthmost nthmost requested a review from a team as a code owner November 15, 2019 23:15
@nthmost nthmost added the type:enhancement Requests for feature enhancements or new features label Nov 16, 2019
@nthmost nthmost changed the title Add ConfigOption attribute "scriptable" and set some options to scriptable=True Add ConfigOption attribute "scriptable" w/ some only options scriptable=True Nov 16, 2019
@nthmost nthmost changed the title Add ConfigOption attribute "scriptable" w/ some only options scriptable=True Add ConfigOption attribute "scriptable" w/ only some options scriptable=True Nov 16, 2019
@nthmost nthmost requested a review from monchier November 18, 2019 22:53
Copy link
Collaborator

@monchier monchier left a comment

Choose a reason for hiding this comment

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

Few minor comments. Looks good to me!

visibility : {'visible', 'hidden', 'obfuscated'}
See __init__.
scriptable : bool
See __init__.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we say what scriptable means as part of the doc at this level?

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm, I see we document this below.

Comment on lines +64 to +70
"""Test that scriptable options can be set from API."""
# This is set in lib/tests/conftest.py to off
self.assertEqual("off", st.get_option("global.sharingMode"))
self.assertEqual(True, st.get_option("client.displayEnabled"))

st.set_option("global.sharingMode", "s3")
self.assertEqual("s3", st.get_option("global.sharingMode"))
# client.displayEnabled and client.caching can be set after run starts.
st.set_option("client.displayEnabled", False)
self.assertEqual(False, st.get_option("client.displayEnabled"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, this tests is about scriptable but requires that some specific options are "scriptable" and others are not. The test may break if we change these options or just we change just their name. In my mind, it would be nice to create a fake "scriptable" and a non "scriptable" option and testing the fakes, but not sure if it is easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point!

@nthmost nthmost merged commit 89ff0a8 into streamlit:develop Nov 19, 2019
@nthmost nthmost deleted the server_enableCORS_set_option_fix_163 branch November 19, 2019 18:25
tconkling added a commit to tconkling/streamlit that referenced this pull request Nov 19, 2019
* develop:
  fixed misspell (streamlit#712)
  Add ConfigOption attribute "scriptable" w/ only some options scriptable=True (streamlit#702)
  Fixing Tornado on Windows + Python 3.8 (streamlit#682)
  Moving reportId and metadata from Element to ReportElement (streamlit#529)
  Fall back on webbrowser if xdg-open is not installed on Linux (streamlit#701)

# Conflicts:
#	e2e/scripts/multiselect.py
tconkling added a commit to tconkling/streamlit that referenced this pull request Nov 19, 2019
* develop: (31 commits)
  fixed misspell (streamlit#712)
  Add ConfigOption attribute "scriptable" w/ only some options scriptable=True (streamlit#702)
  Fixing Tornado on Windows + Python 3.8 (streamlit#682)
  Moving reportId and metadata from Element to ReportElement (streamlit#529)
  Fall back on webbrowser if xdg-open is not installed on Linux (streamlit#701)
  Dockerfile: ensure we install the NODE_VERSION we reference elsewhere (streamlit#639)
  Datepicker pop-up aligned on left (streamlit#676)
  Fixing number input spin buttons for Firefox (streamlit#683)
  Fixing makeElementWithInfoText (streamlit#692)
  Fixing CTRL+ENTER on Windows (streamlit#699)
  Add option to use PollingFileWatcher, even if watchdog is available (streamlit#626)
  Break util.py into several util files (streamlit#703)
  Do not automatically create credential file when in headless mode (streamlit#467) (streamlit#603)
  make __future__ import be the first line (streamlit#687)
  Split text protos (streamlit#506)
  pandas.isna was introduced in version 0.21.0 (streamlit#679)
  Prefix get_report_ctx with underscore in __init__ and import it correctly in (streamlit#669)
  Fix single word in changelog (streamlit#672)
  Move some functions from util.py into type_util.py (streamlit#670)
  Release 0.50.2 (streamlit#666)
  ...
tconkling added a commit to tconkling/streamlit that referenced this pull request Nov 19, 2019
* develop: (38 commits)
  Add viz.js to the repo (streamlit#635)
  fixed misspell (streamlit#712)
  Add ConfigOption attribute "scriptable" w/ only some options scriptable=True (streamlit#702)
  Fixing Tornado on Windows + Python 3.8 (streamlit#682)
  Moving reportId and metadata from Element to ReportElement (streamlit#529)
  Fall back on webbrowser if xdg-open is not installed on Linux (streamlit#701)
  Dockerfile: ensure we install the NODE_VERSION we reference elsewhere (streamlit#639)
  Datepicker pop-up aligned on left (streamlit#676)
  Fixing number input spin buttons for Firefox (streamlit#683)
  Fixing makeElementWithInfoText (streamlit#692)
  Fixing CTRL+ENTER on Windows (streamlit#699)
  Add option to use PollingFileWatcher, even if watchdog is available (streamlit#626)
  Break util.py into several util files (streamlit#703)
  Do not automatically create credential file when in headless mode (streamlit#467) (streamlit#603)
  make __future__ import be the first line (streamlit#687)
  Split text protos (streamlit#506)
  pandas.isna was introduced in version 0.21.0 (streamlit#679)
  Prefix get_report_ctx with underscore in __init__ and import it correctly in (streamlit#669)
  Fix single word in changelog (streamlit#672)
  Move some functions from util.py into type_util.py (streamlit#670)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement Requests for feature enhancements or new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants