Skip to content

Commit

Permalink
Try fixing packaging issues
Browse files Browse the repository at this point in the history
  • Loading branch information
artscoop committed Dec 28, 2023
1 parent 3dbdfb9 commit 429cc82
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "dash-htmlayout"
version = "1.0.2"
version = "1.0.3"
authors = [
{ name="Steve Kossouho", email="[email protected]" },
]
Expand All @@ -29,6 +29,12 @@ dependencies = [
[tool.hatch.build]
packages = ["src/dash", "src/dash/htmlayout"]

[tool.hatch.build.targets.sdist]
sources = ["src"]

[tool.hatch.build.targets.wheel]
sources = ["src"]

[tool.pylint.TYPECHECK]
ignored-modules= ["numpy", "lxml"]

Expand Down
14 changes: 11 additions & 3 deletions src/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,26 @@ Since the usual way to build a Dash layout does not involve making the whole HTM
```

Only HTML comments and tags backed up by a component offered by the Dash libraries would be
accepted in your document. Also, your document must have a valid root element (anything usable).
accepted in your document. Also, your document must have a valid root element (anything usable
that is not a `head`, `body`, `html`, `script`, etc. tag).

### Non-string parameters

Any parameter for a component class can be defined as a tag attribute, as long as it is a
`str`. Parameters that are not of type `str` can be provided in HTML using the following scheme:
`str`. That means that string attributes can be passed as-is.

```html
<div parameter="string only">
```

Parameters that are not of type `str` can be provided in HTML using the following scheme:

```html
<div data-parameter="python literal to evaluate" ...>
```

For example, the `Dropdown` and `Slider` components from `dash.dcc` accept some arguments that are lists or integers, like `options` and `value`. You may pass those in HTML like follows:
For example, the `Dropdown` and `Slider` components from `dash.dcc` accept some arguments that are lists or integers, like `options` and `value`. You may pass those in HTML like follows, prefixing the attribute with `data-` and putting a Python
literal in the attribute string:

```html
<dcc-slider data-value="1" data-min="0" data-max="10" data-step="5" />
Expand Down
6 changes: 3 additions & 3 deletions src/dash/htmlayout/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from importlib import import_module
from os import PathLike
from typing import Optional, Type, Any
from typing import Optional, Type, Any, Union

from dash.development.base_component import Component
from lxml import etree
Expand Down Expand Up @@ -61,7 +61,7 @@ class Builder:
# Layout root component
layout: Optional[Component] = None

def __new__(cls, *args, file: PathLike = None, **kwargs) -> "Builder":
def __new__(cls, *args, file: Union[PathLike, str] = None, **kwargs) -> "Builder":
"""
Instanciate a new LayoutBuilder object.
Expand Down Expand Up @@ -147,7 +147,7 @@ def register_library(
return True
return False

def load(self, path: PathLike) -> Component:
def load(self, path: Union[PathLike, str]) -> Component:
"""
Build a layout from an HTML file.
Expand Down
2 changes: 1 addition & 1 deletion tests/files/simple.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Comments should be properly ignored -->
<section id="content">
<dcc-dropdown data-options="['Red', 'Blue']"/>
<dcc-dropdown id="color-dropdown" data-options="['Red', 'Blue']"/>
</section>
8 changes: 6 additions & 2 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def setUpClass(cls):
pass

def test_simple_file(self):
simple_builder = Builder(file="files/simple.html")
print(simple_builder.layout)
"""Check that components are properly built from the HTML file."""
builder = Builder(file="files/simple.html")
dropdown = builder.get_component("color-dropdown")
self.assertIsNotNone(dropdown)
self.assertIsNone(builder.get_component("invalid-dropdown"))
self.assertIn("Red", dropdown.options)

def test_empty_file(self):
"""Check that the empty layout file creates no layout."""
Expand Down

0 comments on commit 429cc82

Please sign in to comment.