Skip to content
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

feat(HTML)!: HTML class no longer inherits from str #86

Merged
merged 51 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9117a8a
Expose `ReprHtml` class
schloerke Apr 22, 2024
179f103
Formatting
schloerke Apr 22, 2024
6b28049
`.get_html_string()` now returns `str` instead of `HTML`
schloerke Apr 22, 2024
991852f
Do not support `HTML` for attrs
schloerke Apr 22, 2024
7a2c188
Update `HTML` class to not inherit from `str`
schloerke Apr 22, 2024
0e2ea4b
Update CHANGELOG.md
schloerke Apr 22, 2024
ee8b640
Update checkout and setup python to latest versions
schloerke Apr 23, 2024
48037ed
Add job to check dev shiny with pypi & dev htmltools
schloerke Apr 23, 2024
8abe640
TagAttrValue and TagAttrDict now support HTML values
schloerke Apr 23, 2024
372f6b2
Make sure single child HTML or text has no white space around it
schloerke Apr 23, 2024
f25ab9c
Loosen type restriction on HTML input object
schloerke Apr 23, 2024
4876bea
bug: Return HTML text when requested
schloerke Apr 23, 2024
e6848a2
Fix failing test; JSX tagified should equal itself, now compares stri…
schloerke Apr 23, 2024
9f7bae4
Check dev Shiny w/ dev Htmltools
schloerke Apr 23, 2024
1428c97
Lints
schloerke Apr 23, 2024
05531b7
Use editable install of htmltools; Run tests before checking shiny
schloerke Apr 23, 2024
05bc8da
Add equality method to `HTML`
schloerke Apr 23, 2024
b7e2473
Fix bug where html + str resulted in str; Now it returns HTML
schloerke Apr 23, 2024
5e4443d
Update pytest.yaml
schloerke Apr 23, 2024
8d0614c
Do not allow HTML in Tag attrs
schloerke Apr 23, 2024
633466b
Remove `_html_escape` for faicons 0.2.1
schloerke Apr 23, 2024
855e46d
Update CHANGELOG.md
schloerke Apr 23, 2024
6cde017
Merge branch 'main' into html_not_str
schloerke Sep 18, 2024
4e164b1
Use `UserString` as base class for HTML
schloerke Sep 18, 2024
1b658db
lint
schloerke Sep 18, 2024
c2d4a58
Add `__radd__()` support for `HTML` to add `HTML()` to `str` objects:…
schloerke Sep 18, 2024
53334c5
Install all of shiny to get the custom version
schloerke Sep 18, 2024
6a094d2
Merge branch 'main' into html_not_str
schloerke Sep 18, 2024
016bc39
Discard changes to .vscode/settings.json
schloerke Sep 18, 2024
75bbd6a
Apply suggestions from code review; Remove unnecessary str calls
schloerke Sep 18, 2024
9ae85d9
Discard changes to htmltools/_util.py
schloerke Sep 18, 2024
f67f5dc
Add another breaking change for HTML type addition
schloerke Sep 18, 2024
4ead746
Export `is_tag_node()`, `is_tag_child()` and `consolidate_attrs()`
schloerke Sep 19, 2024
70f4e06
Update CHANGELOG.md
schloerke Sep 19, 2024
19c5eba
`add_style()` added support for receiving `HTML` objects
schloerke Sep 19, 2024
242da23
Use `isinstance(x, ReprHtml)` rather than looking for specific field
schloerke Sep 19, 2024
c2cd993
Update test_jsx_tags.py
schloerke Sep 19, 2024
d1ea0e0
Allow attr values to be HTML
schloerke Sep 19, 2024
19c4e8c
Move py-shiny testing to it's own job, away from pytest.yaml
schloerke Sep 19, 2024
90c5a84
Use shiny's `ci-install-deps` target to build faster
schloerke Sep 19, 2024
25d5558
Use dev shiny branch for faster debugging
schloerke Sep 19, 2024
3fc4b1c
Update shiny.yaml
schloerke Sep 19, 2024
88e4d78
Update shiny.yaml
schloerke Sep 19, 2024
40b7e1c
Update py-shiny dev branch to main. Use new check action from posit-d…
schloerke Sep 19, 2024
2483d2b
checkout htmltools within _dev/htmltools so that py-shiny checks will…
schloerke Sep 19, 2024
2448ede
auto accept uninstall
schloerke Sep 19, 2024
0d25a1a
Revert TagAttrDict changelog entry about not supporting HTML
schloerke Sep 19, 2024
8e0e26c
Remove outdate changelog
schloerke Sep 19, 2024
7f9bdc6
Apply suggestions from code review
schloerke Sep 19, 2024
86563dc
format comment
schloerke Sep 19, 2024
f6badbf
bump dev version to 0.5.3.9001
schloerke Sep 19, 2024
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
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
12 changes: 10 additions & 2 deletions htmltools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
__version__ = "0.5.3.9000"

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
Loading