]> jfr.im git - yt-dlp.git/blame - devscripts/update-version.py
[ie/RTVSLO] Fix format extraction (#8131)
[yt-dlp.git] / devscripts / update-version.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
54007a45 2
3# Allow direct execution
4import os
5import sys
6
7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9
29cb20bd 10import argparse
115add43 11import contextlib
f8271158 12import sys
13from datetime import datetime
915f2a92 14
392389b7 15from devscripts.utils import read_version, run_process, write_file
915f2a92 16
915f2a92 17
29cb20bd
SS
18def get_new_version(version, revision):
19 if not version:
20 version = datetime.utcnow().strftime('%Y.%m.%d')
915f2a92 21
115add43 22 if revision:
23 assert revision.isdigit(), 'Revision must be a number'
24 else:
25 old_version = read_version().split('.')
26 if version.split('.') == old_version[:3]:
27 revision = str(int((old_version + [0])[3]) + 1)
75b725a7 28
115add43 29 return f'{version}.{revision}' if revision else version
915f2a92 30
915f2a92 31
115add43 32def get_git_head():
33 with contextlib.suppress(Exception):
392389b7 34 return run_process('git', 'rev-parse', 'HEAD').stdout.strip()
115add43 35
36
29cb20bd 37VERSION_TEMPLATE = '''\
36eaf303 38# Autogenerated by devscripts/update-version.py
915f2a92 39
29cb20bd 40__version__ = {version!r}
5b328c97 41
29cb20bd 42RELEASE_GIT_HEAD = {git_head!r}
70b23409 43
44VARIANT = None
45
46UPDATE_HINT = None
29cb20bd 47
bfc861a9 48CHANNEL = {channel!r}
b69fd25c 49'''
36eaf303 50
29cb20bd
SS
51if __name__ == '__main__':
52 parser = argparse.ArgumentParser(description='Update the version.py file')
53 parser.add_argument(
c4efa0ae 54 '-c', '--channel', default='stable',
29cb20bd
SS
55 help='Select update channel (default: %(default)s)')
56 parser.add_argument(
57 '-o', '--output', default='yt_dlp/version.py',
58 help='The output file to write to (default: %(default)s)')
59 parser.add_argument(
60 'version', nargs='?', default=None,
61 help='A version or revision to use instead of generating one')
62 args = parser.parse_args()
63
64 git_head = get_git_head()
65 version = (
66 args.version if args.version and '.' in args.version
67 else get_new_version(None, args.version))
68 write_file(args.output, VERSION_TEMPLATE.format(
69 version=version, git_head=git_head, channel=args.channel))
70
71 print(f'version={version} ({args.channel}), head={git_head}')