|
3 | 3 | import platform |
4 | 4 | import subprocess |
5 | 5 | from pathlib import Path |
| 6 | +from selenium import webdriver |
| 7 | +from selenium.common.exceptions import WebDriverException |
| 8 | + |
| 9 | +def is_safari_driver_enabled(): |
| 10 | + try: |
| 11 | + driver = webdriver.Safari() |
| 12 | + driver.quit() |
| 13 | + return True |
| 14 | + except WebDriverException as e: |
| 15 | + return False |
| 16 | + |
| 17 | +def run_browser_tests_linux(build_dir,emrun_path): |
| 18 | + 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' |
| 23 | + ) |
| 24 | + subprocess.run(browser_install_cmd, cwd=build_dir / "test", shell=True) |
| 25 | + browsers = {"Firefox": 'firefox', "Google Chrome": 'google-chrome'} |
| 26 | + for name, browser in browsers.items(): |
| 27 | + print(f"\nRunning headless tests in {name}") |
| 28 | + browser_args = "--headless" |
| 29 | + if "chrome" in name: |
| 30 | + browser_args += " --no-sandbox" |
| 31 | + |
| 32 | + browser_test_cmd = ( |
| 33 | + 'eval "$(micromamba shell hook --shell bash)" && ' |
| 34 | + 'micromamba activate xeus-cpp-wasm-build && ' |
| 35 | + f'export PATH="{build_dir}/test/chrome/opt/google/chrome/:{build_dir}/test/firefox/:$PATH" && ' |
| 36 | + f'python {emrun_path} --browser="{browser}" --kill_exit --timeout 60 --browser-args="{browser_args}" test_xeus_cpp.html' |
| 37 | + ) |
| 38 | + |
| 39 | + subprocess.run(browser_test_cmd, cwd=build_dir / "test", shell=True) |
| 40 | + |
| 41 | +def run_browser_tests_macos(repo_dir,build_dir,emrun_path): |
| 42 | + browser_install_cmd = ( |
| 43 | + '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' |
| 49 | + ) |
| 50 | + subprocess.run(browser_install_cmd, cwd=build_dir / "test", shell=True) |
| 51 | + browsers = {"Firefox": 'firefox', "Google Chrome": 'Google Chrome'} |
| 52 | + for name, browser in browsers.items(): |
| 53 | + print(f"\nRunning Emscripten C++ tests in {name}") |
| 54 | + browser_args = "--headless" |
| 55 | + if "Chrome" in name: |
| 56 | + browser_args += " --no-sandbox" |
| 57 | + |
| 58 | + browser_test_cmd = ( |
| 59 | + 'eval "$(micromamba shell hook --shell bash)" && ' |
| 60 | + 'micromamba activate xeus-cpp-wasm-build && ' |
| 61 | + f'export PATH="{build_dir}/test/Firefox.app/Contents/MacOS:{build_dir}/test/google-chrome/GoogleChrome.pkg/Payload/Google Chrome.app/Contents/MacOS/:$PATH" && ' |
| 62 | + f'python {emrun_path} --browser="{browser}" --kill_exit --timeout 60 --browser-args="{browser_args}" test_xeus_cpp.html' |
| 63 | + ) |
| 64 | + |
| 65 | + subprocess.run(browser_test_cmd, cwd=build_dir / "test", shell=True) |
| 66 | + |
| 67 | + if is_safari_driver_enabled(): |
| 68 | + print("\nRunning Emscripten C++ tests in Safari") |
| 69 | + safari_cmd = ( |
| 70 | + 'eval "$(micromamba shell hook --shell bash)" && ' |
| 71 | + 'micromamba activate xeus-cpp-wasm-build && ' |
| 72 | + 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' |
| 74 | + ) |
| 75 | + subprocess.run(safari_cmd, cwd=build_dir / "test", shell=True) |
| 76 | + else: |
| 77 | + print("Safari WebDriver is NOT enabled, so not running browser tests in Safari.") |
| 78 | + |
| 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 | + ]) |
| 85 | + |
| 86 | + serve_cmd = [ |
| 87 | + '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 ' |
| 98 | + ] |
| 99 | + subprocess.run(serve_cmd, cwd=repo_dir, shell=True) |
6 | 100 |
|
7 | 101 | def build_native(launch_lab=False): |
8 | 102 | repo_dir = Path.cwd() |
@@ -45,7 +139,6 @@ def build_emscripten(run_browser_tests_flag=False, launch_lite=False): |
45 | 139 |
|
46 | 140 | subprocess.run(["micromamba", "create", "-n", "node-env", "-c", "conda-forge", "nodejs=22", "-y"]) |
47 | 141 |
|
48 | | - # Build |
49 | 142 | build_dir = repo_dir / "build" |
50 | 143 | build_dir.mkdir(exist_ok=True) |
51 | 144 |
|
@@ -79,87 +172,13 @@ def build_emscripten(run_browser_tests_flag=False, launch_lite=False): |
79 | 172 | subprocess.run(install_cmd, cwd=build_dir, shell=True) |
80 | 173 |
|
81 | 174 | if run_browser_tests_flag: |
82 | | - emrun_path = f"{build_prefix}/bin/emrun.py" |
83 | | - |
84 | 175 | if platform.system() == "Darwin": |
85 | | - browser_install_cmd = ( |
86 | | - 'wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg && ' |
87 | | - 'hdiutil attach Firefox-latest.dmg && ' |
88 | | - 'cp -r /Volumes/Firefox/Firefox.app . && ' |
89 | | - 'hdiutil detach /Volumes/Firefox && ' |
90 | | - '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 && ' |
91 | | - 'pkgutil --expand-full googlechrome.pkg google-chrome' |
92 | | - ) |
93 | | - subprocess.run(browser_install_cmd, cwd=build_dir / "test", shell=True) |
94 | | - browsers = {"Firefox": 'firefox', "Google Chrome": 'Google Chrome'} |
95 | | - for name, browser in browsers.items(): |
96 | | - print(f"\nRunning headless tests in {name}") |
97 | | - browser_args = "--headless" |
98 | | - if "Chrome" in name: |
99 | | - browser_args += " --no-sandbox" |
100 | | - |
101 | | - browser_test_cmd = ( |
102 | | - 'eval "$(micromamba shell hook --shell bash)" && ' |
103 | | - 'micromamba activate xeus-cpp-wasm-build && ' |
104 | | - f'export PATH="{build_dir}/test/Firefox.app/Contents/MacOS:{build_dir}/test/google-chrome/GoogleChrome.pkg/Payload/Google Chrome.app/Contents/MacOS/:$PATH" && ' |
105 | | - f'python {emrun_path} --browser="{browser}" --kill_exit --timeout 60 --browser-args="{browser_args}" test_xeus_cpp.html' |
106 | | - ) |
107 | | - |
108 | | - subprocess.run(browser_test_cmd, cwd=build_dir / "test", shell=True) |
109 | | - # FIXME: Currently assumed that safari driver is enabled and that Selenium is installed |
110 | | - print("\nRunning Safari test via safaridriver") |
111 | | - safari_cmd = ( |
112 | | - 'eval "$(micromamba shell hook --shell bash)" && ' |
113 | | - 'micromamba activate xeus-cpp-wasm-build && ' |
114 | | - f'python {emrun_path} --no_browser --kill_exit --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html & ' |
115 | | - f'python {repo_dir}/scripts/browser_tests_safari.py test_xeus_cpp.html' |
116 | | - ) |
117 | | - subprocess.run(safari_cmd, cwd=build_dir / "test", shell=True) |
118 | | - |
| 176 | + run_browser_tests_macos(repo_dir = repo_dir , build_dir= repo_dir / "build" , emrun_path= f"{build_prefix}/bin/emrun.py") |
119 | 177 | elif platform.system() == "Linux": |
120 | | - browser_install_cmd = ( |
121 | | - 'wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb&& ' |
122 | | - 'dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome && ' |
123 | | - 'wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz && ' |
124 | | - 'tar -xJf firefox-138.0.1.tar.xz' |
125 | | - ) |
126 | | - browsers = {"Firefox": 'firefox', "Google Chrome": 'google-chrome'} |
127 | | - for name, browser in browsers.items(): |
128 | | - print(f"\nRunning headless tests in {name}") |
129 | | - browser_args = "--headless" |
130 | | - if "chrome" in name: |
131 | | - browser_args += " --no-sandbox" |
132 | | - |
133 | | - browser_test_cmd = ( |
134 | | - 'eval "$(micromamba shell hook --shell bash)" && ' |
135 | | - 'micromamba activate xeus-cpp-wasm-build && ' |
136 | | - f'export PATH="{build_dir}/test/chrome/opt/google/chrome/:{build_dir}/test/firefox/:$PATH" && ' |
137 | | - f'python {emrun_path} --browser="{browser}" --kill_exit --timeout 60 --browser-args="{browser_args}" test_xeus_cpp.html' |
138 | | - ) |
139 | | - |
140 | | - subprocess.run(browser_test_cmd, cwd=build_dir / "test", shell=True) |
141 | | - |
142 | | - if launch_lite: |
143 | | - subprocess.run([ |
144 | | - "micromamba", "create", "-n", "xeus-lite-host", |
145 | | - "jupyterlite-core=0.6", "jupyter_server", "jupyterlite-xeus", |
146 | | - "-c", "conda-forge", "-y" |
147 | | - ]) |
| 178 | + run_browser_tests_linux(build_dir= repo_dir / "build" , emrun_path= f"{build_prefix}/bin/emrun.py" ) |
148 | 179 |
|
149 | | - serve_cmd = [ |
150 | | - 'eval "$(micromamba shell hook --shell bash)" && ' |
151 | | - 'micromamba activate xeus-lite-host && ' |
152 | | - 'jupyter lite serve ' |
153 | | - f'--XeusAddon.prefix={prefix} ' |
154 | | - f'--XeusAddon.mounts={prefix}/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles ' |
155 | | - f'--XeusAddon.mounts={prefix}/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d ' |
156 | | - f'--contents {repo_dir}/README.md ' |
157 | | - f'--contents {repo_dir}/notebooks/xeus-cpp-lite-demo.ipynb ' |
158 | | - f'--contents {repo_dir}/notebooks/smallpt.ipynb ' |
159 | | - f'--contents {repo_dir}/notebooks/images/marie.png ' |
160 | | - f'--contents {repo_dir}/notebooks/audio/audio.wav ' |
161 | | - ] |
162 | | - subprocess.run(serve_cmd, cwd=repo_dir, shell=True) |
| 180 | + if launch_lite: |
| 181 | + run_lite(repo_dir=repo_dir,prefix=prefix) |
163 | 182 |
|
164 | 183 | def main(): |
165 | 184 | parser = argparse.ArgumentParser(description="Build xeus-cpp (native or emscripten).") |
|
0 commit comments