set-variant.py 949 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. # Allow direct execution
  3. import os
  4. import sys
  5. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  6. import argparse
  7. import functools
  8. import re
  9. from devscripts.utils import compose_functions, read_file, write_file
  10. VERSION_FILE = 'yt_dlp/version.py'
  11. def parse_options():
  12. parser = argparse.ArgumentParser(description='Set the build variant of the package')
  13. parser.add_argument('variant', help='Name of the variant')
  14. parser.add_argument('-M', '--update-message', default=None, help='Message to show in -U')
  15. return parser.parse_args()
  16. def property_setter(name, value):
  17. return functools.partial(re.sub, rf'(?m)^{name}\s*=\s*.+$', f'{name} = {value!r}')
  18. opts = parse_options()
  19. transform = compose_functions(
  20. property_setter('VARIANT', opts.variant),
  21. property_setter('UPDATE_HINT', opts.update_message),
  22. )
  23. write_file(VERSION_FILE, transform(read_file(VERSION_FILE)))