Skip to content

Support cli parameters#186

Merged
dnuske merged 15 commits intostreamlit:developfrom
dnuske:support-cli-parameters
Oct 7, 2019
Merged

Support cli parameters#186
dnuske merged 15 commits intostreamlit:developfrom
dnuske:support-cli-parameters

Conversation

@dnuske
Copy link
Copy Markdown
Contributor

@dnuske dnuske commented Sep 25, 2019

issue: https://github.com/streamlit/streamlit-old-private/issues/670

Brief

Fetches all config options available and exposes them as click cmd option params.

Description

You can do things such as streamlit run --server.port 4031 examples/reference.py now
To see all available options call streamlit run --help.
Screen Shot 2019-09-25 at 6 10 02 PM
👆I don't consider it looks great, I'd prefer it to have a break line after every option, but wasn't able to find a way to format the description for an option in click.

Things that keep this away from being perfect:

  • we can add a nice error when type casting fails (like when sending --server.port "asd")
  • better format to streamlit run --help

Weird behavior

  • something that seems unusual to me is that calling config._set_option only works when the option is not existing in the config file! 🤔

@dnuske dnuske requested review from kantuni, monchier and tvst September 25, 2019 06:25
@dnuske dnuske self-assigned this Sep 25, 2019
@dnuske dnuske removed their assignment Sep 25, 2019
Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

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

Approved, once comments are addressed.

So excited for this to land 💯

def _compose_option_parameter(config_option):
"""
Composes given config option options as options for click lib.
"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fix docstring to match the Numpy docstring style guide.

"""
Decorator that adds config param keys to click dynamically.
"""
for _, value in reversed(_config._config_options.items()):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you need reversed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for some reason the default order gives me the last config item first. I don't know why I just saw it was this way and reversed it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh actually it makes sense now. click probably reverses them internally so the help string appears in the same order as you declare the decorators. The topmost decorator should show up first on the help.

But the topmost decorator is actually the last decorator that is applied. So on our case, we should reverse again to make sure the thing we want to have at the top is applied last.

_main_run(filename)


def _compose_option_parameter(config_option):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think a name like this would be clearer: _convert_config_option_to_click_option

from validators import url

# read through all option configs that are set via cmd option param
# and call set_option to override default/file configs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: capitalize comment.

"""Run a Python script, piping stderr to Streamlit.
The script can be local or it can be an url. In the
latter case, streamlit will download the script to a
temporary file and runs this file.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not your doing, but can you make this docstring extend all the way to the 80-character line?

from validators import url

# read through all option configs that are set via cmd option param
# and call set_option to override default/file configs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't really understand this comment 😕

Can you rephrase? Something like: "The "streamlit run" command supports passing Streamlit's config options as flags. So here we read through all unhandled command-line parameters, massage them, and pass them to _set_config()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"massage them" 😂


# read through all option configs that are set via cmd option param
# and call set_option to override default/file configs
for config_option in kwargs:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you move this whole for-loop into its own helper function? Something like _apply_config_options_from_cli()



@main.command("run")
@configurator_options
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should add this to streamlit hello too.

@dnuske dnuske requested a review from tvst October 4, 2019 15:15
if old_step is None or old_stop is None:
raise AttributeError("'RangeIndex' object has no attribute "
"'step'")
raise AttributeError("'RangeIndex' object has no attribute " "'step'")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The linter messed up here. If it fits within 80 characters, can you join these strings?

Copy link
Copy Markdown
Contributor Author

@dnuske dnuske Oct 7, 2019

Choose a reason for hiding this comment

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

doesn't fit :/

                raise AttributeError("'RangeIndex' object has no attribute "
                                     "'step'")

@dnuske dnuske merged commit 2bbb67a into streamlit:develop Oct 7, 2019
@dnuske dnuske deleted the support-cli-parameters branch October 7, 2019 19:31
tconkling added a commit to tconkling/streamlit that referenced this pull request Oct 7, 2019
* develop:
  Support cli parameters (streamlit#186)
  Update README.md
  Update README.md (streamlit#282)
  Bug fix: make Streamlit watch files in subfolders again (streamlit#265)
  fix st.code("") (streamlit#272)
  different jslint commands for circleci and not (streamlit#273)
  Batch updates to report elements in the App state (streamlit#194)
  Minor typo in pull_request_template.md (streamlit#262)
  Fix wrong quote used in the provided sample code (streamlit#267)
  Fix websocket port handling (streamlit#263)
  Closing sidebar when clicking outside (streamlit#223)
  Version 0.47.2 (streamlit#212)
  [docs] Changed value in Show progress section of docs/getting_started.md to fix error (Issue streamlit#234) (streamlit#235)
  Update README.md
  Remove checkbox from CLA in PR Template
  Update README.md
  Update README.md
  mapping_demo: catch urllib errors (streamlit#224)
sthagen referenced this pull request in sthagen/streamlit-streamlit Oct 8, 2019
tconkling added a commit to tconkling/streamlit that referenced this pull request Oct 8, 2019
* develop:
  Read config from ${CWD}/.streamlit/config.toml (streamlit#227)
  Fix unsafe_allow_html (streamlit#259)
  Support cli parameters (streamlit#186)
  Update README.md
  Update README.md (streamlit#282)
  Bug fix: make Streamlit watch files in subfolders again (streamlit#265)
  fix st.code("") (streamlit#272)
  different jslint commands for circleci and not (streamlit#273)
  Batch updates to report elements in the App state (streamlit#194)
  Minor typo in pull_request_template.md (streamlit#262)
  Fix wrong quote used in the provided sample code (streamlit#267)
  Fix websocket port handling (streamlit#263)
  Closing sidebar when clicking outside (streamlit#223)
  Version 0.47.2 (streamlit#212)
  [docs] Changed value in Show progress section of docs/getting_started.md to fix error (Issue streamlit#234) (streamlit#235)
  Update README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants