check_version.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright 2016 gRPC authors.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import os
18 import re
19 import subprocess
20 import sys
21 
22 import yaml
23 
24 errors = 0
25 
26 os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
27 
28 # hack import paths to pick up extra code
29 sys.path.insert(0, os.path.abspath('tools/buildgen/plugins'))
30 from expand_version import Version
31 
32 try:
33  branch_name = subprocess.check_output('git rev-parse --abbrev-ref HEAD',
34  shell=True).decode()
35 except:
36  print('WARNING: not a git repository')
37  branch_name = None
38 
39 if branch_name is not None:
40  m = re.match(r'^release-([0-9]+)_([0-9]+)$', branch_name)
41  if m:
42  print('RELEASE branch')
43  # version number should align with the branched version
44  check_version = lambda version: (version.major == int(m.group(1)) and
45  version.minor == int(m.group(2)))
46  warning = 'Version key "%%s" value "%%s" should have a major version %s and minor version %s' % (
47  m.group(1), m.group(2))
48  elif re.match(r'^debian/.*$', branch_name):
49  # no additional version checks for debian branches
50  check_version = lambda version: True
51  else:
52  # all other branches should have a -dev tag
53  check_version = lambda version: version.tag == 'dev'
54  warning = 'Version key "%s" value "%s" should have a -dev tag'
55 else:
56  check_version = lambda version: True
57 
58 with open('build_handwritten.yaml', 'r') as f:
59  build_yaml = yaml.load(f.read())
60 
61 settings = build_yaml['settings']
62 
63 top_version = Version(settings['version'])
64 if not check_version(top_version):
65  errors += 1
66  print((warning % ('version', top_version)))
67 
68 for tag, value in list(settings.items()):
69  if re.match(r'^[a-z]+_version$', tag):
70  value = Version(value)
71  if tag != 'core_version':
72  if value.major != top_version.major:
73  errors += 1
74  print(('major version mismatch on %s: %d vs %d' %
75  (tag, value.major, top_version.major)))
76  if value.minor != top_version.minor:
77  errors += 1
78  print(('minor version mismatch on %s: %d vs %d' %
79  (tag, value.minor, top_version.minor)))
80  if not check_version(value):
81  errors += 1
82  print((warning % (tag, value)))
83 
84 sys.exit(errors)
xds_interop_client.int
int
Definition: xds_interop_client.py:113
grpc._common.decode
def decode(b)
Definition: grpc/_common.py:75
check_version
Definition: check_version.py:1
expand_version.Version
Definition: expand_version.py:35
open
#define open
Definition: test-fs.c:46


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:45