_driver.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) Microsoft Corporation.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import inspect
  15. import os
  16. import sys
  17. from pathlib import Path
  18. from typing import Tuple
  19. import playwright
  20. from playwright._repo_version import version
  21. def compute_driver_executable() -> Tuple[str, str]:
  22. driver_path = Path(inspect.getfile(playwright)).parent / "driver"
  23. cli_path = str(driver_path / "package" / "cli.js")
  24. if sys.platform == "win32":
  25. return (
  26. os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node.exe")),
  27. cli_path,
  28. )
  29. return (os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node")), cli_path)
  30. def get_driver_env() -> dict:
  31. env = os.environ.copy()
  32. env["PW_LANG_NAME"] = "python"
  33. env["PW_LANG_NAME_VERSION"] = f"{sys.version_info.major}.{sys.version_info.minor}"
  34. env["PW_CLI_DISPLAY_VERSION"] = version
  35. return env