Skip to content

Commit 621c82f

Browse files
committed
Update to tidy-html5 v5.7.45
1 parent 131d841 commit 621c82f

File tree

13 files changed

+164
-15
lines changed

13 files changed

+164
-15
lines changed

.github/workflows/build_wheels.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build wheels
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
os:
7+
description: OS
8+
required: true
9+
default: ubuntu-20.04
10+
python:
11+
description: Python
12+
required: true
13+
default: 3.8
14+
manylinux:
15+
description: Manylinux
16+
required: true
17+
default: manylinux2014
18+
19+
jobs:
20+
build_wheels:
21+
name: Build compat:${{ github.event.inputs.manylinux }}, python:${{ github.event.inputs.python }}, os:${{ github.event.inputs.os }}
22+
runs-on: ${{ github.event.inputs.os }}
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
with:
27+
submodules: true
28+
29+
- name: Cache pip
30+
uses: actions/cache@v2
31+
with:
32+
key: cache--${{ github.event.inputs.os }}--${{ github.event.inputs.python }}--${{ hashFiles('./requirements.txt') }}
33+
path: ~/.cache/pip
34+
35+
- uses: actions/setup-python@v2
36+
name: Install Python
37+
38+
- name: Setup python
39+
uses: actions/setup-python@v2
40+
with:
41+
python-version: ${{ github.event.inputs.python }}
42+
43+
- name: Update pip
44+
run: python -m pip install -U pip wheel setuptools
45+
46+
- name: Install requirements
47+
run: python -m pip install -Ur requirements.txt
48+
49+
- name: Convert Cython code
50+
run: make _pytidyhtml5.cpp
51+
52+
- name: Build wheels
53+
run: python -m cibuildwheel --output-dir wheelhouse
54+
env:
55+
CIBW_BEFORE_ALL: make tidy-html5/build/cmake/libtidys.a
56+
CIBW_SKIP: "cp27-* pp27-* cp35-* pp35-*" # skip Python 2.7 & 3.5 wheels
57+
CIBW_MANYLINUX_X86_64_IMAGE: ${{ github.event.inputs.manylinux }}
58+
CIBW_MANYLINUX_I686_IMAGE: ${{ github.event.inputs.manylinux }}
59+
60+
- name: Store artifacts
61+
uses: actions/upload-artifact@v2
62+
with:
63+
name: Wheelhouse
64+
path: ./wheelhouse/*.whl

.gitmodules

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[submodule "tidy-html5"]
22
path = tidy-html5
3-
url = https://github.com/htacg/tidy-html5.git
4-
branch = 3a30f6a4300417674026f6dddea5973debc6b808
3+
url = git://github.com/htacg/tidy-html5.git

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ all: sdist bdist_wheel docs
44

55
NAME := pytidyhtml5
66

7-
.PHONY: all sdist bdist_wheel clean docs
7+
.PHONY: all sdist bdist_wheel clean docs prepare
88

99
FILES := Makefile MANIFEST.in _${NAME}.pyx README.rst setup.py \
10-
lib/native.hpp lib/VERSION
10+
lib/native.hpp lib/VERSION tidy-html5/build/cmake/libtidys.a
1111

1212

1313
TIDY_CFLAGS := -O2 -fomit-frame-pointer -flto
@@ -45,13 +45,15 @@ tidy-html5/build/cmake/libtidys.a: | tidy-html5/.git
4545

4646
$(RANLIB) $@
4747

48-
lib/_import_tidy_enum.pyx: tidy-html5/build/cmake/libtidys.a
48+
lib/_import_tidy_enum.pyx:
4949
./generate_imports.py
5050

51-
_${NAME}.cpp: _${NAME}.pyx $(wildcard lib/*.pyx) lib/_import_tidy_enum.pyx
52-
rm -f -- dist/*.so _${NAME}.cpp
53-
rm -f ./_${NAME}.cpp
54-
cythonize -f $<
51+
_${NAME}.cpp: _${NAME}.pyx $(wildcard lib/*.pyx) | lib/_import_tidy_enum.pyx
52+
-rm -- dist/*.so
53+
-rm ./_${NAME}.cpp
54+
python -m Cython.Build.Cythonize -f $<
55+
56+
prepare: _${NAME}.cpp ${FILES}
5557

5658
sdist: _${NAME}.cpp ${FILES}
5759
rm -f -- dist/${NAME}-*.tar.gz
@@ -68,6 +70,7 @@ docs: bdist_wheel $(wildcard docs/* docs/*/*)
6870
python -m sphinx -M html docs/ dist/
6971

