mypyc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!C:\Users\admin\source\repos\Snips_SmallTalk2\Snips_SmallTalk2\env\Scripts\python.exe
  2. """Mypyc command-line tool.
  3. Usage:
  4. $ mypyc foo.py [...]
  5. $ python3 -c 'import foo' # Uses compiled 'foo'
  6. This is just a thin wrapper that generates a setup.py file that uses
  7. mypycify, suitable for prototyping and testing.
  8. """
  9. import os
  10. import os.path
  11. import subprocess
  12. import sys
  13. import tempfile
  14. import time
  15. base_path = os.path.join(os.path.dirname(__file__), '..')
  16. setup_format = """\
  17. from distutils.core import setup
  18. from mypyc.build import mypycify
  19. setup(name='mypyc_output',
  20. ext_modules=mypycify([], {}, {}),
  21. )
  22. """
  23. def main() -> None:
  24. build_dir = 'build' # can this be overridden??
  25. try:
  26. os.mkdir(build_dir)
  27. except FileExistsError:
  28. pass
  29. opt_level = os.getenv("MYPYC_OPT_LEVEL", '')
  30. setup_file = os.path.join(build_dir, 'setup.py')
  31. with open(setup_file, 'w') as f:
  32. f.write(setup_format.format(sys.argv[1:], opt_level))
  33. # We don't use run_setup (like we do in the test suite) because it throws
  34. # away the error code from distutils, and we don't care about the slight
  35. # performance loss here.
  36. env = os.environ.copy()
  37. base_path = os.path.join(os.path.dirname(__file__), '..')
  38. env['PYTHONPATH'] = base_path + os.pathsep + env.get('PYTHONPATH', '')
  39. cmd = subprocess.run([sys.executable, setup_file, 'build_ext', '--inplace'], env=env)
  40. sys.exit(cmd.returncode)
  41. if __name__ == '__main__':
  42. main()