|
5 | 5 | import threading
|
6 | 6 | from concurrent import futures
|
7 | 7 | from os import path
|
8 |
| - |
| 8 | +import pkg_resources |
9 | 9 | import grpc
|
| 10 | +import json |
10 | 11 |
|
11 | 12 | from getgauge import connection, processor
|
12 | 13 | from getgauge import lsp_server
|
13 | 14 | from getgauge.impl_loader import copy_skel_files
|
14 | 15 | from getgauge.messages import lsp_pb2_grpc
|
15 | 16 | from getgauge.static_loader import load_files
|
16 | 17 | from getgauge.util import get_step_impl_dir
|
| 18 | +from distutils import version |
| 19 | +from subprocess import Popen, PIPE |
17 | 20 |
|
| 21 | +PLUGIN_JSON = 'python.json' |
| 22 | +VERSION = 'version' |
18 | 23 |
|
19 | 24 | def main():
|
20 | 25 | _init_logger()
|
21 | 26 | logging.info("Python: {}".format(platform.python_version()))
|
22 | 27 | if sys.argv[1] == "--init":
|
23 | 28 | copy_skel_files()
|
24 | 29 | 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) |
27 | 45 |
|
| 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 '' |
28 | 54 |
|
29 | 55 | def load_implementations():
|
30 | 56 | d = get_step_impl_dir()
|
|
0 commit comments