Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Config cleanup - #761

Merged
byronz merged 36 commits into
masterfrom
config-cleanup
Jun 11, 2019
Merged

Config cleanup#761
byronz merged 36 commits into
masterfrom
config-cleanup

Conversation

@alexcjohnson

@alexcjohnsonalexcjohnson commented Jun 7, 2019

Copy link
Copy Markdown
Collaborator

closes#746

Some breaking changes to the dash.Dash API

Constructor / config breaking changes:

  • Removed two obsolete constructor kwargs: static_folder (assets_folder is much smarter) and components_cache_max_age (all files have cache-busting URLs)
  • Removed the very old misspelled supress_callback_exceptions fallback
  • Removed the unused resources.config.infer_from_layout
  • Revamped app.config: ALL constructor args are now stored in config (and none are stored in any other instance attributes anymore), with three exceptions:
    • server - app.init_app(server) is the right way to set this
    • index_string - it has a special setter method
    • plugins - You could add more plugins by calling my_plugin.plug(app) but not by modifying a config entry

Dev tools breaking changes:

  • Changed hot_reload_interval from msec to seconds, for consistency with hot_reload_watch_interval
  • When called from enable_dev_tools, debug=True by default. It's still False by default from run_server.

Non-breaking changes:

  • The expanded app.config prevents you from adding new (ie misspelled or obsolete) items and makes some items read-only - the ones that will not take effect if changed after the constructor (and init_app, since that can happen in the constructor) have finished.
  • The default assets_url_path is now just 'assets', not '/assets'. Since in actual usage we always strip the leading '/' and prepend the requests prefix, it's misleading as well as harder to explain with the slash there.
  • New constructor kwarg serve_locally - default True as per serve_locally by default #722 - sets both JS and CSS config
  • Added a docstring for the dash.Dash constructor and improved docstrings for the run_server and enable_dev_tools methods

Not implemented:

