Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit b4e7a39

Browse files
committed
Add --git-version argument to create_snapshot
This replaces git revs in a snpashots git_tag entries, when they are detected by a heuristic, with "git" Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
1 parent b59ac6b commit b4e7a39

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

scripts/create_snapshot.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import subprocess
1818
from pathlib import Path
1919
import shutil
20+
import string
2021

2122

2223
def main():
@@ -29,6 +30,7 @@ def main():
2930
help='Temporary directory for creating the snapshot in (default: working-dir/tmp-for-snapshot)', default=None)
3031
parser.add_argument('--version', type=str,
3132
help='dependency version to override, format is: dependency1:version,dependency2:version2', default=None)
33+
parser.add_argument('--git-version', action='store_true', help='Use "git" as version when encountering a git hash')
3234

3335
args = parser.parse_args()
3436

@@ -71,24 +73,30 @@ def main():
7173
stderr=subprocess.PIPE, cwd=tmp_dir) as edm:
7274
for line in edm.stderr:
7375
print(line.decode('utf-8'), end='')
74-
if args.version:
75-
versions = args.version.split(',')
76-
in_snapshot = tmp_dir / 'snapshot.yaml'
77-
snapshot = None
78-
with open(in_snapshot, mode='r', encoding='utf-8') as snapshot_file:
79-
try:
80-
snapshot = yaml.safe_load(snapshot_file)
81-
except yaml.YAMLError as e:
82-
print(f'Error parsing yaml of {in_snapshot}: {e}')
83-
if snapshot:
76+
in_snapshot = tmp_dir / 'snapshot.yaml'
77+
snapshot = None
78+
with open(in_snapshot, mode='r', encoding='utf-8') as snapshot_file:
79+
try:
80+
snapshot = yaml.safe_load(snapshot_file)
81+
except yaml.YAMLError as e:
82+
print(f'Error parsing yaml of {in_snapshot}: {e}')
83+
if snapshot:
84+
# check if git_tag is a 40 character hex string and assume it is a git_rev
85+
if args.git_version:
86+
for dependency, entry in snapshot.items():
87+
if len(entry['git_tag']) == 40 and all(character in string.hexdigits for character in entry['git_tag']):
88+
snapshot[dependency]['git_tag'] = 'git'
89+
if args.version:
90+
versions = args.version.split(',')
8491
for dep_versions in versions:
8592
dependency, version = dep_versions.split(':')
8693
if dependency in snapshot:
8794
print(f'Overriding {dependency} version {snapshot[dependency]['git_tag']} to {version}')
8895
snapshot[dependency]['git_tag'] = version
89-
with open(in_snapshot, mode='w', encoding='utf-8') as snapshot_file:
90-
yaml.safe_dump(snapshot, snapshot_file, indent=2, sort_keys=False, width=120)
96+
with open(in_snapshot, mode='w', encoding='utf-8') as snapshot_file:
97+
yaml.safe_dump(snapshot, snapshot_file, indent=2, sort_keys=False, width=120)
9198
print('Done')
9299

100+
93101
if __name__ == '__main__':
94102
main()

0 commit comments

Comments
 (0)