1
0

__main__.py 4.3 KB

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