66from selenium import webdriver
77from selenium .common .exceptions import WebDriverException
88
9+
910def is_safari_driver_enabled ():
1011 try :
1112 driver = webdriver .Safari ()
1213 driver .quit ()
1314 return True
14- except WebDriverException as e :
15+ except WebDriverException :
1516 return False
1617
17- def run_browser_tests_linux (build_dir ,emrun_path ):
18+
19+ def run_browser_tests_linux (build_dir , emrun_path ):
1820 browser_install_cmd = (
19- ' wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb&& '
20- ' dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome && '
21- ' wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz && '
22- ' tar -xJf firefox-138.0.1.tar.xz'
21+ " wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && "
22+ " dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome && "
23+ " wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz && "
24+ " tar -xJf firefox-138.0.1.tar.xz"
2325 )
2426 subprocess .run (browser_install_cmd , cwd = build_dir / "test" , shell = True )
25- browsers = {"Firefox" : ' firefox' , "Google Chrome" : ' google-chrome' }
27+ browsers = {"Firefox" : " firefox" , "Google Chrome" : " google-chrome" }
2628 for name , browser in browsers .items ():
2729 print (f"\n Running headless tests in { name } " )
2830 browser_args = "--headless"
@@ -31,24 +33,25 @@ def run_browser_tests_linux(build_dir,emrun_path):
3133
3234 browser_test_cmd = (
3335 'eval "$(micromamba shell hook --shell bash)" && '
34- ' micromamba activate xeus-cpp-wasm-build && '
36+ " micromamba activate xeus-cpp-wasm-build && "
3537 f'export PATH="{ build_dir } /test/chrome/opt/google/chrome/:{ build_dir } /test/firefox/:$PATH" && '
3638 f'python { emrun_path } --browser="{ browser } " --kill_exit --timeout 60 --browser-args="{ browser_args } " test_xeus_cpp.html'
3739 )
3840
3941 subprocess .run (browser_test_cmd , cwd = build_dir / "test" , shell = True )
4042
41- def run_browser_tests_macos (repo_dir ,build_dir ,emrun_path ):
43+
44+ def run_browser_tests_macos (repo_dir , build_dir , emrun_path ):
4245 browser_install_cmd = (
4346 'wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg && '
44- ' hdiutil attach Firefox-latest.dmg && '
45- ' cp -r /Volumes/Firefox/Firefox.app . && '
46- ' hdiutil detach /Volumes/Firefox && '
47- ' wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg && '
48- ' pkgutil --expand-full googlechrome.pkg google-chrome'
47+ " hdiutil attach Firefox-latest.dmg && "
48+ " cp -r /Volumes/Firefox/Firefox.app . && "
49+ " hdiutil detach /Volumes/Firefox && "
50+ " wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg && "
51+ " pkgutil --expand-full googlechrome.pkg google-chrome"
4952 )
5053 subprocess .run (browser_install_cmd , cwd = build_dir / "test" , shell = True )
51- browsers = {"Firefox" : ' firefox' , "Google Chrome" : ' Google Chrome' }
54+ browsers = {"Firefox" : " firefox" , "Google Chrome" : " Google Chrome" }
5255 for name , browser in browsers .items ():
5356 print (f"\n Running Emscripten C++ tests in { name } " )
5457 browser_args = "--headless"
@@ -57,7 +60,7 @@ def run_browser_tests_macos(repo_dir,build_dir,emrun_path):
5760
5861 browser_test_cmd = (
5962 'eval "$(micromamba shell hook --shell bash)" && '
60- ' micromamba activate xeus-cpp-wasm-build && '
63+ " micromamba activate xeus-cpp-wasm-build && "
6164 f'export PATH="{ build_dir } /test/Firefox.app/Contents/MacOS:{ build_dir } /test/google-chrome/GoogleChrome.pkg/Payload/Google Chrome.app/Contents/MacOS/:$PATH" && '
6265 f'python { emrun_path } --browser="{ browser } " --kill_exit --timeout 60 --browser-args="{ browser_args } " test_xeus_cpp.html'
6366 )
@@ -68,140 +71,208 @@ def run_browser_tests_macos(repo_dir,build_dir,emrun_path):
6871 print ("\n Running Emscripten C++ tests in Safari" )
6972 safari_cmd = (
7073 'eval "$(micromamba shell hook --shell bash)" && '
71- ' micromamba activate xeus-cpp-wasm-build && '
74+ " micromamba activate xeus-cpp-wasm-build && "
7275 f'python { emrun_path } --no_browser --kill_exit --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html & '
73- f' python { repo_dir } /scripts/browser_tests_safari.py test_xeus_cpp.html'
76+ f" python { repo_dir } /scripts/browser_tests_safari.py test_xeus_cpp.html"
7477 )
7578 subprocess .run (safari_cmd , cwd = build_dir / "test" , shell = True )
7679 else :
77- print ("Safari WebDriver is NOT enabled, so not running browser tests in Safari." )
80+ print (
81+ "Safari WebDriver is NOT enabled, so not running browser tests in Safari."
82+ )
7883
79- def run_lite (repo_dir ,prefix ):
80- subprocess .run ([
81- "micromamba" , "create" , "-n" , "xeus-lite-host" ,
82- "jupyterlite-core=0.6" , "jupyter_server" , "jupyterlite-xeus" ,
83- "-c" , "conda-forge" , "-y"
84- ])
84+
85+ def run_lite (repo_dir , prefix ):
86+ subprocess .run (
87+ [
88+ "micromamba" ,
89+ "create" ,
90+ "-n" ,
91+ "xeus-lite-host" ,
92+ "jupyterlite-core=0.6" ,
93+ "jupyter_server" ,
94+ "jupyterlite-xeus" ,
95+ "-c" ,
96+ "conda-forge" ,
97+ "-y" ,
98+ ]
99+ )
85100
86101 serve_cmd = [
87102 'eval "$(micromamba shell hook --shell bash)" && '
88- ' micromamba activate xeus-lite-host && '
89- ' jupyter lite serve '
90- f' --XeusAddon.prefix={ prefix } '
91- f' --XeusAddon.mounts={ prefix } /share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles '
92- f' --XeusAddon.mounts={ prefix } /etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d '
93- f' --contents { repo_dir } /README.md '
94- f' --contents { repo_dir } /notebooks/xeus-cpp-lite-demo.ipynb '
95- f' --contents { repo_dir } /notebooks/smallpt.ipynb '
96- f' --contents { repo_dir } /notebooks/images/marie.png '
97- f' --contents { repo_dir } /notebooks/audio/audio.wav '
103+ " micromamba activate xeus-lite-host && "
104+ " jupyter lite serve "
105+ f" --XeusAddon.prefix={ prefix } "
106+ f" --XeusAddon.mounts={ prefix } /share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles "
107+ f" --XeusAddon.mounts={ prefix } /etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d "
108+ f" --contents { repo_dir } /README.md "
109+ f" --contents { repo_dir } /notebooks/xeus-cpp-lite-demo.ipynb "
110+ f" --contents { repo_dir } /notebooks/smallpt.ipynb "
111+ f" --contents { repo_dir } /notebooks/images/marie.png "
112+ f" --contents { repo_dir } /notebooks/audio/audio.wav "
98113 ]
99114 subprocess .run (serve_cmd , cwd = repo_dir , shell = True )
100115
116+
101117def build_native (launch_lab = False ):
102118 repo_dir = Path .cwd ()
103119
104120 subprocess .run (["micromamba" , "create" , "-f" , "environment-dev.yml" , "-y" ])
105- subprocess .run (["micromamba" , "install" , "-n" , "xeus-cpp" , "jupyterlab" , "-c" , "conda-forge" , "-y" ])
121+ subprocess .run (
122+ [
123+ "micromamba" ,
124+ "install" ,
125+ "-n" ,
126+ "xeus-cpp" ,
127+ "jupyterlab" ,
128+ "-c" ,
129+ "conda-forge" ,
130+ "-y" ,
131+ ]
132+ )
106133
107134 prefix_path = os .environ .get ("MAMBA_ROOT_PREFIX" )
108135 build_dir = repo_dir / "build"
109136 build_dir .mkdir (exist_ok = True )
110137
111138 cmake_cmd = [
112- "micromamba" ,"run" ,"-n" ,"xeus-cpp" ,"cmake" , ".." ,
139+ "micromamba" ,
140+ "run" ,
141+ "-n" ,
142+ "xeus-cpp" ,
143+ "cmake" ,
144+ ".." ,
113145 f"-DCMAKE_PREFIX_PATH={ prefix_path } /envs/xeus-cpp/" ,
114146 f"-DCMAKE_INSTALL_PREFIX={ prefix_path } /envs/xeus-cpp/" ,
115- "-DCMAKE_INSTALL_LIBDIR=lib"
147+ "-DCMAKE_INSTALL_LIBDIR=lib" ,
116148 ]
117149
118150 subprocess .run (cmake_cmd , cwd = build_dir )
119- subprocess .run (["micromamba" ,"run" ,"-n" ,"xeus-cpp" ,"make" , "check-xeus-cpp" ], cwd = build_dir )
151+ subprocess .run (
152+ ["micromamba" , "run" , "-n" , "xeus-cpp" , "make" , "check-xeus-cpp" ], cwd = build_dir
153+ )
120154
121155 subprocess .run (["make" , "install" ], cwd = build_dir )
122- subprocess .run ([f"{ prefix_path } /envs/xeus-cpp/bin/pytest" , "-sv" , "test_xcpp_kernel.py" ], cwd = repo_dir / "test" )
156+ subprocess .run (
157+ [f"{ prefix_path } /envs/xeus-cpp/bin/pytest" , "-sv" , "test_xcpp_kernel.py" ],
158+ cwd = repo_dir / "test" ,
159+ )
123160
124161 if launch_lab :
125162 subprocess .run ([f"{ prefix_path } /envs/xeus-cpp/bin/jupyter-lab" ])
126163
127164
128165def build_emscripten (run_browser_tests_flag = False , launch_lite = False ):
129166 repo_dir = Path .cwd ()
130-
167+
131168 subprocess .run (["micromamba" , "create" , "-f" , "environment-wasm-build.yml" , "-y" ])
132- subprocess .run (["micromamba" , "create" , "-f" , "environment-wasm-host.yml" , "--platform=emscripten-wasm32" , "-y" ])
169+ subprocess .run (
170+ [
171+ "micromamba" ,
172+ "create" ,
173+ "-f" ,
174+ "environment-wasm-host.yml" ,
175+ "--platform=emscripten-wasm32" ,
176+ "-y" ,
177+ ]
178+ )
133179
134180 mamba_root = os .environ .get ("MAMBA_ROOT_PREFIX" )
135181
136182 build_prefix = f"{ mamba_root } /envs/xeus-cpp-wasm-build"
137183 prefix = f"{ mamba_root } /envs/xeus-cpp-wasm-host"
138184 sysroot_path = f"{ build_prefix } /opt/emsdk/upstream/emscripten/cache/sysroot"
139185
140- subprocess .run (["micromamba" , "create" , "-n" , "node-env" , "-c" , "conda-forge" , "nodejs=22" , "-y" ])
186+ subprocess .run (
187+ [
188+ "micromamba" ,
189+ "create" ,
190+ "-n" ,
191+ "node-env" ,
192+ "-c" ,
193+ "conda-forge" ,
194+ "nodejs=22" ,
195+ "-y" ,
196+ ]
197+ )
141198
142199 build_dir = repo_dir / "build"
143200 build_dir .mkdir (exist_ok = True )
144201
145202 cmake_cmd = (
146203 'eval "$(micromamba shell hook --shell bash)" && '
147- ' micromamba activate xeus-cpp-wasm-build && '
148- f' export PATH={ mamba_root } /envs/node-env/bin:$PATH &&'
149- ' emcmake cmake '
150- f' -DCMAKE_BUILD_TYPE=Release '
151- f' -DCMAKE_INSTALL_PREFIX={ prefix } '
152- ' -DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON '
153- f' -DCMAKE_FIND_ROOT_PATH={ prefix } '
154- f' -DSYSROOT_PATH={ sysroot_path } '
155- '..'
204+ " micromamba activate xeus-cpp-wasm-build && "
205+ f" export PATH={ mamba_root } /envs/node-env/bin:$PATH &&"
206+ " emcmake cmake "
207+ f" -DCMAKE_BUILD_TYPE=Release "
208+ f" -DCMAKE_INSTALL_PREFIX={ prefix } "
209+ " -DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON "
210+ f" -DCMAKE_FIND_ROOT_PATH={ prefix } "
211+ f" -DSYSROOT_PATH={ sysroot_path } "
212+ ".."
156213 )
157214 subprocess .run (cmake_cmd , cwd = build_dir , shell = True )
158215 make_cmd = (
159216 'eval "$(micromamba shell hook --shell bash)" && '
160- ' micromamba activate xeus-cpp-wasm-build && '
161- f' export PATH={ mamba_root } /envs/node-env/bin:$PATH &&'
162- ' emmake make check-xeus-cpp'
217+ " micromamba activate xeus-cpp-wasm-build && "
218+ f" export PATH={ mamba_root } /envs/node-env/bin:$PATH &&"
219+ " emmake make check-xeus-cpp"
163220 )
164221 subprocess .run (make_cmd , cwd = build_dir , shell = True )
165222 install_cmd = (
166- f' export PATH={ mamba_root } /node-env/bin:$PATH &&'
223+ f" export PATH={ mamba_root } /node-env/bin:$PATH &&"
167224 'eval "$(micromamba shell hook --shell bash)" && '
168- ' micromamba activate xeus-cpp-wasm-build && '
169- f' export PATH={ mamba_root } /envs/node-env/bin:$PATH &&'
170- ' emmake make install'
225+ " micromamba activate xeus-cpp-wasm-build && "
226+ f" export PATH={ mamba_root } /envs/node-env/bin:$PATH &&"
227+ " emmake make install"
171228 )
172229 subprocess .run (install_cmd , cwd = build_dir , shell = True )
173230
174231 if run_browser_tests_flag :
175232 if platform .system () == "Darwin" :
176- run_browser_tests_macos (repo_dir = repo_dir , build_dir = repo_dir / "build" , emrun_path = f"{ build_prefix } /bin/emrun.py" )
233+ run_browser_tests_macos (
234+ repo_dir = repo_dir ,
235+ build_dir = repo_dir / "build" ,
236+ emrun_path = f"{ build_prefix } /bin/emrun.py" ,
237+ )
177238 elif platform .system () == "Linux" :
178- run_browser_tests_linux (build_dir = repo_dir / "build" , emrun_path = f"{ build_prefix } /bin/emrun.py" )
239+ run_browser_tests_linux (
240+ build_dir = repo_dir / "build" , emrun_path = f"{ build_prefix } /bin/emrun.py"
241+ )
179242
180243 if launch_lite :
181- run_lite (repo_dir = repo_dir ,prefix = prefix )
244+ run_lite (repo_dir = repo_dir , prefix = prefix )
245+
182246
183247def main ():
184- parser = argparse .ArgumentParser (description = "Build xeus-cpp (native or emscripten)." )
248+ parser = argparse .ArgumentParser (
249+ description = "Build xeus-cpp (native or emscripten)."
250+ )
185251 parser .add_argument (
186- "--build" , choices = ["native" , "emscripten" ], default = "native" ,
187- help = "Choose build type (default: native)"
252+ "--build" ,
253+ choices = ["native" , "emscripten" ],
254+ default = "native" ,
255+ help = "Choose build type (default: native)" ,
188256 )
189257 parser .add_argument (
190- "--run-browser-tests" , action = "store_true" ,
191- help = "Run headless browser tests after Emscripten build"
258+ "--run-browser-tests" ,
259+ action = "store_true" ,
260+ help = "Run headless browser tests after Emscripten build" ,
192261 )
193262 parser .add_argument (
194- "--launch-lite" , action = "store_true" ,
195- help = "Launch a local JupyterLite demo after Emscripten build"
263+ "--launch-lite" ,
264+ action = "store_true" ,
265+ help = "Launch a local JupyterLite demo after Emscripten build" ,
196266 )
197267 parser .add_argument (
198- "--launch-lab" , action = "store_true" ,
199- help = "Launch JupyterLab after native build"
268+ "--launch-lab" , action = "store_true" , help = "Launch JupyterLab after native build"
200269 )
201270 args = parser .parse_args ()
202271
203272 if args .build == "emscripten" :
204- build_emscripten (run_browser_tests_flag = args .run_browser_tests , launch_lite = args .launch_lite )
273+ build_emscripten (
274+ run_browser_tests_flag = args .run_browser_tests , launch_lite = args .launch_lite
275+ )
205276 else :
206277 build_native (launch_lab = args .launch_lab )
207278
0 commit comments