From 1e04450a4c75b8b8c1511a6225e46a94a45a562a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 16 Jan 2022 17:57:56 +0000 Subject: [PATCH 1/7] Add GHA scripts --- .github/workflows/linting.yml | 20 +++++++++ .github/workflows/test.yml | 35 +++++++++++++++ docutils/.flake8 | 85 +++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 .github/workflows/linting.yml create mode 100644 .github/workflows/test.yml create mode 100644 docutils/.flake8 diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 000000000..0b5435fea --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,20 @@ +name: 🎨 linting + +on: [push, pull_request] + +jobs: + linting: + name: lint using flake8 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3 + - name: Install dependencies + run: pip install flake8 + - name: Run flake8 + run: | + cd docutils + flake8 docutils diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..ea0be727f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: ✅ tests #and coverage + +on: [push, pull_request] + +jobs: + tests: + name: test with Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11-dev" + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + cd docutils + python -m pip install --upgrade pip + python -m pip install -e . + python -m pip install pygments + + - name: Run test suite + run: | + cd docutils + python test/alltests.py diff --git a/docutils/.flake8 b/docutils/.flake8 new file mode 100644 index 000000000..d40602322 --- /dev/null +++ b/docutils/.flake8 @@ -0,0 +1,85 @@ +[flake8] +# The following rules are ignored as they're stylistic and can be addressed at +# a later point: +# +# E101 indentation contains mixed spaces and tabs +# E111 indentation is not a multiple of four +# E114 indentation is not a multiple of four (comment) +# E115 expected an indented block (comment) +# E116 unexpected indentation (comment) +# E117 over-indented +# E121 continuation line under-indented for hanging indent +# E122 continuation line missing indentation or outdented +# E123 closing bracket does not match indentation of opening bracket's line +# E124 closing bracket does not match visual indentation +# E125 continuation line with same indent as next logical line +# E126 continuation line over-indented for hanging indent +# E127 continuation line over-indented for visual indent +# E128 continuation line under-indented for visual indent +# E129 visually indented line with same indent as next logical line +# E131 continuation line unaligned for hanging indent +# E201 whitespace after '(' +# E202 whitespace before '}' +# E203 whitespace before ':' +# E211 whitespace before '(' +# E221 multiple spaces before operator +# E222 multiple spaces after operator +# E225 missing whitespace around operator +# E226 missing whitespace around arithmetic operator +# E228 missing whitespace around modulo operator +# E231 missing whitespace after ',' +# E241 multiple spaces after ':' +# E251 unexpected spaces around keyword / parameter equals +# E261 at least two spaces before inline comment +# E262 inline comment should start with '# ' +# E265 block comment should start with '# ' +# E266 too many leading '#' for block comment +# E271 multiple spaces after keyword +# E301 expected 1 blank line, found 0 +# E302 expected 2 blank lines, found 1 +# E303 too many blank lines (N) +# E305 expected 2 blank lines after class or function definition, found 1 +# E306 expected 1 blank line before a nested definition, found 0 +# E401 multiple imports on one line +# E402 module level import not at top of file +# E501 line too long (N > 79 characters) +# E502 the backslash is redundant between brackets +# E701 multiple statements on one line (colon) +# E704 multiple statements on one line (def) +# E711 comparison to None should be 'if cond is not None:' +# E713 test for membership should be 'not in' +# E721 do not compare types, use 'isinstance()' +# E722 do not use bare 'except' +# E731 do not assign a lambda expression, use a def +# E741 ambiguous variable name 'a' +# W191 indentation contains tabs +# W291 trailing whitespace +# W293 blank line contains whitespace +# W391 blank line at end of file +# W503 line break before binary operator +# W504 line break after binary operator +# F401 'foo' imported but unused +# F841 local variable 'foo' is assigned to but never used +# +# The following rules are required for Python 3 support and so are not +# disabled +# +# W605 invalid escape sequence '\ ' +# W601 .has_key() is deprecated, use 'in' +# W602 deprecated form of raising exception +# F811 redefinition of unused 'foo' from line 79 +# +# Similarly, the following are straight up bugs that should be addressed +# immediately: +# +# E999 SyntaxError: invalid syntax +# F404 from __future__ imports must occur at the beginning of the file +# F821 undefined name 'foo' +ignore = E101,E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E222,E225,E226,E228,E231,E241,E251,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E401,E402,E501,E502,E701,E704,E711,E713,E721,E722,E731,E741,W191,W291,W293,W391,W503,W504,W605,F401,F841 +exclude = .venv,.tox,dist,*egg,build +max-complexity = 35 +# Some rules are disabled for specific files (requires flake8 3.7.0) +# +# F821, disabled due to use of 'settings_overrides' +per-file-ignores = + docutils/test/functional/tests/*:F821 From 01026cadd160f7a6ed7259cc9f6b55edb4a78dd7 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 21 Jan 2022 18:57:35 +0000 Subject: [PATCH 2/7] Restore combining marks --- docutils/docutils/utils/math/math2html.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docutils/docutils/utils/math/math2html.py b/docutils/docutils/utils/math/math2html.py index 84f4e064b..2cc478c9c 100755 --- a/docutils/docutils/utils/math/math2html.py +++ b/docutils/docutils/utils/math/math2html.py @@ -176,17 +176,17 @@ class FormulaConfig: } combiningfunctions = { - "\\'": '', - '\\"': '', - '\\^': '', - '\\`': '', - '\\~': '', - '\\c': '', - '\\r': '', - '\\s': '', - '\\textcircled': '', - '\\textsubring': '', - '\\v': '', + "\\'": '́', + '\\"': '̈', + '\\^': '̂', + '\\`': '̀', + '\\~': '̃', + '\\c': '̧', + '\\r': '̊', + '\\s': 'ĚŠ', + '\\textcircled': '⃝', + '\\textsubring': 'ĚĽ', + '\\v': '̌', } for key, value in tex2unichar.mathaccent.items(): combiningfunctions['\\'+key] = value From 1f2dd148da107cb84032a7a0a49f461ee3f17e2a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 21 Jan 2022 19:00:11 +0000 Subject: [PATCH 3/7] Restore removed `u` characters --- docutils/docutils/utils/math/tex2unichar.py | 6 +++--- docutils/docutils/utils/math/unichar2tex.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docutils/docutils/utils/math/tex2unichar.py b/docutils/docutils/utils/math/tex2unichar.py index 46d295086..f266b8614 100644 --- a/docutils/docutils/utils/math/tex2unichar.py +++ b/docutils/docutils/utils/math/tex2unichar.py @@ -61,15 +61,15 @@ 'jmath': '\u0237', # ȡ LATIN SMALL LETTER DOTLESS J 'kappa': '\u03ba', # Îş GREEK SMALL LETTER KAPPA 'lambda': '\u03bb', # Îť GREEK SMALL LETTER LAMDA - 'm': '\u03bc', # Îź GREEK SMALL LETTER MU - 'n': '\u03bd', # ν GREEK SMALL LETTER NU + 'mu': '\u03bc', # Îź GREEK SMALL LETTER MU + 'nu': '\u03bd', # ν GREEK SMALL LETTER NU 'omega': '\u03c9', # ω GREEK SMALL LETTER OMEGA 'phi': '\u03d5', # ϕ GREEK PHI SYMBOL 'pi': '\u03c0', # π GREEK SMALL LETTER PI 'psi': '\u03c8', # ψ GREEK SMALL LETTER PSI 'rho': '\u03c1', # ρ GREEK SMALL LETTER RHO 'sigma': '\u03c3', # σ GREEK SMALL LETTER SIGMA - 'ta': '\u03c4', # τ GREEK SMALL LETTER TAU + 'tau': '\u03c4', # τ GREEK SMALL LETTER TAU 'theta': '\u03b8', # θ GREEK SMALL LETTER THETA 'upsilon': '\u03c5', # υ GREEK SMALL LETTER UPSILON 'varDelta': '\U0001d6e5', # 𝛥 MATHEMATICAL ITALIC CAPITAL DELTA diff --git a/docutils/docutils/utils/math/unichar2tex.py b/docutils/docutils/utils/math/unichar2tex.py index b4fb83348..da1f828af 100644 --- a/docutils/docutils/utils/math/unichar2tex.py +++ b/docutils/docutils/utils/math/unichar2tex.py @@ -500,7 +500,7 @@ 0x1d445: 'R', 0x1d446: 'S', 0x1d447: 'T', -0x1d448: '', +0x1d448: 'U', 0x1d449: 'V', 0x1d44a: 'W', 0x1d44b: 'X', @@ -525,7 +525,7 @@ 0x1d45f: 'r', 0x1d460: 's', 0x1d461: 't', -0x1d462: '', +0x1d462: 'u', 0x1d463: 'v', 0x1d464: 'w', 0x1d465: 'x', From 18798b13daadc633903409ee5473c8a438094f80 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 26 Jan 2022 23:25:12 +0000 Subject: [PATCH 4/7] s/u'/'/ --- docutils/docs/user/smartquotes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docutils/docs/user/smartquotes.txt b/docutils/docs/user/smartquotes.txt index a186501ad..97536639c 100644 --- a/docutils/docs/user/smartquotes.txt +++ b/docutils/docs/user/smartquotes.txt @@ -263,7 +263,7 @@ There is built-in support for the following languages:\ [#smartquotes-locales]_ "'Dutch' alternative quotes" - .. # 'nl-x-altquot2': u'””’’', + .. # 'nl-x-altquot2': '””’’', :pl: .. class:: language-pl @@ -337,7 +337,7 @@ There is built-in support for the following languages:\ [#smartquotes-locales]_ "'Turkish' alternative quotes" -.. 'tr-x-altquot2': u'“„‘‚', # antiquated? +.. 'tr-x-altquot2': '“„‘‚', # antiquated? :uk: .. class:: language-uk From 7b57ba1c9e603d060db6a2d4dbd548d1df79e9a7 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 22 Jan 2022 17:33:12 +0000 Subject: [PATCH 5/7] Make dictionary copying explict --- docutils/docutils/writers/html4css1/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index 6548d0677..a8355bbb5 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -156,7 +156,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): ' content="application/xhtml+xml; charset=%s" />\n') # encode also non-breaking space - special_characters = dict(_html_base.HTMLTranslator.special_characters) + special_characters = _html_base.HTMLTranslator.special_characters.copy() special_characters[0xa0] = ' ' # use character reference for dash (not valid in HTML5) From 11c640ad238b46d21db757d2b505d8e12a23efcd Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 25 Jan 2022 21:53:07 +0000 Subject: [PATCH 6/7] Remove redundant parentheses --- docutils/docutils/writers/_html_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py index a71714482..53c5d42a5 100644 --- a/docutils/docutils/writers/_html_base.py +++ b/docutils/docutils/writers/_html_base.py @@ -1247,11 +1247,11 @@ def visit_math(self, node, math_env=''): self.document.reporter) elif converter == 'blahtexml': math_code = tex2mathml_extern.blahtexml(math_code, - inline=not(math_env), - reporter=self.document.reporter) + inline=not math_env, + reporter=self.document.reporter) elif not converter: math_code = latex2mathml.tex2mathml(math_code, - inline=not(math_env)) + inline=not math_env) else: self.document.reporter.error('option "%s" not supported ' 'with math-output "MathML"') From 29e124653663504aa46a039448bebca8610867e4 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 22 Jan 2022 17:41:50 +0000 Subject: [PATCH 7/7] Generator expression for str.join --- docutils/docutils/nodes.py | 12 ++++++------ docutils/docutils/parsers/rst/directives/misc.py | 4 ++-- docutils/docutils/utils/smartquotes.py | 10 ---------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index 8a0154eb4..efb34940a 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -603,9 +603,9 @@ def endtag(self): return '' % self.tagname def emptytag(self): - return '<%s/>' % ' '.join([self.tagname] + - ['%s="%s"' % (n, v) - for n, v in self.attlist()]) + return '<%s/>' % ' '.join((self.tagname, + *('%s="%s"' % (n, v) + for n, v in self.attlist()))) def __len__(self): return len(self.children) @@ -1045,9 +1045,9 @@ def first_child_not_matching_class(self, childclass, start=0, return None def pformat(self, indent=' ', level=0): - return ''.join(['%s%s\n' % (indent * level, self.starttag())] + - [child.pformat(indent, level+1) - for child in self.children]) + return ''.join(('%s%s\n' % (indent * level, self.starttag()), + *(child.pformat(indent, level+1) + for child in self.children))) def copy(self): obj = self.__class__(rawsource=self.rawsource, **self.attributes) diff --git a/docutils/docutils/parsers/rst/directives/misc.py b/docutils/docutils/parsers/rst/directives/misc.py index 63bd7009a..67e15c933 100644 --- a/docutils/docutils/parsers/rst/directives/misc.py +++ b/docutils/docutils/parsers/rst/directives/misc.py @@ -176,8 +176,8 @@ def run(self): (None, None, None, None))) if (path, clip_options) in include_log: raise self.warning('circular inclusion in "%s" directive: %s' - % (self.name, ' < '.join([path] + [pth for (pth, opt) - in include_log[::-1]]))) + % (self.name, ' < '.join((path, *(pth for pth, opt + in reversed(include_log)))))) if 'parser' in self.options: # parse into a dummy document and return created nodes diff --git a/docutils/docutils/utils/smartquotes.py b/docutils/docutils/utils/smartquotes.py index 70400dee4..8bff85880 100644 --- a/docutils/docutils/utils/smartquotes.py +++ b/docutils/docutils/utils/smartquotes.py @@ -878,16 +878,6 @@ def tokenize(text): Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin. """ - - pos = 0 - length = len(text) - # tokens = [] - - depth = 6 - nested_tags = "|".join(['(?:<(?:[^<>]',] * depth) + (')*>)' * depth) - #match = r"""(?: ) | # comments - # (?: <\? .*? \?> ) | # directives - # %s # nested tags """ % (nested_tags,) tag_soup = re.compile(r"""([^<]*)(<[^>]*>)""") token_match = tag_soup.search(text)