Skip to content

Commit 791eeb0

Browse files
authored
Merge pull request #1410 from seleniumbase/reduce-python-dependencies
Reduce required Python dependencies
2 parents 6734c10 + 8ccafe7 commit 791eeb0

File tree

7 files changed

+66
-27
lines changed

7 files changed

+66
-27
lines changed

requirements.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,12 @@ pymysql==0.10.1;python_version<"3.6"
106106
pymysql==1.0.2;python_version>="3.6"
107107
pyotp==2.3.0;python_version<"3.6"
108108
pyotp==2.6.0;python_version>="3.6"
109-
boto==2.49.0
110109
cffi==1.15.1
111110
toml==0.10.2
112-
Pillow==6.2.2;python_version<"3.6"
113-
Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"
114-
Pillow==9.2.0;python_version>="3.7"
115111
typing-extensions==3.10.0.2;python_version<"3.6"
116112
typing-extensions==4.1.1;python_version>="3.6" and python_version<"3.7"
117113
typing-extensions==4.2.0;python_version>="3.7" and python_version<"3.9"
118114
rich==12.5.1;python_version>="3.6" and python_version<"4.0"
119-
tornado==5.1.1;python_version<"3.6"
120-
tornado==6.1;python_version>="3.6" and python_version<"3.7"
121-
tornado==6.2;python_version>="3.7"
122-
pdfminer.six==20191110;python_version<"3.6"
123-
pdfminer.six==20211012;python_version>="3.6" and python_version<"3.7"
124-
pdfminer.six==20220524;python_version>="3.7"
125115

126116
# --- Testing Requirements --- #
127117
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "3.5.1"
2+
__version__ = "3.5.2"

seleniumbase/core/s3_manager.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Methods for uploading/managing files on Amazon S3.
33
"""
44
from seleniumbase.config import settings
5+
from seleniumbase.fixtures import shared_utils
56

67
already_uploaded_files = []
78

@@ -19,15 +20,23 @@ def __init__(
1920
selenium_access_key=settings.S3_SELENIUM_ACCESS_KEY,
2021
selenium_secret_key=settings.S3_SELENIUM_SECRET_KEY,
2122
):
22-
from boto.s3.connection import S3Connection
23+
try:
24+
from boto.s3.connection import S3Connection
25+
except Exception:
26+
shared_utils.pip_install("boto", version="2.49.0")
27+
from boto.s3.connection import S3Connection
2328

2429
self.conn = S3Connection(selenium_access_key, selenium_secret_key)
2530
self.bucket = self.conn.get_bucket(log_bucket)
2631
self.bucket_url = bucket_url
2732

2833
def get_key(self, file_name):
2934
"""Create a new Key instance with the given name."""
30-
from boto.s3.key import Key
35+
try:
36+
from boto.s3.key import Key
37+
except Exception:
38+
shared_utils.pip_install("boto", version="2.49.0")
39+
from boto.s3.key import Key
3140

3241
return Key(bucket=self.bucket, name=file_name)
3342

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,13 @@ def click(
413413
else:
414414
# A smaller subset of self.wait_for_ready_state_complete()
415415
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
416-
if self.driver.current_url != pre_action_url:
417-
self.__ad_block_as_needed()
416+
try:
417+
if self.driver.current_url != pre_action_url:
418+
self.__ad_block_as_needed()
419+
except Exception:
420+
self.wait_for_ready_state_complete()
421+
if self.driver.current_url != pre_action_url:
422+
self.__ad_block_as_needed()
418423
if self.browser == "safari":
419424
time.sleep(0.02)
420425
if self.demo_mode:
@@ -5493,7 +5498,12 @@ def get_pdf_text(
54935498

54945499
with warnings.catch_warnings():
54955500
warnings.simplefilter("ignore", category=UserWarning)
5496-
from pdfminer.high_level import extract_text
5501+
try:
5502+
from pdfminer.high_level import extract_text
5503+
except Exception:
5504+
shared_utils.pip_install("pdfminer.six")
5505+
from pdfminer.high_level import extract_text
5506+
54975507
if not password:
54985508
password = ""
54995509
if not maxpages:
@@ -5718,7 +5728,11 @@ def save_element_as_image_file(
57185728
file.write(element_png)
57195729
# Add a text overlay if given
57205730
if type(overlay_text) is str and len(overlay_text) > 0:
5721-
from PIL import Image, ImageDraw
5731+
try:
5732+
from PIL import Image, ImageDraw
5733+
except Exception:
5734+
shared_utils.pip_install("Pillow")
5735+
from PIL import Image, ImageDraw
57225736

57235737
text_rows = overlay_text.split("\n")
57245738
len_text_rows = len(text_rows)

seleniumbase/fixtures/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class Dashboard:
7373
DASH_PIE_PNG_3 = encoded_images.DASH_PIE_PNG_3 # Faster than CDN
7474

7575

76+
class PipInstall:
77+
LOCKFILE = Files.DOWNLOADS_FOLDER + "/pipinstall.lock"
78+
79+
7680
class SideBySide:
7781
HTML_FILE = "side_by_side.html"
7882
SIDE_BY_SIDE_PNG = encoded_images.SIDE_BY_SIDE_PNG

seleniumbase/fixtures/shared_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
This module contains shared utility methods.
33
"""
4+
import fasteners
5+
import subprocess
6+
import sys
47
import time
58
from selenium.common.exceptions import ElementNotVisibleException
69
from selenium.common.exceptions import NoAlertPresentException
@@ -9,9 +12,26 @@
912
from selenium.common.exceptions import NoSuchFrameException
1013
from selenium.common.exceptions import NoSuchWindowException
1114
from seleniumbase.common.exceptions import TextNotVisibleException
15+
from seleniumbase.fixtures import constants
1216
from seleniumbase import config as sb_config
1317

