Skip to content

Commit

Permalink
Fix MathML generation on Macs
Browse files Browse the repository at this point in the history
geckodriver was vendored in, but only as an ELF binary which aren’t natively compatible on Macs. This adds ARM and Intel binaries for Mac and a Windows Intel binary too, and falls back to checking the path for other machines.
  • Loading branch information
robinwhittleton committed Mar 10, 2024
1 parent bc8645d commit c66ca9b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions se/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import platform
import shutil
from pathlib import Path
import importlib_resources
Expand Down Expand Up @@ -43,10 +44,21 @@ def initialize_selenium_firefox_webdriver() -> webdriver.firefox.webdriver.WebDr
profile.set_preference("browser.http.use-cache", False)
profile.set_preference("layout.css.devPixelsPerPx", "2.0")

if platform.system() == "Linux":
geckodriver_path = importlib_resources.path("se.data.geckodriver", "geckodriver-linux64")
elif platform.system() == "Windows":
geckodriver_path = importlib_resources.path("se.data.geckodriver", "geckodriver-win64.exe")
elif platform.system() == "Darwin":
if platform.machine() == "arm64":
geckodriver_path = importlib_resources.path("se.data.geckodriver", "geckodriver-macos-aarch64")
else:
geckodriver_path = importlib_resources.path("se.data.geckodriver", "geckodriver-macos")
else:
geckodriver_path = shutil.which("geckodriver")

try:
with importlib_resources.path("se.data.geckodriver", "geckodriver") as geckodriver_path:
driver = webdriver.Firefox(firefox_profile=profile, options=options, service_log_path=os.devnull, executable_path=geckodriver_path)
driver = webdriver.Firefox(firefox_profile=profile, options=options, service_log_path=os.devnull, executable_path=geckodriver_path)
except WebDriverException as ex:
raise se.MissingDependencyException("Selenium Firefox web driver is not installed. To install it on Linux, download the appropriate zip file from [url][link=https://github.com/mozilla/geckodriver/releases/latest]https://github.com/mozilla/geckodriver/releases/latest[/][/] and place the [bash]geckodriver[/] executable in your [path]$PATH[/] (for example, in [path]~/.local/bin/[/] or [path]/usr/local/bin/[/]). To install it on macOS, run [bash]brew install geckodriver[/].") from ex
raise se.MissingDependencyException("Selenium Firefox web driver is not installed. To install it on Linux or Windows, download the appropriate zip file from [url][link=https://github.com/mozilla/geckodriver/releases/latest]https://github.com/mozilla/geckodriver/releases/latest[/][/] and place the [bash]geckodriver[/] executable in your [path]$PATH[/] (for example, in [path]~/.local/bin/[/] or [path]/usr/local/bin/[/]). To install it on macOS, run [bash]brew install geckodriver[/].") from ex

return driver
Binary file not shown.
Binary file added se/data/geckodriver/geckodriver-macos
Binary file not shown.
Binary file added se/data/geckodriver/geckodriver-macos-aarch64
Binary file not shown.
Binary file added se/data/geckodriver/geckodriver-win64.exe
Binary file not shown.

0 comments on commit c66ca9b

Please sign in to comment.