27
27
manually using the command make gen-cpydiff. """
28
28
29
29
import os
30
- import errno
31
30
import subprocess
32
31
import time
33
32
import re
44
43
CPYTHON3 = os .getenv ("MICROPY_CPYTHON3" , "python3" )
45
44
MICROPYTHON = os .getenv ("MICROPY_MICROPYTHON" , "../ports/unix/build-standard/micropython" )
46
45
47
- TESTPATH = "../tests/cpydiff/ "
48
- DOCPATH = "../docs/genrst/ "
46
+ TESTPATH = "../tests/cpydiff"
47
+ DOCPATH = "../docs/genrst"
49
48
INDEXTEMPLATE = "../docs/differences/index_template.txt"
50
49
INDEX = "index.rst"
51
50
@@ -79,7 +78,8 @@ def readfiles():
79
78
files = []
80
79
81
80
for test in tests :
82
- text = open (TESTPATH + test , "r" ).read ()
81
+ test_fullpath = os .path .join (TESTPATH , test )
82
+ text = open (test_fullpath , "r" ).read ()
83
83
84
84
try :
85
85
class_ , desc , cause , workaround , code = [
@@ -98,7 +98,7 @@ def readfiles():
98
98
output = Output (test , class_ , desc , cause , workaround , code , "" , "" , "" )
99
99
files .append (output )
100
100
except IndexError :
101
- print ("Incorrect format in file " + TESTPATH + test )
101
+ print ("Incorrect format in file " + test_fullpath )
102
102
103
103
return files
104
104
@@ -107,7 +107,8 @@ def run_tests(tests):
107
107
"""executes all tests"""
108
108
results = []
109
109
for test in tests :
110
- with open (TESTPATH + test .name , "rb" ) as f :
110
+ test_fullpath = os .path .join (TESTPATH , test .name )
111
+ with open (test_fullpath , "rb" ) as f :
111
112
input_py = f .read ()
112
113
113
114
process = subprocess .Popen (
@@ -130,7 +131,7 @@ def run_tests(tests):
130
131
131
132
if output_cpy [0 ] == output_upy [0 ] and output_cpy [1 ] == output_upy [1 ]:
132
133
status = "Supported"
133
- print ("Supported operation!\n File: " + TESTPATH + test . name )
134
+ print ("Supported operation!\n File: " + test_fullpath )
134
135
else :
135
136
status = "Unsupported"
136
137
@@ -197,11 +198,8 @@ def gen_rst(results):
197
198
"""creates restructured text documents to display tests"""
198
199
199
200
# make sure the destination directory exists
200
- try :
201
+ if not os . path . isdir ( DOCPATH ) :
201
202
os .mkdir (DOCPATH )
202
- except OSError as e :
203
- if e .args [0 ] != errno .EEXIST and e .args [0 ] != errno .EISDIR :
204
- raise
205
203
206
204
toctree = []
207
205
class_ = []
@@ -214,7 +212,7 @@ def gen_rst(results):
214
212
if i >= len (class_ ) or section [i ] != class_ [i ]:
215
213
if i == 0 :
216
214
filename = section [i ].replace (" " , "_" ).lower ()
217
- rst = open (DOCPATH + filename + ".rst" , "w" )
215
+ rst = open (os . path . join ( DOCPATH , filename + ".rst" ) , "w" )
218
216
rst .write (HEADER )
219
217
rst .write (section [i ] + "\n " )
220
218
rst .write (RSTCHARS [0 ] * len (section [i ]))
@@ -225,7 +223,7 @@ def gen_rst(results):
225
223
rst .write (RSTCHARS [min (i , len (RSTCHARS ) - 1 )] * len (section [i ]))
226
224
rst .write ("\n \n " )
227
225
class_ = section
228
- rst .write (".. _cpydiff_%s:\n \n " % output . name . rsplit ( "." , 1 )[0 ])
226
+ rst .write (".. _cpydiff_%s:\n \n " % os . path . splitext ( output . name )[0 ])
229
227
rst .write (output .desc + "\n " )
230
228
rst .write ("~" * len (output .desc ) + "\n \n " )
231
229
if output .cause != "Unknown" :
@@ -242,7 +240,7 @@ def gen_rst(results):
242
240
rst .write (table )
243
241
244
242
template = open (INDEXTEMPLATE , "r" )
245
- index = open (DOCPATH + INDEX , "w" )
243
+ index = open (os . path . join ( DOCPATH , INDEX ) , "w" )
246
244
index .write (HEADER )
247
245
index .write (template .read ())
248
246
for section in INDEXPRIORITY :
0 commit comments