@@ -27,7 +27,7 @@ const LOG_TAG = "CLI";
2727const VIRTUAL_ENVIRONMENT_DIR = process . env . VIRTUAL_ENV || path . join ( process . cwd ( ) , ".venv" ) ;
2828
2929// The version of glean_parser to install from PyPI.
30- const GLEAN_PARSER_VERSION = "8.1.1 " ;
30+ const GLEAN_PARSER_VERSION = "8.1" ;
3131
3232// This script runs a given Python module as a "main" module, like
3333// `python -m module`. However, it first checks that the installed
@@ -51,20 +51,43 @@ except ImportError:
5151 found_version = None
5252else:
5353 found_version = getattr(module, '__version__')
54- if found_version != expected_version:
55- if not offline:
56- subprocess.check_call([
57- sys.executable,
58- '-m',
59- 'pip',
60- 'install',
61- '--upgrade',
62- f'{module_name}=={expected_version}'
63- ])
54+
55+ if not offline:
56+ # When running in online mode, we always install.
57+ # If it is installed this is essentially a no-op,
58+ # otherwise it installs/upgrades.
59+ if 'git' in expected_version:
60+ target=expected_version
6461 else:
65- print(f'Using Python environment at {sys.executable},')
66- print(f'expected glean_parser version {expected_version}, found {found_version}.')
62+ target=f'{module_name}~={expected_version}'
63+
64+ subprocess.check_call([
65+ sys.executable,
66+ '-m',
67+ 'pip',
68+ 'install',
69+ '--upgrade',
70+ target
71+ ])
72+ else:
73+ error_text = f'''
74+ Using Python environment at {sys.executable},
75+ expected glean_parser version ~={expected_version}, found {found_version}.
76+ '''
77+
78+ if found_version is None:
79+ print(error_text)
6780 sys.exit(1)
81+ else:
82+ # We check MAJOR.MINOR only
83+ expected_ver = expected_version.split('.')
84+ expected_maj, expected_min = int(expected_ver[0]), int(expected_ver[1])
85+ current_ver = found_version.split('.')
86+ current_maj, current_min = int(current_ver[0]), int(current_ver[1])
87+
88+ if current_maj > expected_maj or current_maj < expected_maj or (current_maj == expected_maj and current_min < expected_min):
89+ print(error_text)
90+ sys.exit(1)
6891try:
6992 subprocess.check_call([
7093 sys.executable,
0 commit comments