]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | # Allow direct execution | |
4 | import os | |
5 | import sys | |
6 | ||
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
9 | ||
10 | import argparse | |
11 | import contextlib | |
12 | import sys | |
13 | from datetime import datetime | |
14 | ||
15 | from devscripts.utils import read_version, run_process, write_file | |
16 | ||
17 | ||
18 | def get_new_version(version, revision): | |
19 | if not version: | |
20 | version = datetime.utcnow().strftime('%Y.%m.%d') | |
21 | ||
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) | |
28 | ||
29 | return f'{version}.{revision}' if revision else version | |
30 | ||
31 | ||
32 | def get_git_head(): | |
33 | with contextlib.suppress(Exception): | |
34 | return run_process('git', 'rev-parse', 'HEAD').stdout.strip() | |
35 | ||
36 | ||
37 | VERSION_TEMPLATE = '''\ | |
38 | # Autogenerated by devscripts/update-version.py | |
39 | ||
40 | __version__ = {version!r} | |
41 | ||
42 | RELEASE_GIT_HEAD = {git_head!r} | |
43 | ||
44 | VARIANT = None | |
45 | ||
46 | UPDATE_HINT = None | |
47 | ||
48 | CHANNEL = {channel!r} | |
49 | ''' | |
50 | ||
51 | if __name__ == '__main__': | |
52 | parser = argparse.ArgumentParser(description='Update the version.py file') | |
53 | parser.add_argument( | |
54 | '-c', '--channel', default='stable', | |
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}') |