Skip to content

Reapply on_config_parsed after applying cli args#1448

Merged
karriebear merged 7 commits intostreamlit:developfrom
karriebear:bug/1321-setting-logLevel
May 27, 2020
Merged

Reapply on_config_parsed after applying cli args#1448
karriebear merged 7 commits intostreamlit:developfrom
karriebear:bug/1321-setting-logLevel

Conversation

@karriebear
Copy link
Copy Markdown
Contributor

@karriebear karriebear commented May 13, 2020

Issue: Fixes #1321

Description: set_log_level runs once on_config_parsed is emitted. This can get triggered before the CLI arguments are parsed. Following changes to address this:

  • Before applying the CLI arguments, parse the config file if it has not already been parsed.
  • After applying the CLI arguments, emit on_config_parsed.
  • Update on_config_parsed with a flag to forcefully connect the callback with the signal. Currently a shortcut exists to bypass connecting to the signal.

Contribution License Agreement

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

@karriebear karriebear force-pushed the bug/1321-setting-logLevel branch from 5a97215 to bf520e4 Compare May 13, 2020 16:08
@karriebear karriebear force-pushed the bug/1321-setting-logLevel branch 3 times, most recently from ac854bd to 9f693e9 Compare May 13, 2020 19:23
@karriebear karriebear marked this pull request as ready for review May 13, 2020 19:29
@karriebear karriebear requested a review from a team as a code owner May 13, 2020 19:29
@karriebear karriebear force-pushed the bug/1321-setting-logLevel branch from 9f693e9 to 9e7b757 Compare May 13, 2020 19:44
@karriebear karriebear requested a review from jrhone May 13, 2020 22:16
# avoids a race condition when another file (such as a test file) tries to pass
# in an alternative config.
_config.on_config_parsed(_set_log_level)
_config.on_config_parsed(_set_log_level, True)
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.

Q: Why force the connect_signal?

A: When we hit this, we've already parsed the config once, and we need set_log_level to be re-run when we parse the cli args and call signal.send()

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 find out if there is a definitive ordering between the config.toml being parsed and the cli args being parsed. I think it impacts our logic.

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.

Right now config.toml is being parsed as a result of getting global.developmentMode in folder_black_list.py which is imported through a series of imports.
cli.py --> bootstrap.py --> caching.py --> hashing.py

Given the current imports, it's definitive but it isn't exactly straightforward. If a change were to be made, I don't think it'd be intuitive to know.

Updated cli.py to force a definitive ordering.

"command-line argument or environment variable",
)
if _config._config_file_has_been_parsed:
_config._on_config_parsed.send()
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.

Is it possible for _config_file_has_been_parsed to be False here?

If so, are we still overriding config.toml args or will they now override the CLI args?

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.

If it is True, is it ok to execute the connected functions multiple times?

They should have executed initially after setting that to True

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.

Potential idea: If config.toml hasn't been parsed when we get here, force it

Copy link
Copy Markdown
Contributor Author

@karriebear karriebear May 18, 2020

Choose a reason for hiding this comment

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

Updated to force config file to be parsed prior to applying CLI args.

Current connected functions are _check_conflicts and _set_development_mode. Both of these seem fine to (and probably should) run again after applying CLI args.

@karriebear karriebear requested a review from nthmost May 18, 2020 20:14
Copy link
Copy Markdown
Contributor

@nthmost nthmost left a comment

Choose a reason for hiding this comment

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

LGTM

@karriebear karriebear force-pushed the bug/1321-setting-logLevel branch from b089e14 to 5b5e2f3 Compare May 26, 2020 19:26
@karriebear karriebear merged commit 6bcf727 into streamlit:develop May 27, 2020
tconkling added a commit that referenced this pull request May 28, 2020
* develop:
  Enable WebSocket compression (#1506)
  Showing an error when it's not localhost and has no mapbox token (#1295)
  Reapply on_config_parsed after applying cli args (#1448)
# goes out of scope immediately.
_on_config_parsed.connect(lambda _: func(), weak=False)
else:
func()
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 there's something better we need to do with the config system, which requires more thought.

But in the meantime, can we refactor this current solution for readability?

For example, we could have two signals:

if file has not been parsed:
  _on_config_parsed.connect(lambda _: func(), weak=False)

if command-line args have not been parsed:
  _on_args_parsed.connect(lambda _: func(), weak=False)

@karriebear karriebear deleted the bug/1321-setting-logLevel branch July 20, 2020 15:50
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.

Log levels not working

4 participants