Skip to content

Issue 481 - Support arbitrary file extensions in component suites #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions @plotly/dash-generator-test-component-standard/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@
dict(
relative_package_path='dash_generator_test_component_standard.js',
namespace='dash_generator_test_component_standard'
),
dict(
relative_package_path='godfather.ttf',
namespace='dash_generator_test_component_standard',
dynamic=True
)
]

_css_dist = [
dict(
relative_package_path='style.css',
namespace='dash_generator_test_component_standard',
dynamic=True
)
]

for _component in __all__:
setattr(locals()[_component], '_js_dist', _js_dist)
setattr(locals()[_component], '_css_dist', _css_dist)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@font-face {
font-family: 'godfather';
src: url(./godfather.ttf) format('truetype');
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import React from 'react';
/**
* MyComponent description
*/
const MyStandardComponent = ({ id, value }) => (<div id={id}>{value}</div>);
const MyStandardComponent = ({ id, style, value }) => (<div id={id} style={style}>{value}</div>);

MyStandardComponent.propTypes = {
/**
* The id of the component
*/
id: PropTypes.string,

/**
* The style
*/
style: PropTypes.shape,

/**
* The value to display
*/
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- [#1103](https://github.com/plotly/dash/pull/1103) Pattern-matching IDs and callbacks. Component IDs can be dictionaries, and callbacks can reference patterns of components, using three different wildcards: `ALL`, `MATCH`, and `ALLSMALLER`, available from `dash.dependencies`. This lets you create components on demand, and have callbacks respond to any and all of them. To help with this, `dash.callback_context` gets three new entries: `outputs_list`, `inputs_list`, and `states_list`, which contain all the ids, properties, and except for the outputs, the property values from all matched components.
- [#1103](https://github.com/plotly/dash/pull/1103) `dash.testing` option `--pause`: after opening the dash app in a test, will invoke `pdb` for live debugging of both Javascript and Python. Use with a single test case like `pytest -k cbwc001 --pause`.
- [#1078](https://github.com/plotly/dash/pull/1078) Permit usage of arbitrary file extensions for assets within component libraries

### Changed
- [#1103](https://github.com/plotly/dash/pull/1103) Multiple changes to the callback pipeline:
Expand Down Expand Up @@ -72,7 +73,7 @@ These functions are particularly useful for apps deployed on Dash Enterprise whe

### Changed
- [#1035](https://github.com/plotly/dash/pull/1035) Simplify our build process.
- [#1074](https://github.com/plotly/dash/pull/1045) Error messages when providing an incorrect property to a component have been improved: they now specify the component type, library, version, and ID (if available).
- [#1074](https://github.com/plotly/dash/pull/1074) Error messages when providing an incorrect property to a component have been improved: they now specify the component type, library, version, and ID (if available).

### Fixed
- [#1037](https://github.com/plotly/dash/pull/1037) Fix no_update test to allow copies, such as those stored and retrieved from a cache.
Expand Down
13 changes: 6 additions & 7 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
import re
import logging
import mimetypes

from functools import wraps

Expand Down Expand Up @@ -45,6 +46,9 @@
from . import _validate
from . import _watch

# Add explicit mapping for map files
mimetypes.add_type("application/json", ".map", True)

_default_index = """<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -669,13 +673,8 @@ def serve_component_suites(self, package_name, fingerprinted_path):

_validate.validate_js_path(self.registered_paths, package_name, path_in_pkg)

mimetype = (
{
"js": "application/javascript",
"css": "text/css",
"map": "application/json",
}
)[path_in_pkg.split(".")[-1]]
extension = "." + path_in_pkg.split(".")[-1]
mimetype = mimetypes.types_map.get(extension, "application/octet-stream")

package = sys.modules[package_name]
self.logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion dash/development/_r_components_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def write_js_metadata(pkg_data, project_shortname, has_wildcards):
for filename in filenames:
extension = os.path.splitext(filename)[1]

if extension not in [".css", ".js", ".map"]:
if extension in [".py", ".pyc", ".json"]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pick up everything but the Python artifacts

continue

target_dirname = os.path.join(
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ def test_gene001_simple_callback(dash_duo):

assert dash_duo.wait_for_element("#standard").text == "Standard"
assert dash_duo.wait_for_element("#nested").text == "Nested"

dash_duo.percy_snapshot(name="gene001-simple-callback")


def test_gene002_arbitrary_resources(dash_duo):
app = Dash(__name__)

app.layout = Div(
[
MyStandardComponent(
id="standard", value="Standard", style={"font-family": "godfather"}
)
]
)

dash_duo.start_server(app)

assert dash_duo.wait_for_element("#standard").text == "Standard"

dash_duo.percy_snapshot(name="gene002-arbitrary-resource")