7072
clean:
73+
-rm -- _${NAME}.cpp
7174
-rm -- ./lib/_import_tidy_enum.pyx
7275
-rm -- ./lib/_tidy_enum.pyx
7376
-rm -r -- ./build/

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
PyTidyHTML5
22
===========
3+
4+
HTML clean-up and repair: Statically linked Python interface for [tidy-html5](https://github.com/htacg/tidy-html5).

lib/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"2020.7.17.post1"
1+
"2021.1.11"

lib/_import_tidy_enum.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ cdef extern from 'tidyenum.h' nogil:
117117
const TidyAttrId TidyAttr_CODEBASE
118118
const TidyAttrId TidyAttr_CODETYPE
119119
const TidyAttrId TidyAttr_COLOR
120+
const TidyAttrId TidyAttr_COLORINTERPOLATION
121+
const TidyAttrId TidyAttr_COLORRENDERING
120122
const TidyAttrId TidyAttr_COLS
121123
const TidyAttrId TidyAttr_COLSPAN
122124
const TidyAttrId TidyAttr_COMPACT
@@ -149,6 +151,9 @@ cdef extern from 'tidyenum.h' nogil:
149151
const TidyAttrId TidyAttr_ENCTYPE
150152
const TidyAttrId TidyAttr_EVENT
151153
const TidyAttrId TidyAttr_FACE
154+
const TidyAttrId TidyAttr_FILL
155+
const TidyAttrId TidyAttr_FILLOPACITY
156+
const TidyAttrId TidyAttr_FILLRULE
152157
const TidyAttrId TidyAttr_FOR
153158
const TidyAttrId TidyAttr_FORM
154159
const TidyAttrId TidyAttr_FORMACTION
@@ -190,6 +195,7 @@ cdef extern from 'tidyenum.h' nogil:
190195
const TidyAttrId TidyAttr_LEFTMARGIN
191196
const TidyAttrId TidyAttr_LINK
192197
const TidyAttrId TidyAttr_LIST
198+
const TidyAttrId TidyAttr_LOADING
193199
const TidyAttrId TidyAttr_LONGDESC
194200
const TidyAttrId TidyAttr_LOOP
195201
const TidyAttrId TidyAttr_LOW
@@ -213,6 +219,7 @@ cdef extern from 'tidyenum.h' nogil:
213219
const TidyAttrId TidyAttr_NOVALIDATE
214220
const TidyAttrId TidyAttr_NOWRAP
215221
const TidyAttrId TidyAttr_OBJECT
222+
const TidyAttrId TidyAttr_OPACITY
216223
const TidyAttrId TidyAttr_OPEN
217224
const TidyAttrId TidyAttr_OPTIMUM
218225
const TidyAttrId TidyAttr_OnABORT
@@ -331,6 +338,7 @@ cdef extern from 'tidyenum.h' nogil:
331338
const TidyAttrId TidyAttr_SHOWGRIDY
332339
const TidyAttrId TidyAttr_SIZE
333340
const TidyAttrId TidyAttr_SIZES
341+
const TidyAttrId TidyAttr_SLOT
334342
const TidyAttrId TidyAttr_SPAN
335343
const TidyAttrId TidyAttr_SPELLCHECK
336344
const TidyAttrId TidyAttr_SRC
@@ -340,6 +348,14 @@ cdef extern from 'tidyenum.h' nogil:
340348
const TidyAttrId TidyAttr_STANDBY
341349
const TidyAttrId TidyAttr_START
342350
const TidyAttrId TidyAttr_STEP
351+
const TidyAttrId TidyAttr_STROKE
352+
const TidyAttrId TidyAttr_STROKEDASHARRAY
353+
const TidyAttrId TidyAttr_STROKEDASHOFFSET
354+
const TidyAttrId TidyAttr_STROKELINECAP
355+
const TidyAttrId TidyAttr_STROKELINEJOIN
356+
const TidyAttrId TidyAttr_STROKEMITERLIMIT
357+
const TidyAttrId TidyAttr_STROKEOPACITY
358+
const TidyAttrId TidyAttr_STROKEWIDTH
343359
const TidyAttrId TidyAttr_STYLE
344360
const TidyAttrId TidyAttr_SUMMARY
345361
const TidyAttrId TidyAttr_TABINDEX
@@ -682,6 +698,7 @@ cdef extern from 'tidyenum.h' nogil:
682698
const TidyTagId TidyTag_SELECT
683699
const TidyTagId TidyTag_SERVER
684700
const TidyTagId TidyTag_SERVLET
701+
const TidyTagId TidyTag_SLOT
685702
const TidyTagId TidyTag_SMALL
686703
const TidyTagId TidyTag_SOURCE
687704
const TidyTagId TidyTag_SPACER

lib/_imports.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ cdef extern from 'native.hpp' namespace 'PyTidyHtml5' nogil:
7171
PyObject **ref_document[Cls](PyObject *self)
7272
Out _reinterpret_cast[Out, In](In ptr)
7373
int call_bool_fn_1(object fn, object arg1)
74+
void reset_hash[T](T *obj)
7475

7576
ctypedef boolean AlwaysTrue
7677

lib/_output_buffer.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ cdef class StringBuffer(Buffer):
141141
result = <object> <PyObject*> ObjectInitVar(
142142
(<PyVarObject*> self.tidy_buffer.bp), bytes, length,
143143
)
144-
(<PyBytesObject*> result).ob_shash = -1
144+
reset_hash(<PyBytesObject*> result)
145145

146146
else:
147147
s = &(<signed char*> self.tidy_buffer.bp)[start]
@@ -199,7 +199,7 @@ cdef class StringBuffer(Buffer):
199199
result = ObjectInit(<PyObject*> self.tidy_buffer.bp, unicode)
200200

201201
(<PyASCIIObject*> result).length = length
202-
(<PyASCIIObject*> result).hash = -1
202+
reset_hash(<PyASCIIObject*> result)
203203
(<PyASCIIObject*> result).wstr = NULL
204204
(<PyASCIIObject*> result).state.interned = SSTATE_NOT_INTERNED
205205
(<PyASCIIObject*> result).state.kind = PyUnicode_1BYTE_KIND

lib/_tidy_enum.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ _AttrId = IntEnum('AttrId', {
165165
'codebase': <unsigned int> TidyAttr_CODEBASE,
166166
'codetype': <unsigned int> TidyAttr_CODETYPE,
167167
'color': <unsigned int> TidyAttr_COLOR,
168+
'colorinterpolation': <unsigned int> TidyAttr_COLORINTERPOLATION,
169+
'colorrendering': <unsigned int> TidyAttr_COLORRENDERING,
168170
'cols': <unsigned int> TidyAttr_COLS,
169171
'colspan': <unsigned int> TidyAttr_COLSPAN,
170172
'compact': <unsigned int> TidyAttr_COMPACT,
@@ -197,6 +199,9 @@ _AttrId = IntEnum('AttrId', {
197199
'enctype': <unsigned int> TidyAttr_ENCTYPE,
198200
'event': <unsigned int> TidyAttr_EVENT,
199201
'face': <unsigned int> TidyAttr_FACE,
202+
'fill': <unsigned int> TidyAttr_FILL,
203+
'fillopacity': <unsigned int> TidyAttr_FILLOPACITY,
204+
'fillrule': <unsigned int> TidyAttr_FILLRULE,
200205
'for_': <unsigned int> TidyAttr_FOR,
201206
'form': <unsigned int> TidyAttr_FORM,
202207
'formaction': <unsigned int> TidyAttr_FORMACTION,
@@ -238,6 +243,7 @@ _AttrId = IntEnum('AttrId', {
238243
'leftmargin': <unsigned int> TidyAttr_LEFTMARGIN,
239244
'link': <unsigned int> TidyAttr_LINK,
240245
'list': <unsigned int> TidyAttr_LIST,
246+
'loading': <unsigned int> TidyAttr_LOADING,
241247
'longdesc': <unsigned int> TidyAttr_LONGDESC,
242248
'loop': <unsigned int> TidyAttr_LOOP,
243249
'low': <unsigned int> TidyAttr_LOW,
@@ -261,6 +267,7 @@ _AttrId = IntEnum('AttrId', {
261267
'novalidate': <unsigned int> TidyAttr_NOVALIDATE,
262268
'nowrap': <unsigned int> TidyAttr_NOWRAP,
263269
'object': <unsigned int> TidyAttr_OBJECT,
270+
'opacity': <unsigned int> TidyAttr_OPACITY,
264271
'open': <unsigned int> TidyAttr_OPEN,
265272
'optimum': <unsigned int> TidyAttr_OPTIMUM,
266273
'on_abort': <unsigned int> TidyAttr_OnABORT,
@@ -379,6 +386,7 @@ _AttrId = IntEnum('AttrId', {
379386
'showgridy': <unsigned int> TidyAttr_SHOWGRIDY,
380387
'size': <unsigned int> TidyAttr_SIZE,
381388
'sizes': <unsigned int> TidyAttr_SIZES,
389+
'slot': <unsigned int> TidyAttr_SLOT,
382390
'span': <unsigned int> TidyAttr_SPAN,
383391
'spellcheck': <unsigned int> TidyAttr_SPELLCHECK,
384392
'src': <unsigned int> TidyAttr_SRC,
@@ -388,6 +396,14 @@ _AttrId = IntEnum('AttrId', {
388396
'standby': <unsigned int> TidyAttr_STANDBY,
389397
'start': <unsigned int> TidyAttr_START,
390398
'step': <unsigned int> TidyAttr_STEP,
399+
'stroke': <unsigned int> TidyAttr_STROKE,
400+
'strokedasharray': <unsigned int> TidyAttr_STROKEDASHARRAY,
401+
'strokedashoffset': <unsigned int> TidyAttr_STROKEDASHOFFSET,
402+
'strokelinecap': <unsigned int> TidyAttr_STROKELINECAP,
403+
'strokelinejoin': <unsigned int> TidyAttr_STROKELINEJOIN,
404+
'strokemiterlimit': <unsigned int> TidyAttr_STROKEMITERLIMIT,
405+
'strokeopacity': <unsigned int> TidyAttr_STROKEOPACITY,
406+
'strokewidth': <unsigned int> TidyAttr_STROKEWIDTH,
391407
'style': <unsigned int> TidyAttr_STYLE,
392408
'summary': <unsigned int> TidyAttr_SUMMARY,
393409
'tabindex': <unsigned int> TidyAttr_TABINDEX,
@@ -1188,6 +1204,7 @@ _TagId = IntEnum('TagId', {
11881204
'select': <unsigned int> TidyTag_SELECT,
11891205
'server': <unsigned int> TidyTag_SERVER,
11901206
'servlet': <unsigned int> TidyTag_SERVLET,
1207+
'slot': <unsigned int> TidyTag_SLOT,
11911208
'small': <unsigned int> TidyTag_SMALL,
11921209
'source': <unsigned int> TidyTag_SOURCE,
11931210
'spacer': <unsigned int> TidyTag_SPACER,

lib/native.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,49 @@ int call_bool_fn_1(PyObject *fn, PyObject *arg1) {
132132
return truthy;
133133
}
134134

135+
136+
template <typename T>
137+
struct has_ob_shash {
138+
template <typename C> static std::uint8_t test(decltype(&C::ob_shash)) ;
139+
template <typename C> static std::uint64_t test(...);
140+
enum { value = sizeof(test<T>(0)) == sizeof(std::uint8_t) };
141+
};
142+
143+
template <typename T>
144+
struct has_hash {
145+
template <typename C> static std::uint8_t test(decltype(&C::hash)) ;
146+
template <typename C> static std::uint64_t test(...);
147+
enum { value = sizeof(test<T>(0)) == sizeof(std::uint8_t) };
148+
};
149+
150+
template<class T, bool ob_shash = has_ob_shash<T>::value, bool hash = has_hash<T>::value>
151+
struct ResetHash_;
152+
153+
template<class T>
154+
struct ResetHash_ <T, true, false> {
155+
static inline void reset(T *obj) {
156+
obj->ob_shash = -1; // CPython: str
157+
}
158+
};
159+
160+
template<class T>
161+
struct ResetHash_ <T, false, true> {
162+
static inline void reset(T *obj) {
163+
obj->hash = -1; // CPython: bytes
164+
}
165+
};
166+
167+
template<class T>
168+
struct ResetHash_ <T, false, false> {
169+
static inline void reset(T *obj) {
170+
(void) 0; // PyPy
171+
}
172+
};
173+
174+
template <class T>
175+
static inline void reset_hash(T *obj) {
176+
ResetHash_<T>::reset(obj);
177+
}
178+
135179
}
136180
}

0 commit comments

Comments
 (0)