Skip to content

Commit

Permalink
feat(HTML)!: HTML class no longer inherits from str (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Carson Sievert <[email protected]>
Co-authored-by: Winston Chang <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent 1857415 commit 81e0749
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 54 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
shell: bash

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -39,16 +39,15 @@ jobs:
- name: pyright, flake8, black and isort
run: |
make check
deploy:
name: "Deploy to PyPI"
runs-on: ubuntu-latest
if: github.event_name == 'release'
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: "Set up Python 3.10"
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/shiny.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Bleeding Edge Shiny

on:
push:
branches: "shiny-**"
pull_request:

jobs:
htmltools-pr:
runs-on: ubuntu-latest
defaults:
run:
shell: bash

steps:
- name: Checkout py-shiny@main
uses: actions/checkout@v4
with:
repository: posit-dev/py-shiny
ref: main
fetch-depth: 0 # Required for shiny version
- name: Setup py-shiny@main
uses: posit-dev/py-shiny/.github/py-shiny/setup@main
with:
python-version: "3.12"

- name: Checkout dev branch of py-htmltools
uses: actions/checkout@v4
with:
path: _dev/htmltools

- name: Install dev py-htmltools htmltools dependencies
run: |
cd _dev/htmltools
pip uninstall -y htmltools
pip install -e ".[dev,test]"
make install
- name: Check py-shiny@main
uses: posit-dev/py-shiny/.github/py-shiny/check@main
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@ All notable changes to htmltools for Python will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED]
## [Unreleased] YYYY-MM-DD

### Breaking changes

* `HTML` no longer inherits from `str`. It now inherits from `collections.UserString`. This was done to avoid confusion between `str` and `HTML` objects. (#86)

* `Tag` and `TagList`'s method `.get_html_string()` now both return `str` instead of `HTML`. (#86)

* Strings added to `HTML` objects, now return `HTML` objects. E.g. `HTML_value + str_value` and `str_value_ + HTML_value` both return `HTML` objects. To maintain a `str` result, call `str()` on your `HTML` objects before adding them to strings. (#86)

### New features

* Exported `ReprHtml` protocol class. If an object has a `_repr_html_` method, then it is of instance `ReprHtml`. (#86)

* Exported `is_tag_node()` and `is_tag_child()` functions that utilize `typing.TypeIs` to narrow `TagNode` and `TagChild` type variables, respectively. (#86)

* Exported `consolidate_attrs(*args, **kwargs)` function. This function will combine the `TagAttrs` (supplied in `*args`) with `TagAttrValues` (supplied in `**kwargs`) into a single `TagAttrs` object. In addition, it will also return all `*args` that are not dictionary as a list of unaltered `TagChild` objects. (#86)

* The `Tag` method `.add_style(style=)` added support for `HTML` objects in addition to `str` values. (#86)

### Bug fixes

* Fixed an issue with `HTMLTextDocument()` returning extracted `HTMLDependency()`s in a non-determistic order. (#95)

Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ check: pyright lint ## check code quality with pyright, flake8, black and isort
black --check .
echo "Sorting imports with isort."
isort --check-only --diff .

check-fix: ## check/fix code quality with pyright, flake8, black and isort
@echo "Fixing code with black."
black .
@echo "Sorting imports with isort."
isort .
$(MAKE) pyright lint
14 changes: 11 additions & 3 deletions htmltools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
__version__ = "0.5.3.9000"
__version__ = "0.5.3.9001"

from . import svg, tags
from ._core import TagAttrArg # pyright: ignore[reportUnusedImport] # noqa: F401
from ._core import TagChildArg # pyright: ignore[reportUnusedImport] # noqa: F401
from ._core import TagAttrArg # pyright: ignore[reportUnusedImport] # noqa: F401
from ._core import TagChildArg # pyright: ignore[reportUnusedImport] # noqa: F401
from ._core import (
HTML,
HTMLDependency,
HTMLDocument,
HTMLTextDocument,
MetadataNode,
RenderedHTML,
ReprHtml,
Tag,
TagAttrs,
TagAttrValue,
Expand All @@ -18,7 +19,10 @@
Tagifiable,
TagList,
TagNode,
consolidate_attrs,
head_content,
is_tag_child,
is_tag_node,
wrap_displayhook_handler,
)
from ._util import css, html_escape
Expand Down Expand Up @@ -59,7 +63,11 @@
"Tagifiable",
"TagList",
"TagNode",
"ReprHtml",
"consolidate_attrs",
"head_content",
"is_tag_child",
"is_tag_node",
"wrap_displayhook_handler",
"css",
"html_escape",
Expand Down
Loading

0 comments on commit 81e0749

Please sign in to comment.