Skip to content

Commit 85698c0

Browse files
Adding source as binding platform + version for tracing through the infrastructure. Separating version into a separate readable file to follow canonical Python packaging practice + relevant unit test. More details in code comments.
1 parent 2b85ae3 commit 85698c0

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

browserstack/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import browserstack.version
2+
3+
# Python modules report to module_name.__version__ with their version
4+
# Ref: https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names
5+
# With this, browserstack.__version__ will respond with <version>
6+
7+
__version__ = version.__version__

browserstack/local.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import subprocess, os, time, json, psutil
2+
import browserstack.version
23
from browserstack.local_binary import LocalBinary
34
from browserstack.bserrors import BrowserStackLocalError
45

6+
7+
# Python modules report to module_name.__version__ with their version
8+
# Ref: https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names
9+
# With this, browserstack.local.__version__ will respond with <version>
10+
__version__ = browserstack.version.__version__
11+
512
class Local:
613
def __init__(self, key=None, binary_path=None, **kwargs):
714
self.key = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else key
@@ -16,8 +23,11 @@ def __xstr(self, key, value):
1623
else:
1724
return ['-' + key, value]
1825

26+
def _get_version(self):
27+
return __version__
28+
1929
def _generate_cmd(self):
20-
cmd = [self.binary_path, '-d', 'start', '-logFile', self.local_logfile_path, self.key]
30+
cmd = [self.binary_path, '-d', 'start','--source', 'python-' + self._get_version() , '-logFile', self.local_logfile_path, self.key]
2131
for o in self.options.keys():
2232
if self.options.get(o) is not None:
2333
cmd = cmd + self.__xstr(o, self.options.get(o))

browserstack/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.2.3"

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
2+
3+
# Need to read the single-source-of-truth version file as text
4+
# Importing version_file here can open the door to a cyclic dependency
5+
def get_version(a_path):
6+
with open(a_path, 'r') as version_file:
7+
for a_line in version_file:
8+
if '__version__' in a_line:
9+
# Cleaning up all spaces and quotes around a string of the form __version__ = "x.y.z"
10+
return a_line.split("=")[1].split()[0].replace('"', '').replace("'","")
11+
raise RuntimeError("Unable to find version string.")
112
try:
213
from setuptools import setup
314
except ImportError:
415
from distutils.core import setup
516
setup(
617
name = 'browserstack-local',
718
packages = ['browserstack'],
8-
version = '1.2.2',
19+
version = get_version("browserstack/version.py"),
920
description = 'Python bindings for Browserstack Local',
1021
author = 'BrowserStack',
1122
author_email = '[email protected]',

tests/test_local.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def test_multiple(self):
2727
except BrowserStackLocalError as e:
2828
self.assertEqual(str(e), "Either another browserstack local client is running on your machine or some server is listening on port 45691")
2929

30+
def test_version(self):
31+
self.assertEqual("1.2.3", self.local._get_version())
32+
3033
def test_verbose(self):
3134
self.local.start(v=True, onlyCommand=True)
3235
self.assertIn('-v', self.local._generate_cmd())

0 commit comments

Comments
 (0)