changeset 5656:60ce376919c5 stable

test2rst: make one_file() useful The issue here was that this function is used when test2rst.py is called with an argument that is not a directory, and in such case we didn't write the result anywhere.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 09 Nov 2020 22:58:37 +0800
parents 1aec5a3be808
children 6e37ce7be367
files docs/test2rst.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/docs/test2rst.py	Sun Aug 23 09:36:36 2020 +0800
+++ b/docs/test2rst.py	Mon Nov 09 22:58:37 2020 +0800
@@ -1,8 +1,7 @@
 #!/usr/bin/env python
 
+import os
 import re
-import os
-import os.path as op
 import sys
 
 INDEX = '''
@@ -21,7 +20,7 @@
 ]
 
 
-def rstify(orig, name):
+def rstify(orig):
     newlines = []
 
     code_block_mode = False
@@ -82,11 +81,7 @@
         if not fn.endswith('.t'):
             continue
         name = os.path.splitext(fn)[0]
-        content = one_file(op.join(base, fn))
-        target = op.join(base, name + '.rst')
-        # with file(doc(name + '.rst'), 'w') as f:
-        with open(target, 'w') as f:
-            f.write(content)
+        one_file(os.path.join(base, fn))
 
         index += '\n   ' + name
 
@@ -95,8 +90,12 @@
 
 
 def one_file(path):
-    name = os.path.basename(path)[:-2]
-    return rstify(open(path).read(), name)
+    with open(path) as f:
+        content = f.read()
+    rst = rstify(content)
+    target = os.path.splitext(path)[0] + '.rst'
+    with open(target, 'w') as f:
+        f.write(rst)
 
 
 if __name__ == '__main__':