__main__.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import argparse
  2. from importlib import import_module
  3. import logging
  4. import os
  5. import sys
  6. __all__ = ['main']
  7. def main():
  8. '''Entry point for the CLI
  9. '''
  10. # Binary dependencies
  11. binaries = ('appimagetool', 'patchelf')
  12. # Parse arguments
  13. parser = argparse.ArgumentParser(
  14. prog='python-appimage',
  15. description='Bundle a Python installation into an AppImage')
  16. subparsers = parser.add_subparsers(title='command',
  17. help='Command to execute',
  18. dest='command')
  19. parser.add_argument('-q', '--quiet', help='disable logging',
  20. dest='verbosity', action='store_const', const=logging.ERROR)
  21. parser.add_argument('-v', '--verbose', help='print extra information',
  22. dest='verbosity', action='store_const', const=logging.DEBUG)
  23. install_parser = subparsers.add_parser('install',
  24. description='Install binary dependencies')
  25. install_parser.add_argument('binary', nargs='+',
  26. choices=binaries, help='one or more binary name')
  27. build_parser = subparsers.add_parser('build',
  28. description='Build a Python appimage')
  29. build_subparsers = build_parser.add_subparsers(
  30. title='type',
  31. help='Type of AppImage build',
  32. dest='sub_command')
  33. build_local_parser = build_subparsers.add_parser('local',
  34. description='Bundle a local Python installation')
  35. build_local_parser.add_argument('-d', '--destination',
  36. help='AppImage destination')
  37. build_local_parser.add_argument('-p', '--python', help='python executable')
  38. build_manylinux_parser = build_subparsers.add_parser('manylinux',
  39. description='Bundle a manylinux Python installation using docker')
  40. build_manylinux_parser.add_argument('tag',
  41. help='manylinux image tag (e.g. 2010_x86_64)')
  42. build_manylinux_parser.add_argument('abi',
  43. help='python ABI (e.g. cp37-cp37m)')
  44. build_manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
  45. action='store_true', default=False)
  46. build_app_parser = build_subparsers.add_parser('app',
  47. description='Build a Python application using a base AppImage')
  48. build_app_parser.add_argument('appdir',
  49. help='path to the application metadata')
  50. build_app_parser.add_argument('-b', '--base-image',
  51. help='path to a base image on disk')
  52. build_app_parser.add_argument('-l', '--linux-tag',
  53. help='linux compatibility tag (e.g. manylinux1_x86_64)')
  54. build_app_parser.add_argument('-n', '--name',
  55. help='application name')
  56. build_app_parser.add_argument('--python-tag',
  57. help='python compatibility tag (e.g. cp37-cp37m)')
  58. build_app_parser.add_argument('-p', '--python-version',
  59. help='python version (e.g. 3.8)')
  60. which_parser = subparsers.add_parser('which',
  61. description='Locate a binary dependency')
  62. which_parser.add_argument('binary', choices=binaries,
  63. help='name of the binary to locate')
  64. args = parser.parse_args()
  65. # Configure the verbosity
  66. if args.verbosity:
  67. logging.getLogger().setLevel(args.verbosity)
  68. # check if no arguments are passed
  69. if args.command is None:
  70. parser.print_help()
  71. return
  72. # Call the requested command
  73. module = '.commands.' + args.command
  74. if args.sub_command:
  75. module += '.' + args.sub_command
  76. command = import_module(module, package=__package__)
  77. command.execute(*command._unpack_args(args))
  78. if __name__ == "__main__":
  79. main()