We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
streamlit `--log-level` appears to have no affect to resultant logging level
### Summary

The CLI argument settings `--log-level` appear to have no affect. `log.debug` is never rendered  or changing the logging level does not appear to suppress logs not required.

### Steps to reproduce

Code snippet:

```
import logging
import streamlit as st
import pandas as pd

log.info("Test LOG INFO")
log.debug("Test LOG DEBUG")
log.warning("Test LOG WARNING")
log.error("Test LOG ERROR")

st.write("Here's our first attempt at using data to create a table:")
st.write(pd.DataFrame({
    'first column': [1, 2, 3, 4],
    'second column': [10, 20, 30, 40]
}))
```

**Actual behavior:**

1. for all debug  `streamlit --log_level=debug run  logging_test_app.py` produces
![image](https://user-images.githubusercontent.com/11743864/148130163-cbef3d60-5541-45f3-aa9e-0d7194a659d6.png)
not rendering `log.debug("Test LOG DEBUG")`

2. for only error  `streamlit --log_level=error  run  logging_test_app.py`  but produces same output
![image](https://user-images.githubusercontent.com/11743864/148130488-5d6e1004-9eac-4cfb-a8ae-b712d105341c.png)
only `log.error("Test LOG ERROR")` should be present


**Expected behavior:**
for case 1 the line `log.debug(..)` should be rendered with the other in the terminal
for case 2 only the `log.error(..)`  should be the only log line  rendered in the terminal

### Is this a regression?

 no

### Debug info

- Streamlit version: 1.3.1
- Python version: 3.9.2
- Using : Poetry 
- OS version: Windows 10
- Browser version: N/A

### Additional information
to ensure no enviromental or instance issues I  have tested  a very basic python script and with various logging levels as described above selected. In all cases the correct log results are rendered in the terminal.
![image](https://user-images.githubusercontent.com/11743864/148132632-0882c903-113d-448a-a3f1-7e951d6f2020.png)
![image](https://user-images.githubusercontent.com/11743864/148132688-426e367a-47d5-4d66-b7bf-e1bbc9fe8c8a.png)

```python
import logging
logging.basicConfig(level=logging.ERROR)
# logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

print("-"*80)
print(f"Logging Level: {logging.getLevelName(log.getEffectiveLevel())}")
log.info("Test LOG INFO")
log.debug("Test LOG DEBUG")
log.warning("Test LOG WARNING")
log.error("Test LOG ERROR")
print("-"*80)
```




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/streamlit/cli.py`
Content:
```
1 # Copyright 2018-2021 Streamlit Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """This is a script which is run when the Streamlit package is executed."""
16 
17 from streamlit import config as _config
18 
19 import os
20 from typing import Optional
21 
22 import click
23 
24 import streamlit
25 from streamlit.credentials import Credentials, check_credentials
26 import streamlit.bootstrap as bootstrap
27 from streamlit.case_converters import to_snake_case
28 
29 ACCEPTED_FILE_EXTENSIONS = ("py", "py3")
30 
31 LOG_LEVELS = ("error", "warning", "info", "debug")
32 
33 
34 def _convert_config_option_to_click_option(config_option):
35     """Composes given config option options as options for click lib."""
36     option = "--{}".format(config_option.key)
37     param = config_option.key.replace(".", "_")
38     description = config_option.description
39     if config_option.deprecated:
40         description += "\n {} - {}".format(
41             config_option.deprecation_text, config_option.expiration_date
42         )
43     envvar = "STREAMLIT_{}".format(to_snake_case(param).upper())
44 
45     return {
46         "param": param,
47         "description": description,
48         "type": config_option.type,
49         "option": option,
50         "envvar": envvar,
51     }
52 
53 
54 def configurator_options(func):
55     """Decorator that adds config param keys to click dynamically."""
56     for _, value in reversed(_config._config_options_template.items()):
57         parsed_parameter = _convert_config_option_to_click_option(value)
58         config_option = click.option(
59             parsed_parameter["option"],
60             parsed_parameter["param"],
61             help=parsed_parameter["description"],
62             type=parsed_parameter["type"],
63             show_envvar=True,
64             envvar=parsed_parameter["envvar"],
65         )
66         func = config_option(func)
67     return func
68 
69 
70 # Fetch remote file at url_path to script_path
71 def _download_remote(script_path, url_path):
72     import requests
73 
74     with open(script_path, "wb") as fp:
75         try:
76             resp = requests.get(url_path)
77             resp.raise_for_status()
78             fp.write(resp.content)
79         except requests.exceptions.RequestException as e:
80             raise click.BadParameter(("Unable to fetch {}.\n{}".format(url_path, e)))
81 
82 
83 @click.group(context_settings={"auto_envvar_prefix": "STREAMLIT"})
84 @click.option("--log_level", show_default=True, type=click.Choice(LOG_LEVELS))
85 @click.version_option(prog_name="Streamlit")
86 @click.pass_context
87 def main(ctx, log_level="info"):
88     """Try out a demo with:
89 
90         $ streamlit hello
91 
92     Or use the line below to run your own script:
93 
94         $ streamlit run your_script.py
95     """
96 
97     if log_level:
98         import streamlit.logger
99 
100         streamlit.logger.set_log_level(log_level.upper())
101 
102 
103 @main.command("help")
104 @click.pass_context
105 def help(ctx):
106     """Print this help message."""
107     # Pretend user typed 'streamlit --help' instead of 'streamlit help'.
108     import sys
109 
110     assert len(sys.argv) == 2  # This is always true, but let's assert anyway.
111     sys.argv[1] = "--help"
112     main(prog_name="streamlit")
113 
114 
115 @main.command("version")
116 @click.pass_context
117 def main_version(ctx):
118     """Print Streamlit's version number."""
119     # Pretend user typed 'streamlit --version' instead of 'streamlit version'
120     import sys
121 
122     assert len(sys.argv) == 2  # This is always true, but let's assert anyway.
123     sys.argv[1] = "--version"
124     main()
125 
126 
127 @main.command("docs")
128 def main_docs():
129     """Show help in browser."""
130     print("Showing help page in browser...")
131     from streamlit import util
132 
133     util.open_browser("https://docs.streamlit.io")
134 
135 
136 @main.command("hello")
137 @configurator_options
138 def main_hello(**kwargs):
139     """Runs the Hello World script."""
140     from streamlit.hello import hello
141 
142     bootstrap.load_config_options(flag_options=kwargs)
143     filename = hello.__file__
144     _main_run(filename, flag_options=kwargs)
145 
146 
147 @main.command("run")
148 @configurator_options
149 @click.argument("target", required=True, envvar="STREAMLIT_RUN_TARGET")
150 @click.argument("args", nargs=-1)
151 def main_run(target, args=None, **kwargs):
152     """Run a Python script, piping stderr to Streamlit.
153 
154     The script can be local or it can be an url. In the latter case, Streamlit
155     will download the script to a temporary file and runs this file.
156 
157     """
158     from validators import url
159 
160     bootstrap.load_config_options(flag_options=kwargs)
161 
162     _, extension = os.path.splitext(target)
163     if extension[1:] not in ACCEPTED_FILE_EXTENSIONS:
164         if extension[1:] == "":
165             raise click.BadArgumentUsage(
166                 "Streamlit requires raw Python (.py) files, but the provided file has no extension.\nFor more information, please see https://docs.streamlit.io"
167             )
168         else:
169             raise click.BadArgumentUsage(
170                 "Streamlit requires raw Python (.py) files, not %s.\nFor more information, please see https://docs.streamlit.io"
171                 % extension
172             )
173 
174     if url(target):
175         from streamlit.temporary_directory import TemporaryDirectory
176 
177         with TemporaryDirectory() as temp_dir:
178             from urllib.parse import urlparse
179             from streamlit import url_util
180 
181             path = urlparse(target).path
182             script_path = os.path.join(temp_dir, path.strip("/").rsplit("/", 1)[-1])
183             # if this is a GitHub/Gist blob url, convert to a raw URL first.
184             target = url_util.process_gitblob_url(target)
185             _download_remote(script_path, target)
186             _main_run(script_path, args, flag_options=kwargs)
187     else:
188         if not os.path.exists(target):
189             raise click.BadParameter("File does not exist: {}".format(target))
190         _main_run(target, args, flag_options=kwargs)
191 
192 
193 def _get_command_line_as_string() -> Optional[str]:
194     import subprocess
195 
196     parent = click.get_current_context().parent
197     if parent is None:
198         return None
199     cmd_line_as_list = [parent.command_path]
200     cmd_line_as_list.extend(click.get_os_args())
201     return subprocess.list2cmdline(cmd_line_as_list)
202 
203 
204 def _main_run(file, args=None, flag_options=None):
205     if args is None:
206         args = []
207 
208     if flag_options is None:
209         flag_options = {}
210 
211     command_line = _get_command_line_as_string()
212 
213     # Set a global flag indicating that we're "within" streamlit.
214     streamlit._is_running_with_streamlit = True
215 
216     check_credentials()
217 
218     bootstrap.run(file, command_line, args, flag_options)
219 
220 
221 # SUBCOMMAND: cache
222 
223 
224 @main.group("cache")
225 def cache():
226     """Manage the Streamlit cache."""
227     pass
228 
229 
230 @cache.command("clear")
231 def cache_clear():
232     """Clear st.cache, st.memo, and st.singleton caches."""
233     import streamlit.legacy_caching
234     import streamlit.caching
235 
236     result = streamlit.legacy_caching.clear_cache()
237     cache_path = streamlit.legacy_caching.get_cache_path()
238     if result:
239         print("Cleared directory %s." % cache_path)
240     else:
241         print("Nothing to clear at %s." % cache_path)
242 
243     streamlit.caching.clear_memo_cache()
244     streamlit.caching.clear_singleton_cache()
245 
246 
247 # SUBCOMMAND: config
248 
249 
250 @main.group("config")
251 def config():
252     """Manage Streamlit's config settings."""
253     pass
254 
255 
256 @config.command("show")
257 @configurator_options
258 def config_show(**kwargs):
259     """Show all of Streamlit's config settings."""
260 
261     bootstrap.load_config_options(flag_options=kwargs)
262 
263     _config.show_config()
264 
265 
266 # SUBCOMMAND: activate
267 
268 
269 @main.group("activate", invoke_without_command=True)
270 @click.pass_context
271 def activate(ctx):
272     """Activate Streamlit by entering your email."""
273     if not ctx.invoked_subcommand:
274         Credentials.get_current().activate()
275 
276 
277 @activate.command("reset")
278 def activate_reset():
279     """Reset Activation Credentials."""
280     Credentials.get_current().reset()
281 
282 
283 if __name__ == "__main__":
284     main()
285
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/streamlit/cli.py b/lib/streamlit/cli.py
--- a/lib/streamlit/cli.py
+++ b/lib/streamlit/cli.py
@@ -95,9 +95,13 @@
     """
 
     if log_level:
-        import streamlit.logger
+        from streamlit.logger import get_logger
 
-        streamlit.logger.set_log_level(log_level.upper())
+        LOGGER = get_logger(__name__)
+        LOGGER.warning(
+            "Setting the log level using the --log_level flag is unsupported."
+            "\nUse the --logger.level flag (after your streamlit command) instead."
+        )
 
 
 @main.command("help")

{"golden_diff": "diff --git a/lib/streamlit/cli.py b/lib/streamlit/cli.py\n--- a/lib/streamlit/cli.py\n+++ b/lib/streamlit/cli.py\n@@ -95,9 +95,13 @@\n     \"\"\"\n \n     if log_level:\n-        import streamlit.logger\n+        from streamlit.logger import get_logger\n \n-        streamlit.logger.set_log_level(log_level.upper())\n+        LOGGER = get_logger(__name__)\n+        LOGGER.warning(\n+            \"Setting the log level using the --log_level flag is unsupported.\"\n+            \"\\nUse the --logger.level flag (after your streamlit command) instead.\"\n+        )\n \n \n @main.command(\"help\")\n", "issue": "streamlit `--log-level` appears to have no affect to resultant logging level\n### Summary\r\n\r\nThe CLI argument settings `--log-level` appear to have no affect. `log.debug` is never rendered  or changing the logging level does not appear to suppress logs not required.\r\n\r\n### Steps to reproduce\r\n\r\nCode snippet:\r\n\r\n```\r\nimport logging\r\nimport streamlit as st\r\nimport pandas as pd\r\n\r\nlog.info(\"Test LOG INFO\")\r\nlog.debug(\"Test LOG DEBUG\")\r\nlog.warning(\"Test LOG WARNING\")\r\nlog.error(\"Test LOG ERROR\")\r\n\r\nst.write(\"Here's our first attempt at using data to create a table:\")\r\nst.write(pd.DataFrame({\r\n    'first column': [1, 2, 3, 4],\r\n    'second column': [10, 20, 30, 40]\r\n}))\r\n```\r\n\r\n**Actual behavior:**\r\n\r\n1. for all debug  `streamlit --log_level=debug run  logging_test_app.py` produces\r\n![image](https://user-images.githubusercontent.com/11743864/148130163-cbef3d60-5541-45f3-aa9e-0d7194a659d6.png)\r\nnot rendering `log.debug(\"Test LOG DEBUG\")`\r\n\r\n2. for only error  `streamlit --log_level=error  run  logging_test_app.py`  but produces same output\r\n![image](https://user-images.githubusercontent.com/11743864/148130488-5d6e1004-9eac-4cfb-a8ae-b712d105341c.png)\r\nonly `log.error(\"Test LOG ERROR\")` should be present\r\n\r\n\r\n**Expected behavior:**\r\nfor case 1 the line `log.debug(..)` should be rendered with the other in the terminal\r\nfor case 2 only the `log.error(..)`  should be the only log line  rendered in the terminal\r\n\r\n### Is this a regression?\r\n\r\n no\r\n\r\n### Debug info\r\n\r\n- Streamlit version: 1.3.1\r\n- Python version: 3.9.2\r\n- Using : Poetry \r\n- OS version: Windows 10\r\n- Browser version: N/A\r\n\r\n### Additional information\r\nto ensure no enviromental or instance issues I  have tested  a very basic python script and with various logging levels as described above selected. In all cases the correct log results are rendered in the terminal.\r\n![image](https://user-images.githubusercontent.com/11743864/148132632-0882c903-113d-448a-a3f1-7e951d6f2020.png)\r\n![image](https://user-images.githubusercontent.com/11743864/148132688-426e367a-47d5-4d66-b7bf-e1bbc9fe8c8a.png)\r\n\r\n```python\r\nimport logging\r\nlogging.basicConfig(level=logging.ERROR)\r\n# logging.basicConfig(level=logging.DEBUG)\r\nlog = logging.getLogger(__name__)\r\n\r\nprint(\"-\"*80)\r\nprint(f\"Logging Level: {logging.getLevelName(log.getEffectiveLevel())}\")\r\nlog.info(\"Test LOG INFO\")\r\nlog.debug(\"Test LOG DEBUG\")\r\nlog.warning(\"Test LOG WARNING\")\r\nlog.error(\"Test LOG ERROR\")\r\nprint(\"-\"*80)\r\n```\r\n\r\n\r\n\n", "before_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"This is a script which is run when the Streamlit package is executed.\"\"\"\n\nfrom streamlit import config as _config\n\nimport os\nfrom typing import Optional\n\nimport click\n\nimport streamlit\nfrom streamlit.credentials import Credentials, check_credentials\nimport streamlit.bootstrap as bootstrap\nfrom streamlit.case_converters import to_snake_case\n\nACCEPTED_FILE_EXTENSIONS = (\"py\", \"py3\")\n\nLOG_LEVELS = (\"error\", \"warning\", \"info\", \"debug\")\n\n\ndef _convert_config_option_to_click_option(config_option):\n    \"\"\"Composes given config option options as options for click lib.\"\"\"\n    option = \"--{}\".format(config_option.key)\n    param = config_option.key.replace(\".\", \"_\")\n    description = config_option.description\n    if config_option.deprecated:\n        description += \"\\n {} - {}\".format(\n            config_option.deprecation_text, config_option.expiration_date\n        )\n    envvar = \"STREAMLIT_{}\".format(to_snake_case(param).upper())\n\n    return {\n        \"param\": param,\n        \"description\": description,\n        \"type\": config_option.type,\n        \"option\": option,\n        \"envvar\": envvar,\n    }\n\n\ndef configurator_options(func):\n    \"\"\"Decorator that adds config param keys to click dynamically.\"\"\"\n    for _, value in reversed(_config._config_options_template.items()):\n        parsed_parameter = _convert_config_option_to_click_option(value)\n        config_option = click.option(\n            parsed_parameter[\"option\"],\n            parsed_parameter[\"param\"],\n            help=parsed_parameter[\"description\"],\n            type=parsed_parameter[\"type\"],\n            show_envvar=True,\n            envvar=parsed_parameter[\"envvar\"],\n        )\n        func = config_option(func)\n    return func\n\n\n# Fetch remote file at url_path to script_path\ndef _download_remote(script_path, url_path):\n    import requests\n\n    with open(script_path, \"wb\") as fp:\n        try:\n            resp = requests.get(url_path)\n            resp.raise_for_status()\n            fp.write(resp.content)\n        except requests.exceptions.RequestException as e:\n            raise click.BadParameter((\"Unable to fetch {}.\\n{}\".format(url_path, e)))\n\n\n@click.group(context_settings={\"auto_envvar_prefix\": \"STREAMLIT\"})\n@click.option(\"--log_level\", show_default=True, type=click.Choice(LOG_LEVELS))\n@click.version_option(prog_name=\"Streamlit\")\n@click.pass_context\ndef main(ctx, log_level=\"info\"):\n    \"\"\"Try out a demo with:\n\n        $ streamlit hello\n\n    Or use the line below to run your own script:\n\n        $ streamlit run your_script.py\n    \"\"\"\n\n    if log_level:\n        import streamlit.logger\n\n        streamlit.logger.set_log_level(log_level.upper())\n\n\n@main.command(\"help\")\n@click.pass_context\ndef help(ctx):\n    \"\"\"Print this help message.\"\"\"\n    # Pretend user typed 'streamlit --help' instead of 'streamlit help'.\n    import sys\n\n    assert len(sys.argv) == 2  # This is always true, but let's assert anyway.\n    sys.argv[1] = \"--help\"\n    main(prog_name=\"streamlit\")\n\n\n@main.command(\"version\")\n@click.pass_context\ndef main_version(ctx):\n    \"\"\"Print Streamlit's version number.\"\"\"\n    # Pretend user typed 'streamlit --version' instead of 'streamlit version'\n    import sys\n\n    assert len(sys.argv) == 2  # This is always true, but let's assert anyway.\n    sys.argv[1] = \"--version\"\n    main()\n\n\n@main.command(\"docs\")\ndef main_docs():\n    \"\"\"Show help in browser.\"\"\"\n    print(\"Showing help page in browser...\")\n    from streamlit import util\n\n    util.open_browser(\"https://docs.streamlit.io\")\n\n\n@main.command(\"hello\")\n@configurator_options\ndef main_hello(**kwargs):\n    \"\"\"Runs the Hello World script.\"\"\"\n    from streamlit.hello import hello\n\n    bootstrap.load_config_options(flag_options=kwargs)\n    filename = hello.__file__\n    _main_run(filename, flag_options=kwargs)\n\n\n@main.command(\"run\")\n@configurator_options\n@click.argument(\"target\", required=True, envvar=\"STREAMLIT_RUN_TARGET\")\n@click.argument(\"args\", nargs=-1)\ndef main_run(target, args=None, **kwargs):\n    \"\"\"Run a Python script, piping stderr to Streamlit.\n\n    The script can be local or it can be an url. In the latter case, Streamlit\n    will download the script to a temporary file and runs this file.\n\n    \"\"\"\n    from validators import url\n\n    bootstrap.load_config_options(flag_options=kwargs)\n\n    _, extension = os.path.splitext(target)\n    if extension[1:] not in ACCEPTED_FILE_EXTENSIONS:\n        if extension[1:] == \"\":\n            raise click.BadArgumentUsage(\n                \"Streamlit requires raw Python (.py) files, but the provided file has no extension.\\nFor more information, please see https://docs.streamlit.io\"\n            )\n        else:\n            raise click.BadArgumentUsage(\n                \"Streamlit requires raw Python (.py) files, not %s.\\nFor more information, please see https://docs.streamlit.io\"\n                % extension\n            )\n\n    if url(target):\n        from streamlit.temporary_directory import TemporaryDirectory\n\n        with TemporaryDirectory() as temp_dir:\n            from urllib.parse import urlparse\n            from streamlit import url_util\n\n            path = urlparse(target).path\n            script_path = os.path.join(temp_dir, path.strip(\"/\").rsplit(\"/\", 1)[-1])\n            # if this is a GitHub/Gist blob url, convert to a raw URL first.\n            target = url_util.process_gitblob_url(target)\n            _download_remote(script_path, target)\n            _main_run(script_path, args, flag_options=kwargs)\n    else:\n        if not os.path.exists(target):\n            raise click.BadParameter(\"File does not exist: {}\".format(target))\n        _main_run(target, args, flag_options=kwargs)\n\n\ndef _get_command_line_as_string() -> Optional[str]:\n    import subprocess\n\n    parent = click.get_current_context().parent\n    if parent is None:\n        return None\n    cmd_line_as_list = [parent.command_path]\n    cmd_line_as_list.extend(click.get_os_args())\n    return subprocess.list2cmdline(cmd_line_as_list)\n\n\ndef _main_run(file, args=None, flag_options=None):\n    if args is None:\n        args = []\n\n    if flag_options is None:\n        flag_options = {}\n\n    command_line = _get_command_line_as_string()\n\n    # Set a global flag indicating that we're \"within\" streamlit.\n    streamlit._is_running_with_streamlit = True\n\n    check_credentials()\n\n    bootstrap.run(file, command_line, args, flag_options)\n\n\n# SUBCOMMAND: cache\n\n\n@main.group(\"cache\")\ndef cache():\n    \"\"\"Manage the Streamlit cache.\"\"\"\n    pass\n\n\n@cache.command(\"clear\")\ndef cache_clear():\n    \"\"\"Clear st.cache, st.memo, and st.singleton caches.\"\"\"\n    import streamlit.legacy_caching\n    import streamlit.caching\n\n    result = streamlit.legacy_caching.clear_cache()\n    cache_path = streamlit.legacy_caching.get_cache_path()\n    if result:\n        print(\"Cleared directory %s.\" % cache_path)\n    else:\n        print(\"Nothing to clear at %s.\" % cache_path)\n\n    streamlit.caching.clear_memo_cache()\n    streamlit.caching.clear_singleton_cache()\n\n\n# SUBCOMMAND: config\n\n\n@main.group(\"config\")\ndef config():\n    \"\"\"Manage Streamlit's config settings.\"\"\"\n    pass\n\n\n@config.command(\"show\")\n@configurator_options\ndef config_show(**kwargs):\n    \"\"\"Show all of Streamlit's config settings.\"\"\"\n\n    bootstrap.load_config_options(flag_options=kwargs)\n\n    _config.show_config()\n\n\n# SUBCOMMAND: activate\n\n\n@main.group(\"activate\", invoke_without_command=True)\n@click.pass_context\ndef activate(ctx):\n    \"\"\"Activate Streamlit by entering your email.\"\"\"\n    if not ctx.invoked_subcommand:\n        Credentials.get_current().activate()\n\n\n@activate.command(\"reset\")\ndef activate_reset():\n    \"\"\"Reset Activation Credentials.\"\"\"\n    Credentials.get_current().reset()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "lib/streamlit/cli.py"}], "after_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"This is a script which is run when the Streamlit package is executed.\"\"\"\n\nfrom streamlit import config as _config\n\nimport os\nfrom typing import Optional\n\nimport click\n\nimport streamlit\nfrom streamlit.credentials import Credentials, check_credentials\nimport streamlit.bootstrap as bootstrap\nfrom streamlit.case_converters import to_snake_case\n\nACCEPTED_FILE_EXTENSIONS = (\"py\", \"py3\")\n\nLOG_LEVELS = (\"error\", \"warning\", \"info\", \"debug\")\n\n\ndef _convert_config_option_to_click_option(config_option):\n    \"\"\"Composes given config option options as options for click lib.\"\"\"\n    option = \"--{}\".format(config_option.key)\n    param = config_option.key.replace(\".\", \"_\")\n    description = config_option.description\n    if config_option.deprecated:\n        description += \"\\n {} - {}\".format(\n            config_option.deprecation_text, config_option.expiration_date\n        )\n    envvar = \"STREAMLIT_{}\".format(to_snake_case(param).upper())\n\n    return {\n        \"param\": param,\n        \"description\": description,\n        \"type\": config_option.type,\n        \"option\": option,\n        \"envvar\": envvar,\n    }\n\n\ndef configurator_options(func):\n    \"\"\"Decorator that adds config param keys to click dynamically.\"\"\"\n    for _, value in reversed(_config._config_options_template.items()):\n        parsed_parameter = _convert_config_option_to_click_option(value)\n        config_option = click.option(\n            parsed_parameter[\"option\"],\n            parsed_parameter[\"param\"],\n            help=parsed_parameter[\"description\"],\n            type=parsed_parameter[\"type\"],\n            show_envvar=True,\n            envvar=parsed_parameter[\"envvar\"],\n        )\n        func = config_option(func)\n    return func\n\n\n# Fetch remote file at url_path to script_path\ndef _download_remote(script_path, url_path):\n    import requests\n\n    with open(script_path, \"wb\") as fp:\n        try:\n            resp = requests.get(url_path)\n            resp.raise_for_status()\n            fp.write(resp.content)\n        except requests.exceptions.RequestException as e:\n            raise click.BadParameter((\"Unable to fetch {}.\\n{}\".format(url_path, e)))\n\n\n@click.group(context_settings={\"auto_envvar_prefix\": \"STREAMLIT\"})\n@click.option(\"--log_level\", show_default=True, type=click.Choice(LOG_LEVELS))\n@click.version_option(prog_name=\"Streamlit\")\n@click.pass_context\ndef main(ctx, log_level=\"info\"):\n    \"\"\"Try out a demo with:\n\n        $ streamlit hello\n\n    Or use the line below to run your own script:\n\n        $ streamlit run your_script.py\n    \"\"\"\n\n    if log_level:\n        from streamlit.logger import get_logger\n\n        LOGGER = get_logger(__name__)\n        LOGGER.warning(\n            \"Setting the log level using the --log_level flag is unsupported.\"\n            \"\\nUse the --logger.level flag (after your streamlit command) instead.\"\n        )\n\n\n@main.command(\"help\")\n@click.pass_context\ndef help(ctx):\n    \"\"\"Print this help message.\"\"\"\n    # Pretend user typed 'streamlit --help' instead of 'streamlit help'.\n    import sys\n\n    assert len(sys.argv) == 2  # This is always true, but let's assert anyway.\n    sys.argv[1] = \"--help\"\n    main(prog_name=\"streamlit\")\n\n\n@main.command(\"version\")\n@click.pass_context\ndef main_version(ctx):\n    \"\"\"Print Streamlit's version number.\"\"\"\n    # Pretend user typed 'streamlit --version' instead of 'streamlit version'\n    import sys\n\n    assert len(sys.argv) == 2  # This is always true, but let's assert anyway.\n    sys.argv[1] = \"--version\"\n    main()\n\n\n@main.command(\"docs\")\ndef main_docs():\n    \"\"\"Show help in browser.\"\"\"\n    print(\"Showing help page in browser...\")\n    from streamlit import util\n\n    util.open_browser(\"https://docs.streamlit.io\")\n\n\n@main.command(\"hello\")\n@configurator_options\ndef main_hello(**kwargs):\n    \"\"\"Runs the Hello World script.\"\"\"\n    from streamlit.hello import hello\n\n    bootstrap.load_config_options(flag_options=kwargs)\n    filename = hello.__file__\n    _main_run(filename, flag_options=kwargs)\n\n\n@main.command(\"run\")\n@configurator_options\n@click.argument(\"target\", required=True, envvar=\"STREAMLIT_RUN_TARGET\")\n@click.argument(\"args\", nargs=-1)\ndef main_run(target, args=None, **kwargs):\n    \"\"\"Run a Python script, piping stderr to Streamlit.\n\n    The script can be local or it can be an url. In the latter case, Streamlit\n    will download the script to a temporary file and runs this file.\n\n    \"\"\"\n    from validators import url\n\n    bootstrap.load_config_options(flag_options=kwargs)\n\n    _, extension = os.path.splitext(target)\n    if extension[1:] not in ACCEPTED_FILE_EXTENSIONS:\n        if extension[1:] == \"\":\n            raise click.BadArgumentUsage(\n                \"Streamlit requires raw Python (.py) files, but the provided file has no extension.\\nFor more information, please see https://docs.streamlit.io\"\n            )\n        else:\n            raise click.BadArgumentUsage(\n                \"Streamlit requires raw Python (.py) files, not %s.\\nFor more information, please see https://docs.streamlit.io\"\n                % extension\n            )\n\n    if url(target):\n        from streamlit.temporary_directory import TemporaryDirectory\n\n        with TemporaryDirectory() as temp_dir:\n            from urllib.parse import urlparse\n            from streamlit import url_util\n\n            path = urlparse(target).path\n            script_path = os.path.join(temp_dir, path.strip(\"/\").rsplit(\"/\", 1)[-1])\n            # if this is a GitHub/Gist blob url, convert to a raw URL first.\n            target = url_util.process_gitblob_url(target)\n            _download_remote(script_path, target)\n            _main_run(script_path, args, flag_options=kwargs)\n    else:\n        if not os.path.exists(target):\n            raise click.BadParameter(\"File does not exist: {}\".format(target))\n        _main_run(target, args, flag_options=kwargs)\n\n\ndef _get_command_line_as_string() -> Optional[str]:\n    import subprocess\n\n    parent = click.get_current_context().parent\n    if parent is None:\n        return None\n    cmd_line_as_list = [parent.command_path]\n    cmd_line_as_list.extend(click.get_os_args())\n    return subprocess.list2cmdline(cmd_line_as_list)\n\n\ndef _main_run(file, args=None, flag_options=None):\n    if args is None:\n        args = []\n\n    if flag_options is None:\n        flag_options = {}\n\n    command_line = _get_command_line_as_string()\n\n    # Set a global flag indicating that we're \"within\" streamlit.\n    streamlit._is_running_with_streamlit = True\n\n    check_credentials()\n\n    bootstrap.run(file, command_line, args, flag_options)\n\n\n# SUBCOMMAND: cache\n\n\n@main.group(\"cache\")\ndef cache():\n    \"\"\"Manage the Streamlit cache.\"\"\"\n    pass\n\n\n@cache.command(\"clear\")\ndef cache_clear():\n    \"\"\"Clear st.cache, st.memo, and st.singleton caches.\"\"\"\n    import streamlit.legacy_caching\n    import streamlit.caching\n\n    result = streamlit.legacy_caching.clear_cache()\n    cache_path = streamlit.legacy_caching.get_cache_path()\n    if result:\n        print(\"Cleared directory %s.\" % cache_path)\n    else:\n        print(\"Nothing to clear at %s.\" % cache_path)\n\n    streamlit.caching.clear_memo_cache()\n    streamlit.caching.clear_singleton_cache()\n\n\n# SUBCOMMAND: config\n\n\n@main.group(\"config\")\ndef config():\n    \"\"\"Manage Streamlit's config settings.\"\"\"\n    pass\n\n\n@config.command(\"show\")\n@configurator_options\ndef config_show(**kwargs):\n    \"\"\"Show all of Streamlit's config settings.\"\"\"\n\n    bootstrap.load_config_options(flag_options=kwargs)\n\n    _config.show_config()\n\n\n# SUBCOMMAND: activate\n\n\n@main.group(\"activate\", invoke_without_command=True)\n@click.pass_context\ndef activate(ctx):\n    \"\"\"Activate Streamlit by entering your email.\"\"\"\n    if not ctx.invoked_subcommand:\n        Credentials.get_current().activate()\n\n\n@activate.command(\"reset\")\ndef activate_reset():\n    \"\"\"Reset Activation Credentials.\"\"\"\n    Credentials.get_current().reset()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "lib/streamlit/cli.py"}]}