Skip to content

Commit 757ed6a

Browse files
Merge pull request #2226 from JoelStalin/master
Refactor: Update for Python 3.13+ compatibility
2 parents 0aa5fbe + c50b6a2 commit 757ed6a

File tree

3 files changed

+96
-74
lines changed

3 files changed

+96
-74
lines changed

setup.py

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
1-
"""
2-
3-
888 888 d8b
4-
888 888 Y8P
5-
888 888
6-
.d8888b 88888b. 888d888 .d88b. 88888b.d88b. .d88b. .d88888 888d888 888 888 888 .d88b. 888d888
7-
d88P" 888 "88b 888P" d88""88b 888 "888 "88b d8P Y8b d88" 888 888P" 888 888 888 d8P Y8b 888P"
8-
888 888 888 888 888 888 888 888 888 88888888 888 888 888 888 Y88 88P 88888888 888
9-
Y88b. 888 888 888 Y88..88P 888 888 888 Y8b. Y88b 888 888 888 Y8bd8P Y8b. 888
10-
"Y8888P 888 888 888 "Y88P" 888 888 888 "Y8888 "Y88888 888 888 Y88P "Y8888 888 88888888
11-
12-
BY ULTRAFUNKAMSTERDAM (https://github.com/ultrafunkamsterdam)"""
13-
14-
import codecs
15-
import os
16-
import re
17-
18-
from setuptools import setup
19-
20-
21-
dirname = os.path.abspath(os.path.dirname(__file__))
22-
23-
with codecs.open(
24-
os.path.join(dirname, "undetected_chromedriver", "__init__.py"),
25-
mode="r",
26-
encoding="utf-8",
27-
) as fp:
28-
try:
29-
version = re.findall(r"^__version__ = ['\"]([^'\"]*)['\"]", fp.read(), re.M)[0]
30-
except Exception:
31-
raise RuntimeError("unable to determine version")
32-
33-
description = (
34-
"Selenium.webdriver.Chrome replacement with compatiblity for Brave, and other Chromium based browsers.",
35-
"Not triggered by CloudFlare/Imperva/hCaptcha and such.",
36-
"NOTE: results may vary due to many factors. No guarantees are given, except for ongoing efforts in understanding detection algorithms.",
37-
)
38-
39-
setup(
40-
name="undetected-chromedriver",
41-
version=version,
42-
packages=["undetected_chromedriver"],
43-
install_requires=[
44-
"selenium>=4.9.0",
45-
"requests",
46-
"websockets",
47-
],
48-
package_data={"undetected_chromedriver": [os.path.join("example", "example.py")]},
49-
url="https://github.com/ultrafunkamsterdam/undetected-chromedriver",
50-
license="GPL-3.0",
51-
author="UltrafunkAmsterdam",
52-
author_email="[email protected]",
53-
description=description,
54-
long_description=open(os.path.join(dirname, "README.md"), encoding="utf-8").read(),
55-
long_description_content_type="text/markdown",
56-
classifiers=[
57-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
58-
"Programming Language :: Python :: 3",
59-
"Programming Language :: Python :: 3.7",
60-
"Programming Language :: Python :: 3.8",
61-
"Programming Language :: Python :: 3.9",
62-
"Programming Language :: Python :: 3.10",
63-
"Programming Language :: Python :: 3.11",
64-
],
65-
)
1+
"""
2+
3+
888 888 d8b
4+
888 888 Y8P
5+
888 888
6+
.d8888b 88888b. 888d888 .d88b. 88888b.d88b. .d88b. .d88888 888d888 888 888 888 .d88b. 888d888
7+
d88P" 888 "88b 888P" d88""88b 888 "888 "88b d8P Y8b d88" 888 888P" 888 888 888 d8P Y8b 888P"
8+
888 888 888 888 888 888 888 888 888 88888888 888 888 888 888 Y88 88P 88888888 888
9+
Y88b. 888 888 888 Y88..88P 888 888 888 Y8b. Y88b 888 888 888 Y8bd8P Y8b. 888
10+
"Y8888P 888 888 888 "Y88P" 888 888 888 "Y8888 "Y88888 888 888 Y88P "Y8888 888 88888888
11+
12+
BY ULTRAFUNKAMSTERDAM (https://github.com/ultrafunkamsterdam)"""
13+
14+
import os
15+
import re
16+
17+
from setuptools import setup
18+
19+
20+
dirname = os.path.abspath(os.path.dirname(__file__))
21+
22+
with open(
23+
os.path.join(dirname, "undetected_chromedriver", "__init__.py"),
24+
mode="r",
25+
encoding="utf-8",
26+
) as fp:
27+
try:
28+
version = re.findall(r"^__version__ = ['\"]([^'\"]*)['\"]", fp.read(), re.M)[0]
29+
except Exception:
30+
raise RuntimeError("unable to determine version")
31+
32+
description = (
33+
"Selenium.webdriver.Chrome replacement with compatiblity for Brave, and other Chromium based browsers.",
34+
"Not triggered by CloudFlare/Imperva/hCaptcha and such.",
35+
"NOTE: results may vary due to many factors. No guarantees are given, except for ongoing efforts in understanding detection algorithms.",
36+
)
37+
38+
setup(
39+
name="undetected-chromedriver",
40+
version=version,
41+
packages=["undetected_chromedriver"],
42+
install_requires=[
43+
"selenium>=4.18.1", # Updated to latest as of Mar 2024
44+
"requests>=2.31.0", # Updated to latest as of Mar 2024
45+
"websockets>=12.0", # Updated to latest as of Mar 2024
46+
"packaging>=23.0", # Specify a recent version
47+
],
48+
package_data={"undetected_chromedriver": [os.path.join("example", "example.py")]},
49+
url="https://github.com/ultrafunkamsterdam/undetected-chromedriver",
50+
license="GPL-3.0",
51+
author="UltrafunkAmsterdam",
52+
author_email="[email protected]",
53+
description=description,
54+
long_description=open(os.path.join(dirname, "README.md"), encoding="utf-8").read(),
55+
long_description_content_type="text/markdown",
56+
classifiers=[
57+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
58+
"Programming Language :: Python :: 3",
59+
"Programming Language :: Python :: 3.7",
60+
"Programming Language :: Python :: 3.8",
61+
"Programming Language :: Python :: 3.9",
62+
"Programming Language :: Python :: 3.10",
63+
"Programming Language :: Python :: 3.11",
64+
"Programming Language :: Python :: 3.12", # Assuming 3.12 is also supported
65+
"Programming Language :: Python :: 3.13",
66+
],
67+
)