I looked into the name parameter and seems to me we should NOT make it mandatory, but would be interested to hear what others think about this. The only time this seems to matter is if the file that was run (python run.py in our common usage, or the gunicorn equivalent) is in a different directory from the one that defines app (let's call it app.py). All it seems to affect is where Flask looks for other files specified by relative paths, the key one being assets_folder.

  • Our default, '__main__', says these are relative to run.py.
  • Our recommended usage, name=__name__, says they're relative to app.py
  • You can specify something else with a package path (dotted, like package.sub.path as in import package.sub.path, and it will be resolved exactly as that import would be)
  • AFAICT it does NOT matter what the working dir was, relative to run.py, when you ran Python

Most of the time this doesn't matter, as run.py and app.py, if they're even separate files, are usually in the same dir. __name__ is nice in that you get the same assets folder no matter where you import app.py from, but on the other hand I suspect the more likely situation is that you set up your project and then at some point decide to move app.py into a subdirectory, without moving assets or run.py. In that case __name__ would cause problems, and the current default '__main__' is probably correct. That to me is a sufficient reason to leave the default behavior as it is.

Contributor Checklist

  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow
    • this github #PR number updates the dash docs
    • here is the show and tell thread in plotly dash community

Comment threaddash/CHANGELOG.md Outdated
@@ -1,5 +1,13 @@
## Unreleased
### Changed
- [#761](https://github.com/plotly/dash/pull/761) Several breaking changes to the `dash.Dash` API:

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.

a 💥 here?

Comment threaddash/dash.py
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash(object):
"""

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.

😸 nice docstring.

tangential question, do we have an agreed reference to follow? I feel like it's not very helpful to use super-long-detailed-sphinx-style; chris is also building sth in the house.

but from our users' perspective, data scientists might feel this more familiar https://sphinxcontrib-napoleon.readthedocs.io/en/latest/

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I'd be up for changing to a cleaner style, I was just copying the style we already had for run_server and enable_dev_tools.

Feels to me like we should have a decent level of detail here, and then use this to generate the corresponding page in dash-docs. Let's keep this format until we decide how we want to do that, so we only need to alter it once. @chriddyp I'm not aware if you're working on something else to fill this gap.

Comment threaddash/dash.py Outdated
Dash is a framework for building analytical web applications.
No JavaScript required.

If a parameter can be set by an environment variable, that is listed too.

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.

that is listed with env: prefix?

Comment threaddash/dash.py Outdated
:type server: boolean or flask.Flask

:param assets_folder: a path, relative to the current working directory,
for extra files to be used in the browser. Default ``'assets'`` By

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 Default 'asset' By default needs a better split.

Comment threaddash/dash.py Outdated
Default ``'assets'``.
:type asset_url_path: string

:param assets_ignore: A regexp, as a string to pass to ``re.compile``, for

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.

regexp is js flavor, pythonic name should be regex

Comment threaddash/dash.py Outdated
be called after the Flask server is attached.
:type plugins: list of objects

:param **kwargs: Do not use. Gives error messages for obsolete arguments.

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.

would it be more intuitive if we add an example section e.g. man lsof for less experienced users?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

You mean rather than the errors on providing old kwargs? I was thinking of those just as helpers for experienced users of old dash versions. This documentation of **kwargs is just intended for people who see **kwargs in the function signature and wonder why it's there. Perhaps I can omit this documentation and just rename it to **obsolete, and assume that's sufficiently self-documenting?

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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with 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.

Sorry for the confusion, I meant for all the docstring. Just happened to leave the comment at this line. Nothing wrong with kwargs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Got it. I feel like once people get here they've seen examples already elsewhere in the docs, so this docstring is just about enumerating all the options.

Anyway I will change **kwargs to **obsolete and remove it from the docstring.

html.Div(id='body')
])
app.config.supress_callback_exceptions = True
app.config.suppress_callback_exceptions = 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.

👍

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.

predicted merge conflicts here

context.exception.args[0]
)

def test_callback_dep_types(self):

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.

@alexcjohnson do you want to migrate this with new style?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

not too hard to migrate -> 4052507

Comment threaddash/testing/browser.py Outdated
((By.CSS_SELECTOR, selector),),
timeout,
"timeout {} => waiting for selector {}".format(timeout, selector),
"timeout {}s => waiting for selector {}".format(_time, selector),

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.

nice fix on the timeout
🐄 minor, I would use more pythonic way format (timeout if timeout else self._wait_timeout, selector)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

🐄 in 55274be

@byronzbyronz left a comment

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.

💃 nice job! the two new comments are good to have, feel free to merge without the change

input_.send_keys('xyz')
dash_duo.wait_for_text_to_equal('#input', 'initial inputxyz')

# callback1 runs 4x (initial page load and 3x through send_keys)

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 would put the comment as an assert msg, so you can see that directly in the assertion exception. the comment does show up too with the code snippet.

with self.assertRaises(InvalidCallbackReturnValue):
multi('aaa')
btn_elements = [
dash_duo.find_element('#' + x) for x in btns

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.

minor: prefer btn than x here

app = Dash(__name__)
btn = dash_duo.find_element('#btn')
for _ in range(10):
btn.click()

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.

you can use this API dash_duo.multiple_click(). yep the API reference is coming soon

 for _ in range(clicks):
self.find_element(css_selector).click()

])

with pytest.raises(IncorrectTypeException):
@app.callback([[Output('out', 'children')]], # extra nesting

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.

comment can be set as message='' inside raises

# Remove those
comment_regex = r'<!--[^\[](.*?)-->' # noqa: W605

# Somehow the html attributes are unordered.

@byronzbyronzJun 11, 2019

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 permutation was a bad idea, I did similar clean up with beautiful soup parser for the initial state test case

# Note: this .html file shows there's no undo/redo button by default
withopen(
os.path.join(
os.path.dirname(__file__), "initial_state_dash_app_content.html"
)
) asfp:
expected_dom=BeautifulSoup(fp.read().strip(), "lxml")
fetched_dom=dash_duo.dash_outerhtml_dom
assert (
fetched_dom.decode() ==expected_dom.decode()
), "the fetching rendered dom is expected"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

yeah I noticed that - BeautifulSoup is a nice idea, I'll try it here.

@byronz
byronz merged commit 558047f into masterJun 11, 2019
@alexcjohnson
alexcjohnson deleted the config-cleanup branch June 11, 2019 17:59
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this pull request May 28, 2021
Sign up for freeto 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.

Clean up kwargs and config

2 participants

@alexcjohnson@byronz