1418

19+
def pip_install(package, version=None):
20+
pip_install_lock = fasteners.InterProcessLock(
21+
constants.PipInstall.LOCKFILE
22+
)
23+
with pip_install_lock:
24+
if not version:
25+
subprocess.check_call(
26+
[sys.executable, "-m", "pip", "install", package]
27+
)
28+
else:
29+
package_and_version = package + "==" + str(version)
30+
subprocess.check_call(
31+
[sys.executable, "-m", "pip", "install", package_and_version]
32+
)
33+
34+
1535
def format_exc(exception, message):
1636
"""
1737
Formats an exception message to make the output cleaner.

setup.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,12 @@
231231
'pymysql==1.0.2;python_version>="3.6"',
232232
'pyotp==2.3.0;python_version<"3.6"',
233233
'pyotp==2.6.0;python_version>="3.6"',
234-
"boto==2.49.0",
235234
"cffi==1.15.1",
236235
"toml==0.10.2",
237-
'Pillow==6.2.2;python_version<"3.6"',
238-
'Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"',
239-
'Pillow==9.2.0;python_version>="3.7"',
240236
'typing-extensions==3.10.0.2;python_version<"3.6"', # <3.9 for "rich"
241237
'typing-extensions==4.1.1;python_version>="3.6" and python_version<"3.7"', # noqa: E501
242238
'typing-extensions==4.2.0;python_version>="3.7" and python_version<"3.9"', # noqa: E501
243239
'rich==12.5.1;python_version>="3.6" and python_version<"4.0"',
244-
'tornado==5.1.1;python_version<"3.6"',
245-
'tornado==6.1;python_version>="3.6" and python_version<"3.7"',
246-
'tornado==6.2;python_version>="3.7"',
247-
'pdfminer.six==20191110;python_version<"3.6"',
248-
'pdfminer.six==20211012;python_version>="3.6" and python_version<"3.7"', # noqa: E501
249-
'pdfminer.six==20220524;python_version>="3.7"',
250240
],
251241
extras_require={
252242
# pip install -e .[coverage]
@@ -269,6 +259,18 @@
269259
'pycodestyle==2.5.0;python_version<"3.6"',
270260
'pycodestyle==2.8.0;python_version>="3.6"',
271261
],
262+
# pip install -e .[pdfminer]
263+
"pdfminer": [
264+
'pdfminer.six==20191110;python_version<"3.6"',
265+
'pdfminer.six==20211012;python_version>="3.6" and python_version<"3.7"', # noqa: E501
266+
'pdfminer.six==20220524;python_version>="3.7"',
267+
],
268+
# pip install -e .[pillow]
269+
"pillow": [
270+
'Pillow==6.2.2;python_version<"3.6"',
271+
'Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"',
272+
'Pillow==9.2.0;python_version>="3.7"',
273+
],
272274
},
273275
packages=[
274276
"seleniumbase",

0 commit comments

Comments
 (0)