From 0c3553c8384d53b4f8351d3a7951355b5d14035a Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 7 Jul 2024 19:46:48 -0600 Subject: [PATCH] [py] Remove precompiled binaries from sdist Python sdist's should not contain precompiled architecture binaries that are architecture specific. They should contain the sources needed to build the binaries instead. --- py/BUILD.bazel | 7 +++++++ py/pyproject.toml | 3 +++ py/selenium/webdriver/common/selenium_manager.py | 8 ++++++++ py/setup.py | 7 +++++++ rust/BUILD.bazel | 15 +++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 py/pyproject.toml diff --git a/py/BUILD.bazel b/py/BUILD.bazel index ffab701e9555e..b54ae66aca8ac 100644 --- a/py/BUILD.bazel +++ b/py/BUILD.bazel @@ -230,10 +230,17 @@ pkg_files( "CHANGES", "MANIFEST.in", "README.rst", + "pyproject.toml", "setup.py", ":license", ":selenium-pkg", ":selenium-pkginfo", + "//rust:selenium_manager_srcs", + ], + excludes = [ + ":manager-linux", + ":manager-macos", + ":manager-windows", ], strip_prefix = strip_prefix.from_pkg(), ) diff --git a/py/pyproject.toml b/py/pyproject.toml new file mode 100644 index 0000000000000..ab3097982a60d --- /dev/null +++ b/py/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "setuptools-rust"] +build-backend = "setuptools.build_meta" diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index 46e23f52b606e..7aad4bdc85342 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -20,6 +20,7 @@ import platform import subprocess import sys +import sysconfig from pathlib import Path from typing import List @@ -61,9 +62,16 @@ def _get_binary() -> Path: :Raises: WebDriverException if the platform is unsupported """ + compiled_path = Path(__file__).parent.joinpath("selenium-manager") + exe = sysconfig.get_config_var("EXE") + if exe is not None: + compiled_path = compiled_path.with_suffix(exe) + if (path := os.getenv("SE_MANAGER_PATH")) is not None: logger.debug("Selenium Manager set by env SE_MANAGER_PATH to: %s", path) path = Path(path) + elif compiled_path.exists(): + path = compiled_path else: allowed = { ("darwin", "any"): "macos/selenium-manager", diff --git a/py/setup.py b/py/setup.py index 3086853df5488..06945930b90e1 100755 --- a/py/setup.py +++ b/py/setup.py @@ -19,6 +19,7 @@ from os.path import dirname, join, abspath from setuptools import setup from setuptools.command.install import install +from setuptools_rust import Binding, RustExtension for scheme in INSTALL_SCHEMES.values(): @@ -83,6 +84,12 @@ "typing_extensions~= 4.9.0", "websocket-client==1.8.0", ], + 'rust_extensions': [ + RustExtension( + {"selenium-manager": "selenium.webdriver.common.selenium-manager"}, + binding=Binding.Exec + ) + ], 'zip_safe': False } diff --git a/rust/BUILD.bazel b/rust/BUILD.bazel index ecf902486e711..12b51c6e582a2 100644 --- a/rust/BUILD.bazel +++ b/rust/BUILD.bazel @@ -95,6 +95,21 @@ rust_library( deps = all_crate_deps(normal = True), ) +filegroup( + name = "selenium_manager_srcs", + srcs = [ + "Cargo.lock", + "Cargo.toml", + ":selenium_manager_rs_srcs", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "selenium_manager_rs_srcs", + srcs = glob(["src/**/*.rs"]), +) + rust_test( name = "unit", size = "small",