Skip to content

Commit 0a6e781

Browse files
authored
Merge pull request #1750 from mozilla/gleanparser-allow-any-patch-version
2 parents a456018 + ee3cb05 commit 0a6e781

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

docs/guides/update_glean_parser.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
To update the version of glean_parser used by the Glean.js, run the `bin/update-glean-parser-version.sh` script, providing the version as a command line parameter:
44

55
```bash
6-
bin/update-glean-parser-version.sh 1.28.3
6+
bin/update-glean-parser-version.sh 1.28
77
```
88

9+
It's enough to specify `MINOR.MAJOR`.
10+
911
This will update the version in all the required places and create a commit with the changes. After that, you just need to create a pull request with the changes.
1012

1113
No further action is required.

glean/src/cli.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const LOG_TAG = "CLI";
2727
const 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
5252
else:
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)
6891
try:
6992
subprocess.check_call([
7093
sys.executable,

0 commit comments

Comments
 (0)