mirror of
https://github.com/wassname/blender_ipython.git
synced 2026-08-20 12:10:33 +08:00
40 lines
866 B
Python
Executable File
40 lines
866 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import tempfile
|
|
|
|
__all__ = 'launch_kernel', 'main'
|
|
|
|
def launch_kernel(argv):
|
|
tempscript = tempfile.mktemp()+"_blender_ipython_kernel.py"
|
|
|
|
# generate kernel starter script
|
|
with open(tempscript,"w") as f:
|
|
f.write("""\
|
|
import sys
|
|
sys.argv[:] = [sys.executable]
|
|
from IPython.zmq.ipkernel import IPKernelApp
|
|
|
|
app = IPKernelApp.instance()
|
|
app.initialize(%r)
|
|
app.start()
|
|
""" % argv)
|
|
|
|
try:
|
|
print('starting: blender -b -P', tempscript)
|
|
sys.exit(subprocess.call(['blender', '-b', '-P', tempscript]))
|
|
finally:
|
|
os.remove(tempscript)
|
|
|
|
def main():
|
|
if sys.argv[1:3] != ['-c', 'from IPython.zmq.ipkernel import main; main()']:
|
|
# if it wasn't used to start a kernel really execute python
|
|
os.execlp('python3','python3',*sys.argv[1:])
|
|
else:
|
|
launch_kernel(sys.argv[1:])
|
|
|
|
if __name__ == '__main__':
|
|
main()
|