summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-06-03 19:36:39 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-06-03 19:36:39 +0200
commit3fcd59c91f9bdc13e1054398a95a0e5819210628 (patch)
tree13608bef6643df85e6340325e2657c78c521a247
parentaf6b1d0e6bc619ad5bccf5ce7b575e1f285cf1b5 (diff)
downloadpython-lxml-3fcd59c91f9bdc13e1054398a95a0e5819210628.tar.gz
clean up doc generator script and modernise syntaxlxml-3.8.0
-rw-r--r--doc/mklatex.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/doc/mklatex.py b/doc/mklatex.py
index 84ea86a3..98e91dff 100644
--- a/doc/mklatex.py
+++ b/doc/mklatex.py
@@ -88,14 +88,13 @@ def rest2latex(script, source_path, dest_path):
def build_pygments_macros(filename):
from pygments.formatters import LatexFormatter
text = LatexFormatter().get_style_defs()
- f = file(filename, "w")
- f.write(text)
- f.write('\n')
- f.close()
+ with open(filename, "w") as f:
+ f.write(text)
+ f.write('\n')
def copy_epydoc_macros(src, dest, existing_header_lines):
- doc = file(src, 'r')
- out = file(dest, "w")
+ doc = open(src, 'r')
+ out = open(dest, "w")
for line in doc:
if line.startswith('%% generator') \
or line.startswith('% generated by ') \
@@ -134,7 +133,6 @@ def tex_postprocess(src_path, dest_path, want_header=False, process_line=noop):
If want_header is set, returns also the document header (as
the list of lines).
"""
- title = ''
header = []
add_header_line = header.append
global counter_no
@@ -144,11 +142,10 @@ def tex_postprocess(src_path, dest_path, want_header=False, process_line=noop):
search_title = re.compile(r'\\title{([^{}]*(?:{[^}]*})*)}').search
skipping = re.compile(r'(\\end{document}|\\tableofcontents|^%)').search
- src = file(src_path)
- dest = file(dest_path, "w")
+ with open(src_path) as src:
+ src_text = src.read()
- src_text = src.read()
- src.close()
+ dest = open(dest_path, "w")
title = search_title(src_text)
if title:
@@ -176,6 +173,8 @@ def tex_postprocess(src_path, dest_path, want_header=False, process_line=noop):
l = l.replace("listcnt0", counter_text)
dest.write(l + '\n')
+ dest.close()
+
if not title:
raise Exception("Bueee, no title in %s" % src_path)
return title, header
@@ -238,7 +237,7 @@ def publish(dirname, lxml_path, release):
outpath = os.path.join(dirname, outname)
path = os.path.join(doc_dir, filename)
- print "Creating %s" % outname
+ print("Creating %s" % outname)
rest2latex(script, path, outpath)
final_name = os.path.join(dirname, os.path.dirname(outname),
@@ -253,7 +252,7 @@ def publish(dirname, lxml_path, release):
# integrate generated API docs
- print "Integrating API docs"
+ print("Integrating API docs")
apidocsname = 'api.tex'
apipath = os.path.join(dirname, apidocsname)
tex_postprocess(apipath, os.path.join(dirname, "_part_%s" % apidocsname),
@@ -263,7 +262,7 @@ def publish(dirname, lxml_path, release):
# convert CHANGES.txt
- print "Integrating ChangeLog"
+ print("Integrating ChangeLog")
find_version_title = re.compile(
r'(.*\\section\{)([0-9][^\} ]*)\s+\(([^)]+)\)(\}.*)').search
def fix_changelog(line):
@@ -283,8 +282,8 @@ def publish(dirname, lxml_path, release):
process_line=fix_changelog)
# Writing a master file
- print "Building %s\n" % TARGET_FILE
- master = file( os.path.join(dirname, TARGET_FILE), "w")
+ print("Building %s\n" % TARGET_FILE)
+ master = open( os.path.join(dirname, TARGET_FILE), "w")
for hln in header:
if hln.startswith(r"\documentclass"):
#hln = hln.replace('article', 'book')
@@ -330,5 +329,6 @@ def publish(dirname, lxml_path, release):
master.write("\\end{appendix}\n")
master.write("\\end{document}\n")
+
if __name__ == '__main__':
publish(sys.argv[1], sys.argv[2], sys.argv[3])