4343import time
4444import unittest
4545import webbrowser
46+ from pathlib import Path
4647from http .server import HTTPServer , SimpleHTTPRequestHandler
4748from urllib .parse import unquote , unquote_plus
4849
6566
6667def path_from_root (* pathelems ):
6768 """Construct a path relative to the emscripten root directory."""
68- return os .path . join ( __rootpath__ , * pathelems )
69+ return os .fspath ( Path ( __rootpath__ , * pathelems ) )
6970
7071
7172sys .path .append (path_from_root ('third_party/websockify' ))
@@ -111,7 +112,7 @@ def delete_contents(pathname):
111112
112113def test_file (* path_components ):
113114 """Construct a path relative to the emscripten "tests" directory."""
114- return os .path . join ( TEST_ROOT , * path_components )
115+ return os .fspath ( Path ( TEST_ROOT , * path_components ) )
115116
116117
117118# checks if browser testing is enabled
@@ -241,8 +242,8 @@ def modified(self):
241242
242243
243244def ensure_dir (dirname ):
244- if not os . path . isdir (dirname ):
245- os . makedirs ( dirname )
245+ dirname = Path (dirname )
246+ dirname . mkdir ( parents = True , exist_ok = True )
246247
247248
248249def limit_size (string , maxbytes = 800000 * 20 , maxlines = 100000 , max_line = 5000 ):
@@ -259,14 +260,16 @@ def limit_size(string, maxbytes=800000 * 20, maxlines=100000, max_line=5000):
259260
260261
261262def create_file (name , contents , binary = False ):
262- assert not os .path .isabs (name )
263- mode = 'wb' if binary else 'w'
264- with open (name , mode ) as f :
265- f .write (contents )
263+ name = Path (name )
264+ assert not name .is_absolute ()
265+ if binary :
266+ name .write_bytes (contents )
267+ else :
268+ name .write_text (contents )
266269
267270
268271def make_executable (name ):
269- os .chmod (name , stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
272+ Path ( name ) .chmod (stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
270273
271274
272275# The core test modes
@@ -595,7 +598,7 @@ def build(self, filename, libraries=[], includes=[], force_c=False,
595598 if shared .suffix (filename ) not in ('.i' , '.ii' ):
596599 # Add the location of the test file to include path.
597600 cmd += ['-I.' ]
598- cmd += ['-I' + include for include in includes ]
601+ cmd += ['-I' + os . fspath ( include ) for include in includes ]
599602
600603 self .run_process (cmd , stderr = self .stderr_redirect if not DEBUG else None )
601604 self .assertExists (output )
@@ -1100,8 +1103,8 @@ def get_poppler_library(self, env_init=None):
11001103 self .set_setting ('ERROR_ON_UNDEFINED_SYMBOLS' , 0 )
11011104
11021105 self .emcc_args += [
1103- '-I' + test_file ('third_party' , ' freetype' , ' include' ),
1104- '-I' + test_file ('third_party' , ' poppler' , ' include' )
1106+ '-I' + test_file ('third_party/ freetype/ include' ),
1107+ '-I' + test_file ('third_party/ poppler/ include' )
11051108 ]
11061109
11071110 freetype = self .get_freetype_library ()
@@ -1613,10 +1616,12 @@ def build_library(name,
16131616 generated_libs = [generated_libs ]
16141617 source_dir = test_file (name .replace ('_native' , '' ))
16151618
1616- project_dir = os .path .join (build_dir , name )
1619+ project_dir = Path (build_dir , name )
1620+ print (project_dir )
16171621 if os .path .exists (project_dir ):
16181622 shutil .rmtree (project_dir )
1619- shutil .copytree (source_dir , project_dir ) # Useful in debugging sometimes to comment this out, and two lines above
1623+ # Useful in debugging sometimes to comment this out, and two lines above
1624+ shutil .copytree (source_dir , project_dir )
16201625
16211626 generated_libs = [os .path .join (project_dir , lib ) for lib in generated_libs ]
16221627 if native :
0 commit comments