Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python undetected chromedriver #316536

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11383,6 +11383,12 @@
githubId = 1769386;
name = "Liam Diprose";
};
liammurphy14 = {
email = "[email protected]";
github = "liam-murphy14";
githubId = 54590679;
name = "Liam Murphy";
};
liarokapisv = {
email = "[email protected]";
github = "liarokapisv";
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ];
};
}

Original file line number Diff line number Diff line change
@@ -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])

2 changes: 2 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down