Skip to content

Commit

Permalink
Adding source as binding platform + version for tracing through the i…
Browse files Browse the repository at this point in the history
…nfrastructure. Separating version into a separate readable file to follow canonical Python packaging practice + relevant unit test. More details in code comments.
  • Loading branch information
abhishekchoudhary committed Jan 11, 2021
1 parent 2b85ae3 commit 03df99c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions browserstack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import version

# Python modules report to module_name.__version__ with their version
# Ref: https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names
# With this, browserstack.__version__ will respond with <version>

__version__ = version.__version__
12 changes: 11 additions & 1 deletion browserstack/local.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import subprocess, os, time, json, psutil
import version
from browserstack.local_binary import LocalBinary
from browserstack.bserrors import BrowserStackLocalError


# Python modules report to module_name.__version__ with their version
# Ref: https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names
# With this, browserstack.local.__version__ will respond with <version>
__version__ = version.__version__

class Local:
def __init__(self, key=None, binary_path=None, **kwargs):
self.key = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else key
Expand All @@ -16,8 +23,11 @@ def __xstr(self, key, value):
else:
return ['-' + key, value]

def _get_version(self):
return __version__

def _generate_cmd(self):
cmd = [self.binary_path, '-d', 'start', '-logFile', self.local_logfile_path, self.key]
cmd = [self.binary_path, '-d', 'start','--source', 'python-' + self._get_version() , '-logFile', self.local_logfile_path, self.key]
for o in self.options.keys():
if self.options.get(o) is not None:
cmd = cmd + self.__xstr(o, self.options.get(o))
Expand Down
1 change: 1 addition & 0 deletions browserstack/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.2.3"
13 changes: 12 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@


# Need to read the single-source-of-truth version file as text
# Importing version_file here can open the door to a cyclic dependency
def get_version(a_path):
with open(a_path, 'r') as version_file:
for a_line in version_file:
if '__version__' in a_line:
# Cleaning up all spaces and quotes around a string of the form __version__ = "x.y.z"
return a_line.split("=")[1].split()[0].replace('"', '').replace("'","")
raise RuntimeError("Unable to find version string.")
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(
name = 'browserstack-local',
packages = ['browserstack'],
version = '1.2.2',
version = get_version("browserstack/version.py"),
description = 'Python bindings for Browserstack Local',
author = 'BrowserStack',
author_email = '[email protected]',
Expand Down
3 changes: 3 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def test_multiple(self):
except BrowserStackLocalError as e:
self.assertEqual(str(e), "Either another browserstack local client is running on your machine or some server is listening on port 45691")

def test_version(self):
self.assertEqual("1.2.3", self.local._get_version())

def test_verbose(self):
self.local.start(v=True, onlyCommand=True)
self.assertIn('-v', self.local._generate_cmd())
Expand Down

0 comments on commit 03df99c

Please sign in to comment.