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 authored and acabal committed Mar 11, 2024
1 parent fbc188a commit a8850b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions se/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"""

import os
import platform
import shutil
from pathlib import Path
import importlib_resources

from selenium import webdriver
from selenium.common.exceptions import WebDriverException


import se

Expand Down Expand Up @@ -43,10 +41,20 @@ 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")

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)
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

return driver
possible_system_geckodriver = shutil.which("geckodriver")

if platform.system() == "Linux":
geckodriver_path = Path("se.data.geckodriver", "geckodriver-linux64")
elif platform.system() == "Windows":
geckodriver_path = Path("se.data.geckodriver", "geckodriver-win64.exe")
elif platform.system() == "Darwin":
if platform.machine() == "arm64":
geckodriver_path = Path("se.data.geckodriver", "geckodriver-macos-aarch64")
else:
geckodriver_path = Path("se.data.geckodriver", "geckodriver-macos")
elif possible_system_geckodriver is not None:
geckodriver_path = Path(possible_system_geckodriver)
else:
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[/].")

return webdriver.Firefox(firefox_profile=profile, options=options, service_log_path=os.devnull, executable_path=geckodriver_path)
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 a8850b1

Please sign in to comment.