internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: plotly/dash

Issue:
Add support for '.map' file extension
As a Dash developer, I find myself wanting (needing) to debug the inner workings of dash components and dash renderer -- since we bundle and uglify with webpack, that is difficult.

Adding support for '.map' extension support (with return type application/json) would allow dash components developers to expose source maps and have access to them at runtime.


Discussion:

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -359,9 +359,6 @@ def _collect_and_register_resources(self, resources):
         # for cache busting
         def _relative_url_path(relative_package_path='', namespace=''):
 
-            # track the registered packages
-            self.registered_paths[namespace].add(relative_package_path)
-
             module_path = os.path.join(
                 os.path.dirname(sys.modules[namespace].__file__),
                 relative_package_path)
@@ -378,11 +375,17 @@ def _relative_url_path(relative_package_path='', namespace=''):
 
         srcs = []
         for resource in resources:
+            is_dynamic_resource = resource.get('dynamic', False)
+
             if 'relative_package_path' in resource:
-                if isinstance(resource['relative_package_path'], str):
-                    srcs.append(_relative_url_path(**resource))
-                else:
-                    for rel_path in resource['relative_package_path']:
+                paths = resource['relative_package_path']
+                paths = [paths] if isinstance(paths, str) else paths
+
+                for rel_path in paths:
+                    self.registered_paths[resource['namespace']]\
+                        .add(rel_path)
+
+                    if not is_dynamic_resource:
                         srcs.append(_relative_url_path(
                             relative_package_path=rel_path,
                             namespace=resource['namespace']
@@ -492,7 +495,8 @@ def serve_component_suites(self, package_name, path_in_package_dist):
 
         mimetype = ({
             'js': 'application/JavaScript',
-            'css': 'text/css'
+            'css': 'text/css',
+            'map': 'application/json'
         })[path_in_package_dist.split('.')[-1]]
 
         headers = {
diff --git a/dash/resources.py b/dash/resources.py
--- a/dash/resources.py
+++ b/dash/resources.py
@@ -19,6 +19,8 @@ def _filter_resources(self, all_resources, dev_bundles=False):
         filtered_resources = []
         for s in all_resources:
             filtered_resource = {}
+            if 'dynamic' in s:
+                filtered_resource['dynamic'] = s['dynamic']
             if 'namespace' in s:
                 filtered_resource['namespace'] = s['namespace']
             if 'external_url' in s and not self.config.serve_locally:
diff --git a/dash/version.py b/dash/version.py
--- a/dash/version.py
+++ b/dash/version.py
@@ -1 +1 @@
-__version__ = '0.31.1'
+__version__ = '0.32.0'


Test patch:
Repository: plotly/dash

Issue:
raising PreventUpdate should not print to stderr, and PreventUpdate should not inherit Exception
Hi, I think the default implementation should not print to `stderr` when `PreventUpdate` is raised. This is a minor point, because the following is a work-around (and as the docs improve both `PreventUpdate` and example of a custom error handler could be documented!)

```
# Example of replacing the default error handler for PreventUpdate
app = dash.Dash(__name__)

@app.server.errorhandler(dash.exceptions.PreventUpdate)
def _handle_error(error):
    """Handle a halted callback and return an empty 204 response"""
    #print(error, file=sys.stderr)
    return ('', 204)
```

Also, as a minor point, PreventUpdate should probably inherit `BaseException` _without_ inheriting Exception - the reason is the same as why `StopIteration` does not inherit `Exception` (because its not an error).


Discussion:
From https://docs.python.org/3/library/exceptions.html#BaseException

> The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use Exception).

The print statement should be removed.

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -169,10 +169,9 @@ def __init__(
             Compress(self.server)
 
         @self.server.errorhandler(exceptions.PreventUpdate)
-        def _handle_error(error):
+        def _handle_error(_):
             """Handle a halted callback and return an empty 204 response"""
-            print(error, file=sys.stderr)
-            return ('', 204)
+            return '', 204
 
         # static files from the packages
         self.css = Css()


Test patch:
Repository: plotly/dash

Issue:
Python 3.8 collections ABC deprecation warning
`Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working`

The warning comes from the base component class:

https://github.com/plotly/dash/blob/c9b392d2525f33b22dec0e877e62efc38509f4b8/dash/development/base_component.py#L61


Discussion:

Resolving patch:
diff --git a/dash/_utils.py b/dash/_utils.py
--- a/dash/_utils.py
+++ b/dash/_utils.py
@@ -1,4 +1,6 @@
 import uuid
+import collections
+import six
 
 
 def interpolate_str(template, **data):
@@ -40,6 +42,13 @@ def get_asset_path(
     ])
 
 
+# pylint: disable=no-member
+def patch_collections_abc(member):
+    if six.PY2:
+        return getattr(collections, member)
+    return getattr(collections.abc, member)
+
+
 class AttributeDict(dict):
     """
     Dictionary subclass enabling attribute lookup/assignment of keys/values.
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -30,8 +30,9 @@
 from ._utils import interpolate_str as _interpolate
 from ._utils import format_tag as _format_tag
 from ._utils import generate_hash as _generate_hash
-from . import _watch
 from ._utils import get_asset_path as _get_asset_path
+from ._utils import patch_collections_abc as _patch_collections_abc
+from . import _watch
 from . import _configs
 
 
@@ -275,7 +276,7 @@ def layout(self):
         return self._layout
 
     def _layout_value(self):
-        if isinstance(self._layout, collections.Callable):
+        if isinstance(self._layout, _patch_collections_abc('Callable')):
             self._cached_layout = self._layout()
         else:
             self._cached_layout = self._layout
@@ -284,7 +285,7 @@ def _layout_value(self):
     @layout.setter
     def layout(self, value):
         if (not isinstance(value, Component) and
-                not isinstance(value, collections.Callable)):
+                not isinstance(value, _patch_collections_abc('Callable'))):
             raise exceptions.NoLayoutException(
                 ''
                 'Layout must be a dash component '
diff --git a/dash/development/base_component.py b/dash/development/base_component.py
--- a/dash/development/base_component.py
+++ b/dash/development/base_component.py
@@ -5,6 +5,8 @@
 
 import six
 
+from .._utils import patch_collections_abc
+
 
 # pylint: disable=no-init,too-few-public-methods
 class ComponentRegistry:
@@ -58,7 +60,7 @@ def _check_if_has_indexable_children(item):
 
 
 @six.add_metaclass(ComponentMeta)
-class Component(collections.MutableMapping):
+class Component(patch_collections_abc('MutableMapping')):
     class _UNDEFINED(object):
         def __repr__(self):
             return 'undefined'


Test patch:
Repository: plotly/dash

Issue:
New version of dash_renderer is not automatically installed with Dash 0.36.0
Deploying apps on Dash Deployment Server results in `dash-renderer` not being updated if it is already installed (even if that version is `0.16.x` and the Dash version is specified as `0.36.0`. This causes an `Error loading dependencies`, as `dash-renderer` attempts to attach event handlers to Dash events, which don't exist any more. 


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,10 @@
         'Flask>=0.12',
         'flask-compress',
         'plotly',
-        'dash_renderer',
+        'dash_renderer==0.17.0',
+        'dash-core-components==0.43.0',
+        'dash-html-components==0.13.5',
+        'dash-table==3.3.0'
     ],
     entry_points={
         'console_scripts': [


Test patch:
Repository: plotly/dash

Issue:
Extract meta failure on missing props docstring.
If a props is missing a docstring, it will fail to generate the component with js error, `Cannot read property 'length' of undefined`.

https://community.plot.ly/t/dash-component-creation-javascript-ok-nothing-rendered-in-python/19369


Discussion:

Resolving patch:
diff --git a/dash/development/component_generator.py b/dash/development/component_generator.py
--- a/dash/development/component_generator.py
+++ b/dash/development/component_generator.py
@@ -89,7 +89,7 @@ def generate_components(components_source, project_shortname,
     )
 
     with open(os.path.join(project_shortname, 'metadata.json'), 'w') as f:
-        json.dump(metadata, f)
+        json.dump(metadata, f, indent=2)
 
     generate_imports(project_shortname, components)
 


Test patch:
Repository: plotly/dash

Issue:
Add components dist to hot reload watch.
The browser should reload when the components libraries bundles are regenerated.


Discussion:

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -24,7 +24,7 @@
 
 from .dependencies import Input, Output, State
 from .resources import Scripts, Css
-from .development.base_component import Component
+from .development.base_component import Component, ComponentRegistry
 from . import exceptions
 from ._utils import AttributeDict as _AttributeDict
 from ._utils import interpolate_str as _interpolate
@@ -1155,9 +1155,20 @@ def enable_dev_tools(self,
 
         if self._dev_tools.hot_reload:
             self._reload_hash = _generate_hash()
+
+            component_packages_dist = [
+                os.path.dirname(package.path)
+                if hasattr(package, 'path')
+                else package.filename
+                for package in (
+                    pkgutil.find_loader(x) for x in
+                    list(ComponentRegistry.registry) + ['dash_renderer']
+                )
+            ]
+
             self._watch_thread = threading.Thread(
                 target=lambda: _watch.watch(
-                    [self._assets_folder],
+                    [self._assets_folder] + component_packages_dist,
                     self._on_assets_change,
                     sleep_time=self._dev_tools.hot_reload_watch_interval)
             )


Test patch:
Repository: plotly/dash

Issue:
Add enable dev tools config 
this is a follow up task of [dash-renderer #100](https://github.com/plotly/dash-renderer/pull/100)

it adds an extra dev-tools config in `<script id="_dash-config" type="application/json">` section, the logic is simple, the value equals to the `debug` option in `run_server()`.

user set app.run_server(debug=True) will implicitly enable the dev-tools icon in FE.


Discussion:

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -237,7 +237,8 @@ def _handle_error(_):
             'hot_reload': False,
             'hot_reload_interval': 3000,
             'hot_reload_watch_interval': 0.5,
-            'hot_reload_max_retry': 8
+            'hot_reload_max_retry': 8,
+            'dev_tools_ui': False,
         })
 
         # add a handler for components suites errors to return 404
@@ -328,7 +329,8 @@ def serve_layout(self):
     def _config(self):
         config = {
             'url_base_pathname': self.url_base_pathname,
-            'requests_pathname_prefix': self.config['requests_pathname_prefix']
+            'requests_pathname_prefix': self.config.requests_pathname_prefix,
+            'dev_tools_ui': self._dev_tools.dev_tools_ui,
         }
         if self._dev_tools.hot_reload:
             config['hot_reload'] = {
@@ -1227,6 +1229,8 @@ def enable_dev_tools(self,
         debug = debug or _configs.get_config('debug', None, env, debug,
                                              is_bool=True)
 
+        self._dev_tools.dev_tools_ui = debug
+
         self._dev_tools['serve_dev_bundles'] = _configs.get_config(
             'serve_dev_bundles', dev_tools_serve_dev_bundles, env,
             default=debug,


Test patch:
Repository: plotly/dash

Issue:
[BUG] Auto-generated docstrings contain JS boolean values instead of Python boolean values
Prompted by https://github.com/plotly/dash-bio/pull/379#discussion_r297840872

While `true` and `false` are not capitalized in JavaScript, they are capitalized in Python. The Python components' docstrings should reflect this, since other JS types are "translated" into Python types (e.g., `PropTypes.shape` -> `dict`). 


Discussion:

Resolving patch:
diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py
--- a/dash/development/_py_components_generation.py
+++ b/dash/development/_py_components_generation.py
@@ -436,6 +436,9 @@ def create_prop_docstring(prop_name, type_object, required, description,
     else:
         default = default['value']
 
+    if default in ['true', 'false']:
+        default = default.title()
+
     is_required = 'optional'
     if required:
         is_required = 'required'


Test patch:
diff --git a/tests/unit/development/test_base_component.py b/tests/unit/development/test_base_component.py
--- a/tests/unit/development/test_base_component.py
+++ b/tests/unit/development/test_base_component.py
@@ -1041,7 +1041,7 @@ def assert_flow_docstring(assertEqual, docstring):
             "Keyword arguments:",
             "- requiredString (string; required): A required string",
             "- optionalString (string; default ''): A string that isn't required.",
-            "- optionalBoolean (boolean; default false): A boolean test",
+            "- optionalBoolean (boolean; default False): A boolean test",
 
             "- optionalNode (a list of or a singular dash component, string or number; optional): "
             "A node test",
Repository: plotly/dash

Issue:
Defer `pytest` import?
Looks like `pytest` isn't the safest dependency, causing issues with scikit-learn: https://community.plot.ly/t/pytest-transient-dependency/25383

Could we move the `import pytest` into the testing module/class/function itself and not require it upon install? We could even have a separate install with setup.py's "extras" feature (https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies) like `pip install dash[testing]` or something.


Discussion:
@chriddyp  in 1.0, we already use the `extras` feature in `setup.py`,  so the `pip install dash[testing]` might be the way to go.   

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,10 @@ def read_req_file(req_type):
     long_description=io.open("README.md", encoding="utf-8").read(),
     long_description_content_type="text/markdown",
     install_requires=read_req_file("install"),
-    extras_require={"ci": read_req_file("ci")},
+    extras_require={
+        "ci": read_req_file("ci"),
+        "testing": read_req_file("testing"),
+    },
     entry_points={
         "console_scripts": [
             "dash-generate-components ="


Test patch:
diff --git a/dash/testing/plugin.py b/dash/testing/plugin.py
--- a/dash/testing/plugin.py
+++ b/dash/testing/plugin.py
@@ -1,17 +1,16 @@
 # pylint: disable=missing-docstring,redefined-outer-name
-import pytest
+import warnings
 
-from selenium import webdriver
+try:
+    import pytest
 
-from dash.testing.application_runners import ThreadedRunner, ProcessRunner
-from dash.testing.browser import Browser
-from dash.testing.composite import DashComposite
+    from dash.testing.application_runners import ThreadedRunner, ProcessRunner
+    from dash.testing.browser import Browser
+    from dash.testing.composite import DashComposite
+except ImportError:
+    warnings.warn("run `pip install dash[testing]` if you need dash.testing")
 
-WEBDRIVERS = {
-    "Chrome": webdriver.Chrome,
-    "Firefox": webdriver.Firefox,
-    "Remote": webdriver.Remote,
-}
+WEBDRIVERS = {"Chrome", "Firefox", "Remote"}
 
 
 def pytest_addoption(parser):
@@ -21,7 +20,7 @@ def pytest_addoption(parser):
 
     dash.addoption(
         "--webdriver",
-        choices=tuple(WEBDRIVERS.keys()),
+        choices=tuple(WEBDRIVERS),
         default="Chrome",
         help="Name of the selenium driver to use",
     )
Repository: plotly/dash

Issue:
Generator should delete contents of inst/deps for R packages prior to rebuild
Currently, assets for component libraries which are shared between Python and R implementations of Dash are copied from within `project_shortname` to `inst/deps` without removing any artifacts of previous build cycles.

To avoid confusion in case older versions of assets remain from earlier build cycles, we should remove any files in `inst/deps` before assets are copied. The relevant code is here:

https://github.com/plotly/dash/blob/57dae3f0a64d82b2e87d67cfdcc2448950ffd324/dash/development/_r_components_generation.py#L442-L455

Documents in other `inst/*` subdirectories should continue to be left as-is, since these resources are not necessarily 1:1 with the Python package (e.g. vignettes, sample data in R format, etc.)

@alexcjohnson @Marc-Andre-Rivet @shammamah 


Discussion:

Resolving patch:
diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py
--- a/dash/development/_r_components_generation.py
+++ b/dash/development/_r_components_generation.py
@@ -442,8 +442,10 @@ def write_js_metadata(pkg_data, project_shortname, has_wildcards):
     # now copy over all JS dependencies from the (Python) components dir
     # the inst/lib directory for the package won't exist on first call
     # create this directory if it is missing
-    if not os.path.exists("inst/deps"):
-        os.makedirs("inst/deps")
+    if os.path.exists("inst/deps"):
+        shutil.rmtree("inst/deps")
+
+    os.makedirs("inst/deps")
 
     for javascript in glob.glob("{}/*.js".format(project_shortname)):
         shutil.copy(javascript, "inst/deps/")


Test patch:
Repository: plotly/dash

Issue:
Dash-docs fail to load because FLASK_ENV is modified at runtime
https://github.com/plotly/dash/blob/dev/dash/dash.py#L1616

This check is there for cosmetic purposes regarding the server start message.


Discussion:

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -1612,7 +1612,4 @@ def verify_url_part(served_part, url_part, part_name):
                 " in production, use a production WSGI server like gunicorn instead.\n"
             )
 
-        if not os.environ.get("FLASK_ENV"):
-            os.environ["FLASK_ENV"] = "development"
-
         self.server.run(host=host, port=port, debug=debug, **flask_run_options)


Test patch:
diff --git a/dash/testing/dash_page.py b/dash/testing/dash_page.py
--- a/dash/testing/dash_page.py
+++ b/dash/testing/dash_page.py
@@ -71,7 +71,7 @@ def window_store(self):
         return self.driver.execute_script("return window.store")
 
     def _wait_for_callbacks(self):
-        return not self.window_store or self.redux_state_rqs
+        return (not self.window_store) or self.redux_state_rqs == []
 
     def get_local_storage(self, store_id="local"):
         return self.driver.execute_script(
Repository: plotly/dash

Issue:
Missing classifiers for Python 3.8/3.9
Python 3.8 and 3.9 are missing from the classifiers in `setup.py`:

https://github.com/plotly/dash/blob/358c5089c929b2e99996f9d4ee6ec634f65437fe/setup.py#L55-L63

But there is no restriction to 3.7 or below in `python_requires`:
https://github.com/plotly/dash/blob/358c5089c929b2e99996f9d4ee6ec634f65437fe/setup.py#L29

Anecdotally, I've been using Dash on Python 3.9 with no issues. Reporting as an issue as I can't see any mention of Python 3.8 and 3.9 compatibility so far!


Discussion:
Good call, the classifiers haven't been updated in a while. FYI in the upcoming Dash 2.0 we're planning to change `python_requires` to `">=3.6"` - dropping Py2 altogether as well as 3.5 and below.
I can submit a basic PR to add 3.8 and 3.9 if you like? Not a big job, but it's something 😄 

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -61,6 +61,8 @@ def read_req_file(req_type):
         "Programming Language :: Python :: 3.5",
         "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
         "Topic :: Database :: Front-Ends",
         "Topic :: Office/Business :: Financial :: Spreadsheet",
         "Topic :: Scientific/Engineering :: Visualization",


Test patch:
Repository: plotly/dash

Issue:
Missing `f` prefix on f-strings
Some strings looks like they're meant to be f-strings but are missing the `f` prefix meaning variable interpolation won't happen.

https://github.com/plotly/dash/blob/f6b51a841e7deddebfbada374e7de4c297bb2ce8/dash/development/update_components.py#L48

I found this issue automatically. I'm a bot. Beep Boop 🦊. See other issues I found in your repo [here](https://codereview.doctor/plotly/dash)


Discussion:

Resolving patch:
diff --git a/dash/development/update_components.py b/dash/development/update_components.py
--- a/dash/development/update_components.py
+++ b/dash/development/update_components.py
@@ -45,7 +45,7 @@ def bootstrap_components(components_source, concurrency, install_type):
 
     if status or not out:
         print(
-            "🚨 Failed installing npm dependencies for component packages: {source_glob} (status={status}) 🚨",
+            f"🚨 Failed installing npm dependencies for component packages: {source_glob} (status={status}) 🚨",
             file=sys.stderr,
         )
         sys.exit(1)


Test patch: