2021-06-03 05:43:42 -04:00
|
|
|
#!/usr/bin/env python3
|
2022-06-24 07:06:16 -04:00
|
|
|
|
|
|
|
# Allow direct execution
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
import argparse
|
2022-08-08 15:38:47 -04:00
|
|
|
import contextlib
|
2022-04-11 18:32:57 -04:00
|
|
|
import sys
|
2023-09-17 06:56:50 -04:00
|
|
|
from datetime import datetime, timezone
|
2020-09-22 21:16:06 -04:00
|
|
|
|
2023-03-04 12:10:08 -05:00
|
|
|
from devscripts.utils import read_version, run_process, write_file
|
2020-09-22 21:16:06 -04:00
|
|
|
|
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
def get_new_version(version, revision):
|
|
|
|
if not version:
|
2023-09-17 06:56:50 -04:00
|
|
|
version = datetime.now(timezone.utc).strftime('%Y.%m.%d')
|
2020-09-22 21:16:06 -04:00
|
|
|
|
2022-08-08 15:38:47 -04:00
|
|
|
if revision:
|
|
|
|
assert revision.isdigit(), 'Revision must be a number'
|
|
|
|
else:
|
|
|
|
old_version = read_version().split('.')
|
|
|
|
if version.split('.') == old_version[:3]:
|
|
|
|
revision = str(int((old_version + [0])[3]) + 1)
|
2021-11-29 12:05:23 -05:00
|
|
|
|
2022-08-08 15:38:47 -04:00
|
|
|
return f'{version}.{revision}' if revision else version
|
2020-09-22 21:16:06 -04:00
|
|
|
|
|
|
|
|
2022-08-08 15:38:47 -04:00
|
|
|
def get_git_head():
|
|
|
|
with contextlib.suppress(Exception):
|
2023-03-04 12:10:08 -05:00
|
|
|
return run_process('git', 'rev-parse', 'HEAD').stdout.strip()
|
2022-08-08 15:38:47 -04:00
|
|
|
|
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
VERSION_TEMPLATE = '''\
|
2021-11-29 12:00:02 -05:00
|
|
|
# Autogenerated by devscripts/update-version.py
|
2020-09-22 21:16:06 -04:00
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
__version__ = {version!r}
|
2021-01-24 15:47:37 -05:00
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
RELEASE_GIT_HEAD = {git_head!r}
|
2022-07-29 11:03:01 -04:00
|
|
|
|
|
|
|
VARIANT = None
|
|
|
|
|
|
|
|
UPDATE_HINT = None
|
2023-03-03 12:03:12 -05:00
|
|
|
|
2023-03-03 14:54:22 -05:00
|
|
|
CHANNEL = {channel!r}
|
2021-12-22 20:42:26 -05:00
|
|
|
'''
|
2021-11-29 12:00:02 -05:00
|
|
|
|
2023-03-03 12:03:12 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Update the version.py file')
|
|
|
|
parser.add_argument(
|
2023-05-20 12:08:50 -04:00
|
|
|
'-c', '--channel', default='stable',
|
2023-03-03 12:03:12 -05:00
|
|
|
help='Select update channel (default: %(default)s)')
|
|
|
|
parser.add_argument(
|
|
|
|
'-o', '--output', default='yt_dlp/version.py',
|
|
|
|
help='The output file to write to (default: %(default)s)')
|
|
|
|
parser.add_argument(
|
|
|
|
'version', nargs='?', default=None,
|
|
|
|
help='A version or revision to use instead of generating one')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
git_head = get_git_head()
|
|
|
|
version = (
|
|
|
|
args.version if args.version and '.' in args.version
|
|
|
|
else get_new_version(None, args.version))
|
|
|
|
write_file(args.output, VERSION_TEMPLATE.format(
|
|
|
|
version=version, git_head=git_head, channel=args.channel))
|
|
|
|
|
|
|
|
print(f'version={version} ({args.channel}), head={git_head}')
|