]>
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__
))))
13 from datetime
import datetime
15 from devscripts
.utils
import read_version
, run_process
, write_file
18 def get_new_version(version
, revision
):
20 version
= datetime
.utcnow().strftime('%Y.%m.%d')
23 assert revision
.isdigit(), 'Revision must be a number'
25 old_version
= read_version().split('.')
26 if version
.split('.') == old_version
[:3]:
27 revision
= str(int((old_version
+ [0])[3]) + 1)
29 return f
'{version}.{revision}' if revision
else version
33 with contextlib
.suppress(Exception):
34 return run_process('git', 'rev-parse', 'HEAD').stdout
.strip()
37 VERSION_TEMPLATE
= '''\
38 # Autogenerated by devscripts/update-version.py
40 __version__ = {version!r}
42 RELEASE_GIT_HEAD = {git_head!r}
51 if __name__
== '__main__':
52 parser
= argparse
.ArgumentParser(description
='Update the version.py file')
54 '-c', '--channel', choices
=['stable', 'nightly'], default
='stable',
55 help='Select update channel (default: %(default)s)')
57 '-o', '--output', default
='yt_dlp/version.py',
58 help='The output file to write to (default: %(default)s)')
60 'version', nargs
='?', default
=None,
61 help='A version or revision to use instead of generating one')
62 args
= parser
.parse_args()
64 git_head
= get_git_head()
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
))
71 print(f
'version={version} ({args.channel}), head={git_head}')