You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.py 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import argparse
  2. from importlib import util
  3. import logging
  4. import os
  5. import subprocess
  6. import sys
  7. spec = util.spec_from_file_location("_common", os.path.join(os.path.dirname(os.path.abspath(__file__)), "./_common.py"))
  8. c = util.module_from_spec(spec)
  9. spec.loader.exec_module(c)
  10. def add_arg_parser(parser):
  11. parser.add_argument('-d', '--debug', action='store_true',
  12. help='Set log level to Debug')
  13. def check_dependencies():
  14. # System & Dependencies Check
  15. c.log.debug("OS : {}".format(c.get_os()))
  16. c.log.debug("Python version : {}".format(c.get_python_version()))
  17. if c.get_os() == c.OS.UNKNOWN:
  18. c.log.fatal("Unknown OS !")
  19. sys.exit(1)
  20. if c.get_python_version() < (3, 5):
  21. c.log.fatal("Unsupported python version !")
  22. sys.exit(1)
  23. if not c.check_pyinstaller():
  24. c.log.fatal("Pyinstaller is not install. It's a required dependency !")
  25. sys.exit(1)
  26. def cli_build(args, dist_path="./dist"):
  27. def pyinstaller_args():
  28. pyinstaller_args = [
  29. '--workpath=./build/',
  30. '--specpath=.',
  31. '-y',
  32. '--onedir',
  33. '--name=dreampower',
  34. '--distpath={}'.format(dist_path),
  35. 'main.py',
  36. ]
  37. if c.get_os() == c.OS.LINUX:
  38. return pyinstaller_args
  39. if c.get_os() == c.OS.MAC:
  40. pyinstaller_args.extend(['--add-binary=/System/Library/Frameworks/Tk.framework/Tk:tk'])
  41. pyinstaller_args.extend(['--add-binary=/System/Library/Frameworks/Tcl.framework/Tcl:tcl'])
  42. return pyinstaller_args
  43. if c.get_os() == c.OS.WIN:
  44. pyinstaller_args.extend(['--add-binary=./third/msvcp/msvcp140.dll;.'])
  45. return pyinstaller_args
  46. c.log.info('Building Cli')
  47. with c.cd(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")):
  48. cmd = [sys.executable, '-m', 'PyInstaller'] + pyinstaller_args()
  49. c.log.debug(cmd)
  50. r = subprocess.run(cmd)
  51. if r.returncode != 0:
  52. c.log.fatal("Cli build failed")
  53. sys.exit(1)
  54. c.log.info('Cli successfully built')
  55. def run(args, dist_path="./dist"):
  56. cli_build(args, dist_path)
  57. c.log.info('Build completed!')
  58. c.log.info(
  59. 'It should have generated a folder called dist/, inside you will find '
  60. 'the final project files that you can share with everyone!')
  61. c.log.info('Enjoy and remember to respect the License!')
  62. if __name__ == '__main__':
  63. parser = argparse.ArgumentParser(description='cli builder')
  64. add_arg_parser(parser)
  65. args = parser.parse_args()
  66. check_dependencies()
  67. if args.debug:
  68. c.log.setLevel(logging.DEBUG)
  69. # Build Cli
  70. run(args)