Wrapper for getting information from the Selenium Manager binaries. This implementation is still in beta, and may change.
| 30 | |
| 31 | |
| 32 | class SeleniumManager: |
| 33 | """Wrapper for getting information from the Selenium Manager binaries. |
| 34 | |
| 35 | This implementation is still in beta, and may change. |
| 36 | """ |
| 37 | |
| 38 | def binary_paths(self, args: list) -> dict: |
| 39 | """Determines the locations of the requested assets. |
| 40 | |
| 41 | Args: |
| 42 | args: the commands to send to the selenium manager binary. |
| 43 | |
| 44 | Returns: |
| 45 | Dictionary of assets and their path. |
| 46 | """ |
| 47 | args = [str(self._get_binary())] + args |
| 48 | if logger.getEffectiveLevel() == logging.DEBUG: |
| 49 | args.append("--debug") |
| 50 | args.append("--language-binding") |
| 51 | args.append("python") |
| 52 | args.append("--output") |
| 53 | args.append("json") |
| 54 | |
| 55 | return self._run(args) |
| 56 | |
| 57 | @staticmethod |
| 58 | def _get_binary() -> Path: |
| 59 | """Determines the path of the Selenium Manager binary. |
| 60 | |
| 61 | Location of the binary is checked in this order: |
| 62 | |
| 63 | 1. location set in an environment variable |
| 64 | 2. location where setuptools-rust places the compiled binary (built from the sdist package) |
| 65 | 3. location where we ship binaries in the wheel package for the platform this is running on |
| 66 | 4. give up |
| 67 | |
| 68 | Returns: |
| 69 | The Selenium Manager executable location. |
| 70 | |
| 71 | Raises: |
| 72 | WebDriverException: If the platform is unsupported or Selenium Manager executable can't be found. |
| 73 | """ |
| 74 | compiled_path = Path(__file__).parent.joinpath("selenium-manager") |
| 75 | exe = sysconfig.get_config_var("EXE") |
| 76 | if exe is not None: |
| 77 | compiled_path = compiled_path.with_suffix(exe) |
| 78 | |
| 79 | path: Path | None = None |
| 80 | |
| 81 | if (env_path := os.getenv("SE_MANAGER_PATH")) is not None: |
| 82 | logger.debug(f"Selenium Manager set by env SE_MANAGER_PATH to: {env_path}") |
| 83 | path_candidate = Path(env_path) |
| 84 | if not path_candidate.is_file(): |
| 85 | raise WebDriverException(f"SE_MANAGER_PATH does not point to a file: {env_path}") |
| 86 | path = path_candidate |
| 87 | elif compiled_path.is_file(): |
| 88 | path = compiled_path |
| 89 | else: |
no outgoing calls