]>
jfr.im git - yt-dlp.git/blob - devscripts/update-version.py
3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
14 from datetime
import datetime
16 from devscripts
.utils
import read_version
, write_file
19 def get_new_version(version
, revision
):
21 version
= datetime
.utcnow().strftime('%Y.%m.%d')
24 assert revision
.isdigit(), 'Revision must be a number'
26 old_version
= read_version().split('.')
27 if version
.split('.') == old_version
[:3]:
28 revision
= str(int((old_version
+ [0])[3]) + 1)
30 return f
'{version}.{revision}' if revision
else version
34 with contextlib
.suppress(Exception):
35 return subprocess
.check_output(['git', 'rev-parse', 'HEAD'], text
=True).strip() or None
38 VERSION_TEMPLATE
= '''\
39 # Autogenerated by devscripts/update-version.py
41 __version__ = {version!r}
43 RELEASE_GIT_HEAD = {git_head!r}
49 CHANNEL = "{channel!r}"
52 if __name__
== '__main__':
53 parser
= argparse
.ArgumentParser(description
='Update the version.py file')
55 '-c', '--channel', choices
=['stable', 'nightly'], default
='stable',
56 help='Select update channel (default: %(default)s)')
58 '-o', '--output', default
='yt_dlp/version.py',
59 help='The output file to write to (default: %(default)s)')
61 'version', nargs
='?', default
=None,
62 help='A version or revision to use instead of generating one')
63 args
= parser
.parse_args()
65 git_head
= get_git_head()
67 args
.version
if args
.version
and '.' in args
.version
68 else get_new_version(None, args
.version
))
69 write_file(args
.output
, VERSION_TEMPLATE
.format(
70 version
=version
, git_head
=git_head
, channel
=args
.channel
))
72 print(f
'version={version} ({args.channel}), head={git_head}')