Skip to content

Commit e0f37cf

Browse files
authored
Checking for gauge-python and getgauge version mismatch #53
1 parent d58643b commit e0f37cf

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

start.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,52 @@
55
import threading
66
from concurrent import futures
77
from os import path
8-
8+
import pkg_resources
99
import grpc
10+
import json
1011

1112
from getgauge import connection, processor
1213
from getgauge import lsp_server
1314
from getgauge.impl_loader import copy_skel_files
1415
from getgauge.messages import lsp_pb2_grpc
1516
from getgauge.static_loader import load_files
1617
from getgauge.util import get_step_impl_dir
18+
from distutils import version
19+
from subprocess import Popen, PIPE
1720

21+
PLUGIN_JSON = 'python.json'
22+
VERSION = 'version'
1823

1924
def main():
2025
_init_logger()
2126
logging.info("Python: {}".format(platform.python_version()))
2227
if sys.argv[1] == "--init":
2328
copy_skel_files()
2429
else:
25-
load_implementations()
26-
start()
30+
python_plugin_version = get_version()
31+
getgauge_version = version.LooseVersion(pkg_resources.get_distribution('getgauge').version)
32+
if list(map(int, python_plugin_version.split(".")[0:2])) != getgauge_version.version[0:2]:
33+
show_error_exit(python_plugin_version, getgauge_version)
34+
if 'dev' in getgauge_version.version and 'nightly' in python_plugin_version:
35+
python_plugin_version.replace("-","")
36+
if python_plugin_version.find(str(getgauge_version.version.pop())) == -1:
37+
show_error_exit(python_plugin_version, getgauge_version)
38+
else:
39+
load_implementations()
40+
start()
41+
42+
def show_error_exit(pythonPluginVersion, getgaugeVersion):
43+
logging.fatal('Gauge-python({}) is not compatible with getgauge({}). Please install compatible versions.\n'.format(pythonPluginVersion, getgaugeVersion))
44+
exit(1)
2745

46+
def get_version():
47+
proc = Popen(['gauge', '-v', '--machine-readable'], stdout=PIPE, stderr=PIPE)
48+
out, _ = proc.communicate()
49+
data = json.loads(str(out.decode()))
50+
for plugin in data['plugins']:
51+
if plugin['name'] == 'python':
52+
return plugin['version']
53+
return ''
2854

2955
def load_implementations():
3056
d = get_step_impl_dir()

0 commit comments

Comments
 (0)