undetected_chromedriver/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def __init__(
463463
self.patcher.executable_path
464464
)
465465

466-
super(Chrome, self).__init__(
466+
super().__init__(
467467
service=service,
468468
options=options,
469469
keep_alive=keep_alive,
@@ -721,10 +721,8 @@ def reconnect(self, timeout=0.1):
721721
def start_session(self, capabilities=None, browser_profile=None):
722722
if not capabilities:
723723
capabilities = self.options.to_capabilities()
724-
super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
725-
capabilities
726-
)
727-
# super(Chrome, self).start_session(capabilities, browser_profile)
724+
super().start_session(capabilities)
725+
# super(Chrome, self).start_session(capabilities, browser_profile) # Original explicit call commented out
728726

729727
def find_elements_recursive(self, by, value):
730728
"""

undetected_chromedriver/patcher.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# this module is part of undetected_chromedriver
33

4-
from distutils.version import LooseVersion
4+
from packaging.version import Version as LooseVersion
55
import io
66
import json
77
import logging
@@ -12,6 +12,7 @@
1212
import re
1313
import shutil
1414
import string
15+
import subprocess
1516
import sys
1617
import time
1718
from urllib.request import urlopen
@@ -323,10 +324,31 @@ def force_kill_instances(exe_name):
323324
"""
324325
exe_name = os.path.basename(exe_name)
325326
if IS_POSIX:
326-
r = os.system("kill -f -9 $(pidof %s)" % exe_name)
327+
# Using shell=True for pidof, consider a more robust pid finding method if issues arise.
328+
# pgrep can be an alternative: ["pgrep", "-f", exe_name]
329+
# Or psutil if adding a dependency is acceptable.
330+
command = f"pidof {exe_name}"
331+
try:
332+
result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)
333+
pids = result.stdout.strip().split()
334+
if pids:
335+
subprocess.run(["kill", "-9"] + pids, check=False) # Changed from -f -9 to -9 as -f is not standard for kill
336+
return True
337+
return False # No PIDs found
338+
except subprocess.CalledProcessError: # pidof returns 1 if no process found
339+
return False # No process found
340+
except Exception as e:
341+
logger.debug(f"Error killing process on POSIX: {e}")
342+
return False
327343
else:
328-
r = os.system("taskkill /f /im %s" % exe_name)
329-
return not r
344+
try:
345+
# TASKKILL /F /IM chromedriver.exe
346+
result = subprocess.run(["taskkill", "/f", "/im", exe_name], check=False, capture_output=True)
347+
# taskkill returns 0 if process was killed, 128 if not found.
348+
return result.returncode == 0
349+
except Exception as e:
350+
logger.debug(f"Error killing process on Windows: {e}")
351+
return False
330352

331353
@staticmethod
332354
def gen_random_cdc():

0 commit comments

Comments
 (0)