From 504efc3bf97902ef1edf6a6beee063cb931c3c41 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Tue, 16 Nov 2021 09:32:14 -0500 Subject: [PATCH 1/3] include dcc and table extras in `__all__` and test that this fixes imports from the old packages --- .../dash_core_components_base/__init__.py | 9 +++- .../dash-table/dash_table_base/__init__.py | 4 +- tests/unit/test_old_imports.py | 42 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_old_imports.py diff --git a/components/dash-core-components/dash_core_components_base/__init__.py b/components/dash-core-components/dash_core_components_base/__init__.py index 3cce7d970e..427d110325 100644 --- a/components/dash-core-components/dash_core_components_base/__init__.py +++ b/components/dash-core-components/dash_core_components_base/__init__.py @@ -4,7 +4,7 @@ import dash as _dash from ._imports_ import * # noqa: F401, F403, E402 -from ._imports_ import __all__ # noqa: E402 +from ._imports_ import __all__ as _components from .express import ( # noqa: F401, E402 send_bytes, send_data_frame, @@ -12,6 +12,13 @@ send_string, ) +__all__ = _components + [ + "send_bytes", + "send_data_frame", + "send_file", + "send_string", +] + _basepath = _os.path.dirname(__file__) _filepath = _os.path.abspath(_os.path.join(_basepath, "package-info.json")) with open(_filepath) as f: diff --git a/components/dash-table/dash_table_base/__init__.py b/components/dash-table/dash_table_base/__init__.py index 40772f329d..7e3bd250b1 100644 --- a/components/dash-table/dash_table_base/__init__.py +++ b/components/dash-table/dash_table_base/__init__.py @@ -14,10 +14,12 @@ _sys.exit(1) from ._imports_ import * # noqa: E402, F401, F403 -from ._imports_ import __all__ # noqa: E402 +from ._imports_ import __all__ as _components from . import Format # noqa: F401, E402 from . import FormatTemplate # noqa: F401, E402 +__all__ = _components + ["Format", "FormatTemplate"] + _basepath = _os.path.dirname(__file__) _filepath = _os.path.abspath(_os.path.join(_basepath, "package-info.json")) with open(_filepath) as f: diff --git a/tests/unit/test_old_imports.py b/tests/unit/test_old_imports.py new file mode 100644 index 0000000000..08d7b14a23 --- /dev/null +++ b/tests/unit/test_old_imports.py @@ -0,0 +1,42 @@ +from pytest import warns + +from dash import dcc, dash_table + + +def filter_dir(package): + ignore = [ + "warnings", + "json", + "async_resources", + "package", + "package_name", + "f", + "express", + ] + return sorted( + [ + item + for item in dir(package) + if item == "__version__" or (item[0] not in "@_" and item not in ignore) + ] + ) + + +def test_old_dcc(): + with warns(UserWarning, match="dash_core_components package is deprecated"): + import dash_core_components as _dcc + + old_dir = filter_dir(_dcc) + new_dir = filter_dir(dcc) + + assert old_dir == new_dir + + +def test_old_table(): + with warns(UserWarning, match="dash_table package is deprecated"): + import dash_table as _dt + + old_dir = filter_dir(_dt) + new_dir = filter_dir(dash_table) + + assert old_dir == new_dir From 66c445b0789acce7e7d4c516d7da670d6534e120 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Tue, 16 Nov 2021 09:48:41 -0500 Subject: [PATCH 2/3] clean up some old files/scripts and refs to old packages --- components/dash-core-components/README.md | 35 ++------ components/dash-core-components/package.json | 1 - components/dash-table/CONTRIBUTING.md | 80 ------------------ components/dash-table/README.md | 9 +- components/dash-table/index.py | 87 -------------------- 5 files changed, 11 insertions(+), 201 deletions(-) delete mode 100644 components/dash-table/CONTRIBUTING.md delete mode 100644 components/dash-table/index.py diff --git a/components/dash-core-components/README.md b/components/dash-core-components/README.md index 41ca68c192..2e7f88075a 100644 --- a/components/dash-core-components/README.md +++ b/components/dash-core-components/README.md @@ -6,24 +6,19 @@ This package provides the core React component suite for [Dash][]. ## Development -The `dash` package contains some tools to build components and drive the bundles build process. -To avoid the circular dependency situation, we don't add `dash` as a required install in the `dash-core-components` setup. -But, in order to do development locally, you need to install `dash` before everything. - -1. Install the dependencies with: +This package is part of `dash`, and if you install `dash` in development mode with extras as below, you can develop in this portion as well. +From the root of the `dash` repo: ```bash -# it's recommended to install your python packages in a virtualenv -# python 2 -$ pip install virtualenv --user && virtualenv venv && . venv/bin/activate -# python 3 +# It's recommended to install your python packages in a virtualenv +# As of dash 2.0, python 3 is required $ python -m venv venv && . venv/bin/activate # make sure dash is installed with dev and testing dependencies -$ pip install dash[dev,testing] # in some shells you need \ to escape [] +$ pip install -e .[dev,testing] # in some shells you need \ to escape [] -# run the build process -$ npm i --ignore-scripts && npm run build +# run the build process - this will build all of dash, including dcc +$ npm i && npm run build # install dcc in editable mode $ pip install -e . @@ -46,22 +41,6 @@ npm test # Import dash_core_components to your layout, then run it: $ python my_dash_layout.py -## Uninstalling python package locally - -```sh -$ npm run uninstall-local -``` - -## Publishing - -There's an npm script that will handle publish, provided you have the right credentials. You can run it by running - -```sh -$ npm run publish-all -``` - -See the [Publishing New Components/Features](CONTRIBUTING.md#publishing-new-componentsfeatures) section of the Contributing guide for step-by-step instructions on publishing new components. - ## Dash Component Boilerplate See the [dash-component-boilerplate](https://github.com/plotly/dash-component-boilerplate) repo for more information. diff --git a/components/dash-core-components/package.json b/components/dash-core-components/package.json index 32be538f39..c0123f2165 100644 --- a/components/dash-core-components/package.json +++ b/components/dash-core-components/package.json @@ -23,7 +23,6 @@ "test": "run-s -c lint test:intg test:pyimport", "test:intg": "pytest --nopercyfinalize --headless tests/integration", "test:pyimport": "python -m unittest tests/test_dash_import.py", - "uninstall-local": "pip uninstall dash-core-components -y", "prebuild:js": "cp node_modules/plotly.js/dist/plotly.min.js dash_core_components_base/plotly.min.js", "build:js": "webpack --mode production", "build:backends": "dash-generate-components ./src/components dash_core_components -p package-info.json && cp dash_core_components_base/** dash_core_components/ && dash-generate-components ./src/components dash_core_components -p package-info.json --r-prefix 'dcc' --r-suggests 'dash,dashHtmlComponents,jsonlite,plotly' --jl-prefix 'dcc' && black dash_core_components", diff --git a/components/dash-table/CONTRIBUTING.md b/components/dash-table/CONTRIBUTING.md deleted file mode 100644 index b96665c014..0000000000 --- a/components/dash-table/CONTRIBUTING.md +++ /dev/null @@ -1,80 +0,0 @@ -# Contributing to Dash Table - -## Getting Started -Refer to the [readme](README.md) for installation and basic use instructions. - -## Coding Style -Please lint any Javascript / TypeScript additions with `npm run lint`. -Please lint any additions to Python code with `pylint` and `flake8`. - -## Pull Request Guidelines -Use the [GitHub flow][] when -proposing contributions to this repository (i.e. create a feature branch and -submit a PR against the master branch). - -## Developer Setup -1. Install Python 3.x (python 3 is required to run the demo apps and tests) -2. Install Node v8+ -3. Install CircleCI CLI (https://circleci.com/docs/2.0/local-cli/) - -`npm install` - -## Local Demo -### Local Server JS Example (Hot reload) -Use to verify the frontend functionality of the table during development or initial testing. This will run the example in the `/demo` directory. - -1. Run `npm run build.watch` -2. Visit [http://localhost:8080/](http://localhost:8080/) -### Local Server Review Apps -Use the review apps to verify callback functionality (note these examples are written in Python: the end-user syntax). This will run `index.py` found in the root of the directory and run the examples found in: `/tests/dash/`. To add more examples create a `.py` file in the `/tests/dash/` directory prepended with `app_` ie: `app_your_example.py`. This example will automatically get added to the example index page. -1. We recommend creating a virtual environment to install the requirements and run the examples. Create a virtual env with `virtualenv venv` and run with: `source venv/bin/activate`. -2. Run `pip install -r requirements.txt` from the root of the directory to install the requirements. -3. From the root of the directory run `gunicorn index:server` -4. Visit [http://127.0.0.1:8000](http://localhost:8000) - -## Running Tests -### Run tests locally -`npm test` -### Run tests locally with hot reload: -`npm run test.watch` -### Run tests in CircleCI CLI -`circleci build --job test` - -## Local Build -`npm run build` - -## Local Dist Build -`python setup.py sdist` - -Note: Distributable file will be located in ./dist - -## Making a Contribution -_For larger features, your contribution will have a higher likelihood of getting merged if you create an issue to discuss the changes that you'd like to make before you create a pull request._ - -1. Create a pull request. -2. After a review has been done and your changes have been approved, they will be merged and included in a future release of Dash. - -## [Checklists](http://rs.io/unreasonable-effectiveness-of-checklists/) -**Beginner tip:** _Copy and paste this section as a comment in your PR, then check off the boxes as you go!_ -### Pre-Merge checklist -- [ ] All tests on CircleCI have passed. -- [ ] All visual regression differences have been approved. -- [ ] If changes are significant, a release candidate has been created and posted to Slack, the Plotly forums, and at the very top of the pull request. -- [ ] You have added an entry describing the change at the the top of `CHANGELOG.md`. For larger additions, your `CHANGELOG.md` entry includes sample code about how the feature works. The entry should also link to the original pull request(s). -- [ ] Two Dash core contributors have :dancer:'d the pull request. - -### Post-Merge checklist -- [ ] You have deleted the branch. -- [ ] You have closed all issues that this pull request solves. -- [ ] If significant enough, you have created an issue about documenting the new feature or change and you have added it to the [dash-docs](https://github.com/plotly/dash-docs) project. - -## Financial Contributions - -Dash, and many of Plotly's open source products, have been funded through direct sponsorship by companies. [Get in touch][] about funding feature additions, consulting, or custom app development. - -[GitHub flow]: https://guides.github.com/introduction/flow/ -[semantic versioning]: https://semver.org/ -[Dash Community Forum]: https://community.plotly.com/c/dash -[Get in touch]: https://plotly.com/products/consulting-and-oem -[Documentation]: https://github.com/orgs/plotly/projects/8 -[Dash Docs]: https://github.com/plotly/dash-docs diff --git a/components/dash-table/README.md b/components/dash-table/README.md index 2db9adb7cb..2a4f3237a8 100644 --- a/components/dash-table/README.md +++ b/components/dash-table/README.md @@ -7,17 +7,16 @@ An interactive `DataTable` for [Dash](https://dash.plotly.com/). ## Quickstart ``` -pip install dash-table +pip install dash ``` ```python -import dash -import dash_table +from dash import Dash, dash_table import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv') -app = dash.Dash(__name__) +app = Dash(__name__) app.layout = dash_table.DataTable( id='table', @@ -41,7 +40,7 @@ This component was written from scratch in React.js and Typescript specifically DataTable was designed with a featureset that allows that Dash users to create complex, spreadsheet driven applications with no compromises. We're excited to continue to work with users and companies that [invest in DataTable's future](https://plotly.com/products/consulting-and-oem/). -Please subscribe to [dash-table#207](https://github.com/plotly/dash-table/issues/207) and the [CHANGELOG.md](https://github.com/plotly/dash-table/blob/master/CHANGELOG.md) to stay up-to-date with any breaking changes. Note: DataTable is currently supported in Chrome, Firefox, Safari, Edge (version 15+), and Internet Explorer 11. +Note: DataTable is currently supported in Chrome, Firefox, Safari, Edge (version 15+), and Internet Explorer 11. Share your DataTable Dash apps on the [community forum](https://community.plotly.com/t/show-and-tell-community-thread/7554)! diff --git a/components/dash-table/index.py b/components/dash-table/index.py deleted file mode 100644 index 392dc8e62f..0000000000 --- a/components/dash-table/index.py +++ /dev/null @@ -1,87 +0,0 @@ -import dash -from dash.dependencies import Input, Output -import dash_core_components as dcc -import dash_html_components as html -import dash_table -import logging -import os - - -logging.getLogger("werkzeug").setLevel(logging.ERROR) - -app = dash.Dash( - __name__, external_stylesheets=["https://codepen.io/chriddyp/pen/dZVMbK.css"] -) -app.config["suppress_callback_exceptions"] = True - -server = app.server - -apps = { - filename.replace(".py", "").replace("app_", ""): getattr( - getattr( - __import__(".".join(["tests", "integration", filename.replace(".py", "")])), - "integration", - ), - filename.replace(".py", ""), - ) - for filename in os.listdir(os.path.join("tests", "integration")) - if filename.startswith("app_") and filename.endswith(".py") -} - - -app.layout = html.Div( - children=[ - dcc.Location(id="location"), - html.Div(id="container"), - html.Div(style={"display": "none"}, children=dash_table.DataTable(id="hidden")), - ] -) - - -@app.callback(Output("container", "children"), [Input("location", "pathname")]) -def display_app(pathname): - if pathname == "/" or pathname is None: - return html.Div( - className="container", - children=[ - html.H1("Dash Table Review App"), - html.Ol( - [ - html.Li( - dcc.Link( - name.replace("app_", "").replace("_", " "), - href="/{}".format( - name.replace("app_", "").replace("_", "-") - ), - ) - ) - for name in apps - ] - ), - ], - ) - - app_name = pathname.replace("/", "").replace("-", "_") - if app_name in apps: - return html.Div( - [ - html.H3(app_name.replace("-", " ")), - html.Div(id="waitfor"), - html.Div(apps[app_name].layout()), - ] - ) - else: - return """ - App not found. - You supplied "{}" and these are the apps that exist: - {} - """.format( - app_name, list(apps.keys()) - ) - - -app.css.config.serve_locally = True -app.scripts.config.serve_locally = True - -if __name__ == "__main__": - app.run_server(debug=True) From dfdc5490ea8ed85e662bc1c02228bb1f33cf1a65 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Tue, 16 Nov 2021 10:05:08 -0500 Subject: [PATCH 3/3] changelog for old import extras and rearrange existing unreleased changelog entries --- CHANGELOG.md | 56 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0356c999f..5892f22d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] -- [#1822](https://github.com/plotly/dash/pull/1822) Remove Radium from renderer dependencies, as part of investigating React 17 support. +### Changed - [#1745](https://github.com/plotly/dash/pull/1745): Improve our `extras_require`: there are now five options here, each with a well-defined role: @@ -14,9 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - `dash[celery]`: required if you use `CeleryLongCallbackManager` - `dash[ci]`: mainly for internal use, these are additional requirements for the Dash CI tests, exposed for other component libraries to use a matching configuration. -- [#1779](https://github.com/plotly/dash/pull/1779): - - Clean up our handling of serialization problems, including fixing `orjson` for Python 3.6 - - Added the ability for `dash.testing` `percy_snapshot` methods to choose widths to generate. +### Added - [#1763](https://github.com/plotly/dash/pull/1763): ## Dash and Dash Renderer @@ -30,21 +28,21 @@ This project adheres to [Semantic Versioning](https://semver.org/). @dash.callback(Output(my_output, 'children'), Input(my_input, 'value')) def update(value): - return f'You have entered {value}' + return f'You have entered {value}' ``` Or, if using Python >=3.8 you can use the `:=` walrus operator: ```python app.layout = html.Div([ - my_input := dcc.Input(), - my_output := html.Div() + my_input := dcc.Input(), + my_output := html.Div() ]) @dash.callback(Output(my_output, 'children'), Input(my_input, 'value')) def update(value): - return f'You have entered {value}' - + return f'You have entered {value}' ``` + ## Dash Core Components ### Rearranged Keyword Arguments & Flexible Types @@ -58,22 +56,23 @@ This project adheres to [Semantic Versioning](https://semver.org/). ```python dcc.Dropdown( - options=[ - {'label': 'New York', 'value': 'New York'}, - {'label': 'Montreal', 'value': 'Montreal'}, - ], - value='New York' + options=[ + {'label': 'New York', 'value': 'New York'}, + {'label': 'Montreal', 'value': 'Montreal'}, + ], + value='New York' ) - ``` + ``` + or ```python dcc.Dropdown( - options=[ - {'label': 'New York', 'value': 'NYC'}, - {'label': 'Montreal', 'value': 'MTL'}, - ], - value='New York' + options=[ + {'label': 'New York', 'value': 'NYC'}, + {'label': 'Montreal', 'value': 'MTL'}, + ], + value='New York' ) ``` @@ -82,6 +81,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ```python dcc.Dropdown(['New York', 'Montreal'], 'New York') ``` + Or ```python @@ -102,14 +102,19 @@ This project adheres to [Semantic Versioning](https://semver.org/). ``` After: + ```python dcc.Slider(min=1, max=3, step=1) ``` + Or equivalently: + ```python dcc.Slider(1, 3, 1) ``` + Step can also be omitted and the `Slider` will attempt to create a nice, human readable step with SI units and around 5 marks: + ```python dcc.Slider(0, 100) ``` @@ -137,6 +142,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ```python dash_table.DataTable(data=df.to_dict('records'), columns=[{'name': i, 'id': i} for i in df.columns]) ``` + After: ```python @@ -153,6 +159,16 @@ This project adheres to [Semantic Versioning](https://semver.org/). dcc.Checklist(inline=True) ``` +### Fixed + +- [#1836](https://github.com/plotly/dash/pull/1836) Fix `__all__` in dcc and table for extras: dcc download helpers and table format helpers. This also restores this functionality to the obsolete top-level packages `dash_core_components` and `dash_table`. + +- [#1822](https://github.com/plotly/dash/pull/1822) Remove Radium from renderer dependencies, as part of investigating React 17 support. + +- [#1779](https://github.com/plotly/dash/pull/1779): + - Clean up our handling of serialization problems, including fixing `orjson` for Python 3.6 + - Added the ability for `dash.testing` `percy_snapshot` methods to choose widths to generate. + ## [2.0.0] - 2021-08-03 ## Dash and Dash Renderer