1
- #!/usr/bin/env python
1
+ #!/usr/bin/env python3
2
2
"""
3
3
build.py
4
4
5
5
Build HTML output
6
6
"""
7
- from __future__ import absolute_import , division , print_function
7
+
8
8
9
9
import re
10
10
import os
@@ -122,7 +122,7 @@ def tag_set_sort(item):
122
122
for fn in non_idx_items :
123
123
index_text .append (":doc:`{0} <items/{1}>`\n " .format (titles [fn ], fn ))
124
124
125
- with open (section_fn , 'w' ) as f :
125
+ with open (section_fn , 'w' , encoding = 'utf-8' ) as f :
126
126
sec_title = titles .get (section_base_fn , tag_id )
127
127
f .write ("{0}\n {1}\n \n " .format (sec_title , "=" * len (sec_title )))
128
128
@@ -143,7 +143,7 @@ def tag_set_sort(item):
143
143
f .write (" {0}\n " .format (fn ))
144
144
145
145
# Write index
146
- with open (index_rst , 'w' ) as f :
146
+ with open (index_rst , 'w' , encoding = 'utf-8' ) as f :
147
147
f .write (".. toctree::\n "
148
148
" :maxdepth: 1\n "
149
149
" :hidden:\n \n " )
@@ -186,7 +186,7 @@ def generate_files(dst_path):
186
186
created_stamp = created .get (basename , 0 )
187
187
modified_stamp = modified .get (basename , created_stamp )
188
188
p = subprocess .Popen (['git' , 'log' , '--format=%at:%an' , 'ef45029096..' , fn ],
189
- stdout = subprocess .PIPE )
189
+ stdout = subprocess .PIPE , encoding = 'utf-8' )
190
190
names , _ = p .communicate ()
191
191
for name in names .splitlines ():
192
192
timestamp , name = name .strip ().split (':' , 1 )
@@ -249,52 +249,46 @@ def convert_file(dst_path, fn, editors, created, modified):
249
249
headers = container .xpath ('//h1' )
250
250
if headers :
251
251
title = headers [0 ].text
252
- if isinstance (title , unicode ):
253
- title = title .encode ('utf-8' )
254
252
h1_parent = headers [0 ].getparent ()
255
253
h1_parent .remove (headers [0 ])
256
254
257
- lines .extend ([u ".. raw:: html" , u "" ])
255
+ lines .extend ([".. raw:: html" , "" ])
258
256
259
257
for element in head .getchildren ():
260
258
if element .tag in ('script' ,):
261
- text = lxml .html .tostring (element )
259
+ text = lxml .html .tostring (element , encoding = 'utf-8' ). decode ( 'utf-8' )
262
260
lines .extend (" " + x for x in text .splitlines ())
263
261
264
- text = lxml .html .tostring (container )
262
+ text = lxml .html .tostring (container , encoding = 'utf-8' ). decode ( 'utf-8' )
265
263
266
- m = re .search (ur '<p>TAGS:\s*(.*)\s*</p>' , text )
264
+ m = re .search (r '<p>TAGS:\s*(.*)\s*</p>' , text )
267
265
if m :
268
266
tag_line = m .group (1 ).strip ().replace (';' , ',' )
269
- if isinstance (tag_line , unicode ):
270
- tag_line = tag_line .encode ('utf-8' )
271
267
tags .update ([x .strip () for x in tag_line .split ("," )])
272
268
text = text [:m .start ()] + text [m .end ():]
273
269
274
- m = re .search (ur '<p>AUTHORS:\s*(.*)\s*</p>' , text )
270
+ m = re .search (r '<p>AUTHORS:\s*(.*)\s*</p>' , text )
275
271
if m :
276
272
# Author lines override editors
277
273
if legacy_editors :
278
274
editors = []
279
275
legacy_editors = False
280
276
author_line = m .group (1 ).strip ().replace (';' , ',' )
281
- if isinstance (author_line , unicode ):
282
- author_line = author_line .encode ('utf-8' )
283
277
for author in author_line .split ("," ):
284
278
author = author .strip ()
285
279
if author and author not in editors :
286
280
editors .append (author )
287
281
288
282
text = text [:m .start ()] + text [m .end ():]
289
283
290
- text = text .replace (u 'attachments/{0}/' .format (basename ),
291
- u '../_downloads/' )
284
+ text = text .replace ('attachments/{0}/' .format (basename ),
285
+ '../_downloads/' )
292
286
293
- lines .extend (u " " + x for x in text .splitlines ())
294
- lines .append (u "" )
287
+ lines .extend (" " + x for x in text .splitlines ())
288
+ lines .append ("" )
295
289
296
290
# Produce output
297
- text = u "\n " .join (lines ). encode ( 'utf-8' )
291
+ text = "\n " .join (lines )
298
292
299
293
if not title :
300
294
title = basename
@@ -317,15 +311,15 @@ def fmt_time(timestamp):
317
311
updateinfo ,
318
312
text )
319
313
320
- with open (rst_fn , 'w' ) as f :
314
+ with open (rst_fn , 'w' , encoding = 'utf-8' ) as f :
321
315
f .write (text )
322
316
if authors :
323
317
f .write ("\n \n .. sectionauthor:: {0}" .format (authors ))
324
318
del text
325
319
326
320
attach_dir = os .path .join ('ipython' , 'attachments' , basename )
327
321
if os .path .isdir (attach_dir ) and len (os .listdir (attach_dir )) > 0 :
328
- with open (rst_fn , 'a' ) as f :
322
+ with open (rst_fn , 'a' , encoding = 'utf-8' ) as f :
329
323
f .write ("""
330
324
331
325
.. rubric:: Attachments
@@ -343,7 +337,7 @@ def parse_wiki_legacy_tags():
343
337
tags = [None , None , None ]
344
338
items = {}
345
339
346
- with open ('wiki-legacy-tags.txt' , 'r' ) as f :
340
+ with open ('wiki-legacy-tags.txt' , 'r' , encoding = 'utf-8' ) as f :
347
341
prev_line = None
348
342
349
343
for line in f :
@@ -383,7 +377,7 @@ def parse_wiki_legacy_tags():
383
377
def parse_wiki_legacy_users ():
384
378
items = {}
385
379
386
- with open ('wiki-legacy-users.txt' , 'r' ) as f :
380
+ with open ('wiki-legacy-users.txt' , 'r' , encoding = 'utf-8' ) as f :
387
381
for line in f :
388
382
line = line .strip ()
389
383
if not line or line .startswith ('#' ):
@@ -401,7 +395,7 @@ def parse_wiki_legacy_timestamps():
401
395
created = {}
402
396
modified = {}
403
397
404
- with open ('wiki-legacy-timestamps.txt' , 'r' ) as f :
398
+ with open ('wiki-legacy-timestamps.txt' , 'r' , encoding = 'utf-8' ) as f :
405
399
for line in f :
406
400
line = line .strip ()
407
401
if not line or line .startswith ('#' ):
0 commit comments