Files
numpy/doc/postprocess.py
Dimitri Papadopoulos Orfanos c31e599938 CI: pycodestyle → ruff (#27300)
* CI: pycodestyle → ruff check

* MAINT: Apply ruff/pycodestyle rule E101

E101 Indentation contains mixed spaces and tabs

* MAINT: Apply ruff/pycodestyle rule E111

E111 Indentation is not a multiple of 4

* MAINT: Apply ruff/pycodestyle rule E116

E116 Unexpected indentation (comment)

* MAINT: Apply ruff/pycodestyle rule E117

E117 Over-indented

* MAINT: Apply ruff/pycodestyle rule E201

E201 Whitespace after bracket

* MAINT: Apply ruff/pycodestyle rule E202

E202 Whitespace before bracket

* MAINT: Apply ruff/pycodestyle rule E203

E203 Whitespace before punctuation

* MAINT: Apply ruff/pycodestyle rule E211

E211 Whitespace before '('

* MAINT: Apply ruff/pycodestyle rule E221

E221 Multiple spaces before operator

* MAINT: Apply ruff/pycodestyle rule E222

E222 Multiple spaces after operator

* MAINT: Apply ruff/pycodestyle rule E225

E225 Missing whitespace around operator

* MAINT: Apply ruff/pycodestyle rule E226

E226 Missing whitespace around arithmetic operator

* MAINT: Apply ruff/pycodestyle rule E227

E227 Missing whitespace around bitwise or shift operator

* MAINT: Apply ruff/pycodestyle rule E228

E228 Missing whitespace around modulo operator

* MAINT: Apply ruff/pycodestyle rule E252

E252 Missing whitespace around parameter equals

* MAINT: Apply ruff/pycodestyle rule E261

E261 Insert at least two spaces before an inline comment

* MAINT: Apply ruff/pycodestyle rule E271

E271 Multiple spaces after keyword

* MAINT: Apply ruff/pycodestyle rule E272

E272 Multiple spaces before keyword

* MAINT: Apply ruff/pycodestyle rule E275

E275 Missing whitespace after keyword

* MAINT: Apply ruff/pycodestyle rule E301

E301 Expected 1 blank line between methods

* MAINT: Apply ruff/pycodestyle rule E303

E303 Too many blank lines

* MAINT: Apply ruff/pycodestyle rule E304

E304 Blank lines found after function decorator

* MAINT: Apply ruff/pycodestyle rule E305

E305 Expected 2 blank lines after class or function definition

* MAINT: Apply ruff/pycodestyle rule E306

E306 Expected 1 blank line before a nested definition

* MAINT: Apply ruff/pycodestyle rule E501

E501 Line too long

* MAINT: Disable ruff/pycodestyle rule E714 in tests

E714 Test for object identity should be `is not`

* MAINT: Apply ruff/pycodestyle rule E743

E743 Ambiguous function name

* MAINT: Disable E501 for now

Ruff has found 1080 occurrences of this error. Fixing them sounds excessive.
2024-12-16 08:34:22 -07:00

51 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Post-processes HTML and Latex files output by Sphinx.
"""
def main():
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('mode', help='file mode', choices=('html', 'tex'))
parser.add_argument('file', nargs='+', help='input file(s)')
args = parser.parse_args()
mode = args.mode
for fn in args.file:
with open(fn, encoding="utf-8") as f:
if mode == 'html':
lines = process_html(fn, f.readlines())
elif mode == 'tex':
lines = process_tex(f.readlines())
with open(fn, 'w', encoding="utf-8") as f:
f.write("".join(lines))
def process_html(fn, lines):
return lines
def process_tex(lines):
"""
Remove unnecessary section titles from the LaTeX file.
"""
new_lines = []
for line in lines:
if line.startswith(("\\section{numpy.",
"\\subsection{numpy.",
"\\subsubsection{numpy.",
"\\paragraph{numpy.",
"\\subparagraph{numpy.",
)):
pass
else:
new_lines.append(line)
return new_lines
if __name__ == "__main__":
main()