Skip to content

Commit 1b658d8

Browse files
committed
Add a method for installing dependencies as needed
1 parent 6734c10 commit 1b658d8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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.

0 commit comments

Comments
 (0)