Coverage for version.py: 0%
52 statements
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
1import os
2import re
3import subprocess
4import sys
5import traceback
7BASE_DIR = os.path.dirname(os.path.abspath(__file__))
8PLUGINS_DIRECTORY = os.path.join(BASE_DIR, 'recipes', 'plugins')
10version_info = []
11tandoor_tag = ''
12tandoor_hash = ''
13try:
14 print('getting tandoor version')
15 r = subprocess.check_output(['git', 'show', '-s'], cwd=BASE_DIR).decode()
16 tandoor_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=BASE_DIR).decode().replace('\n', '')
17 tandoor_hash = r.split('\n')[0].split(' ')[1]
18 try:
19 tandoor_tag = subprocess.check_output(['git', 'describe', '--exact-match', '--tags', tandoor_hash], cwd=BASE_DIR).decode().replace('\n', '')
20 except BaseException:
21 pass
23 version_info.append({
24 'name': 'Tandoor ',
25 'version': re.sub(r'<.*>', '', r),
26 'website': 'https://github.com/TandoorRecipes/recipes',
27 'commit_link': 'https://github.com/TandoorRecipes/recipes/commit/' + r.split('\n')[0].split(' ')[1],
28 'ref': tandoor_hash,
29 'branch': tandoor_branch,
30 'tag': tandoor_tag
31 })
33 if os.path.isdir(PLUGINS_DIRECTORY):
34 for d in os.listdir(PLUGINS_DIRECTORY):
35 if d != '__pycache__':
36 try:
37 apps_path = f'recipes.plugins.{d}.apps'
38 __import__(apps_path)
39 app_config_classname = dir(sys.modules[apps_path])[1]
40 plugin_module = f'recipes.plugins.{d}.apps.{app_config_classname}'
41 plugin_class = getattr(sys.modules[apps_path], app_config_classname)
43 print('getting plugin version for ', plugin_class.verbose_name if hasattr(plugin_class, 'verbose_name') else plugin_class.name)
44 r = subprocess.check_output(['git', 'show', '-s'], cwd=os.path.join(BASE_DIR, 'recipes', 'plugins', d)).decode()
45 branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=os.path.join(BASE_DIR, 'recipes', 'plugins', d)).decode()
46 commit_hash = r.split('\n')[0].split(' ')[1]
47 try:
48 print('running describe')
49 tag = subprocess.check_output(['git', 'describe', '--exact-match', commit_hash],
50 cwd=os.path.join(BASE_DIR, 'recipes', 'plugins', d)).decode().replace('\n', '')
51 except BaseException:
52 tag = ''
54 version_info.append({
55 'name': 'Plugin: ' + plugin_class.verbose_name if hasattr(plugin_class, 'verbose_name') else plugin_class.name,
56 'version': re.sub(r'<.*>', '', r),
57 'website': plugin_class.website if hasattr(plugin_class, 'website') else '',
58 'commit_link': plugin_class.github if hasattr(plugin_class, 'github') else '' + '/commit/' + commit_hash,
59 'ref': commit_hash,
60 'branch': branch,
61 'tag': tag
62 })
63 except subprocess.CalledProcessError as e:
64 print("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
65 except Exception:
66 traceback.print_exc()
67except subprocess.CalledProcessError as e:
68 print("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
69except BaseException:
70 traceback.print_exc()
72with open('cookbook/version_info.py', 'w+', encoding='UTF-8') as f:
73 print(f"writing version info {version_info}")
74 if not tandoor_tag:
75 tandoor_tag = tandoor_hash
76 f.write(f'TANDOOR_VERSION = "{tandoor_tag}"\nTANDOOR_REF = "{tandoor_hash}"\nVERSION_INFO = {version_info}')