5
5
from browserstack .bserrors import BrowserStackLocalError
6
6
7
7
logger = logging .getLogger (__name__ )
8
+ try :
9
+ from importlib .metadata import version as package_version , PackageNotFoundError
10
+ except :
11
+ import pkg_resources
8
12
9
13
class Local :
10
14
def __init__ (self , key = None , binary_path = None , ** kwargs ):
@@ -22,8 +26,30 @@ def __xstr(self, key, value):
22
26
else :
23
27
return ['-' + key , value ]
24
28
29
+ def get_package_version (self ):
30
+ name = "browserstack-local"
31
+ version = 'None'
32
+ use_fallback = False
33
+ try :
34
+ temp = package_version
35
+ except NameError : # Only catch if package_version is not defined(and not other errors)
36
+ use_fallback = True
37
+
38
+ if use_fallback :
39
+ try :
40
+ version = pkg_resources .get_distribution (name ).version
41
+ except pkg_resources .DistributionNotFound :
42
+ version = 'None'
43
+ else :
44
+ try :
45
+ version = package_version (name )
46
+ except PackageNotFoundError :
47
+ version = 'None'
48
+
49
+ return version
50
+
25
51
def _generate_cmd (self ):
26
- cmd = [self .binary_path , '-d' , 'start' , '-logFile' , self .local_logfile_path , "-k" , self .key ]
52
+ cmd = [self .binary_path , '-d' , 'start' , '-logFile' , self .local_logfile_path , "-k" , self .key , '--source' , 'python:' + self . get_package_version () ]
27
53
for o in self .options .keys ():
28
54
if self .options .get (o ) is not None :
29
55
cmd = cmd + self .__xstr (o , self .options .get (o ))
@@ -55,7 +81,11 @@ def start(self, **kwargs):
55
81
if "onlyCommand" in kwargs and kwargs ["onlyCommand" ]:
56
82
return
57
83
58
- self .proc = subprocess .Popen ('ls' , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
84
+
85
+ if 'source' in self .options :
86
+ del self .options ['source' ]
87
+
88
+ self .proc = subprocess .Popen (self ._generate_cmd (), stdout = subprocess .PIPE , stderr = subprocess .PIPE )
59
89
(out , err ) = self .proc .communicate ()
60
90
61
91
os .system ('echo "" > "' + self .local_logfile_path + '"' )
0 commit comments