set_version.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2023, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. import argparse
  12. import os
  13. try:
  14. from argcomplete import autocomplete
  15. except ImportError:
  16. def autocomplete(parser):
  17. return None
  18. def run():
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument(
  21. 'info_file',
  22. metavar='info-file',
  23. help="text file containing version info",
  24. )
  25. parser.add_argument(
  26. 'exe_file',
  27. metavar='exe-file',
  28. help="full pathname of a Windows executable",
  29. )
  30. autocomplete(parser)
  31. args = parser.parse_args()
  32. info_file = os.path.abspath(args.info_file)
  33. exe_file = os.path.abspath(args.exe_file)
  34. try:
  35. from PyInstaller.utils.win32 import versioninfo
  36. info = versioninfo.load_version_info_from_text_file(info_file)
  37. versioninfo.write_version_info_to_executable(exe_file, info)
  38. print(f"Version info written to: {exe_file!r}")
  39. except KeyboardInterrupt:
  40. raise SystemExit("Aborted by user request.")
  41. if __name__ == '__main__':
  42. run()