__main__.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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('-n', '--name',
  51. help='application name')
  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('--python-tag',
  55. help='python compatibility tag (e.g. cp37-cp37m)')
  56. build_app_parser.add_argument('-p', '--python-version',
  57. help='python version (e.g. 3.8)')
  58. which_parser = subparsers.add_parser('which',
  59. description='Locate a binary dependency')
  60. which_parser.add_argument('binary', choices=binaries,
  61. help='name of the binary to locate')
  62. args = parser.parse_args()
  63. # Configure the verbosity
  64. if args.verbosity:
  65. logging.getLogger().setLevel(args.verbosity)
  66. # Call the requested command
  67. module = '.commands.' + args.command
  68. if args.sub_command:
  69. module += '.' + args.sub_command
  70. command = import_module(module, package=__package__)
  71. command.execute(*command._unpack_args(args))
  72. if __name__ == "__main__":
  73. main()