From 6e62dced2fcc2b03d593c0d4698c774c4ff3c547 Mon Sep 17 00:00:00 2001 From: liam-murphy14 Date: Sun, 31 Dec 2023 17:00:34 -0800 Subject: [PATCH] python3Packages.undetected-chromedriver: init at 3.5.5 --- .../undetected-chromedriver/default.nix | 85 +++++++++++++++++++ .../patchChromedriver.py | 8 ++ pkgs/top-level/python-packages.nix | 2 + 3 files changed, 95 insertions(+) create mode 100644 pkgs/development/python-modules/undetected-chromedriver/default.nix create mode 100755 pkgs/development/python-modules/undetected-chromedriver/patchChromedriver.py diff --git a/pkgs/development/python-modules/undetected-chromedriver/default.nix b/pkgs/development/python-modules/undetected-chromedriver/default.nix new file mode 100644 index 0000000000000..00c3bb86f17f5 --- /dev/null +++ b/pkgs/development/python-modules/undetected-chromedriver/default.nix @@ -0,0 +1,85 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, pythonOlder +, pythonAtLeast +, selenium +, requests +, websockets +, chromedriver +, python3 +}: + +let + patchPythonPath = ./patchChromedriver.py; + chromedriverPackage = chromedriver; +in + +buildPythonPackage { + pname = "undetected-chromedriver"; + version = "3.5.5"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "ultrafunkamsterdam"; + repo = "undetected-chromedriver"; + rev = "0aa5fbe252370b4cb2b95526add445392cad27ba"; + hash = "sha256-Qe+GrsUPnhjJMDgjdUCloapjj0ggFlm/Dr42WLcmb1o="; + }; + + disabled = pythonOlder "3.7" || pythonAtLeast "3.12"; + + + buildInputs = [ + chromedriverPackage + ]; + + propagatedBuildInputs = [ + selenium + requests + websockets + ]; + + # remove items that cause build failures on NixOS, and add the binary driver path so that it + # does not try to download and patch at runtime + postConfigure = '' + substituteInPlace undetected_chromedriver/patcher.py \ + --replace "os.makedirs(self.data_path, exist_ok=True)" "print('test 1')" \ + --replace "os.makedirs(self.zip_path, mode=0o755, exist_ok=True)" "print('test 2')" + substituteInPlace undetected_chromedriver/__init__.py \ + --replace "driver_executable_path=None," "driver_executable_path='$out/bin/chromedriver'," + ''; + + # run the patch script now since chromedriver won't be writeable after this + # need to use glob wildcard because chromedriver is packaged with extra + # libraries on darwin platforms that must be copied to $out/bin + postFixup = '' + mkdir mutableChromedriverBin + cp ${chromedriverPackage.out}/bin/* mutableChromedriverBin + chmod +w mutableChromedriverBin/chromedriver + ${python3.out}/bin/python3 ${patchPythonPath} mutableChromedriverBin/chromedriver + mkdir $out/bin + cp mutableChromedriverBin/* $out/bin + ''; + + pythonImportsCheck = [ + "undetected_chromedriver" + ]; + + meta = with lib; { + homepage = "https://github.com/UltrafunkAmsterdam/undetected-chromedriver"; + changelog = "https://github.com/ultrafunkamsterdam/undetected-chromedriver/blob/master/README.md"; + license = licenses.gpl3Only; + description = '' + Selenium.webdriver.Chrome replacement with compatiblity for Brave, and other Chromium based browsers. + ''; + # undetected-chromedriver will attempt to install a compatible chromedriver binary + # when undetected-chromedriver.Chrome is instantiated if one is not found in + # $PATH or passed explicitly as an argument to the constructor + # this will fail on nixos, so we also install and add the patched version of + # chromedriver to path with this library + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + maintainers = with maintainers; [ liammurphy14 toasteruwu ]; + }; +} + diff --git a/pkgs/development/python-modules/undetected-chromedriver/patchChromedriver.py b/pkgs/development/python-modules/undetected-chromedriver/patchChromedriver.py new file mode 100755 index 0000000000000..66c74077327c9 --- /dev/null +++ b/pkgs/development/python-modules/undetected-chromedriver/patchChromedriver.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +import undetected_chromedriver as uc + +if __name__ == "__main__": + uc.Patcher(executable_path=sys.argv[1]).auto(executable_path=sys.argv[1]) + diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 983d0d25bb970..291852264b200 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -16648,6 +16648,8 @@ self: super: with self; { undefined = callPackage ../development/python-modules/undefined { }; + undetected-chromedriver = callPackage ../development/python-modules/undetected-chromedriver { }; + unearth = callPackage ../development/python-modules/unearth { }; unicodecsv = callPackage ../development/python-modules/unicodecsv { };