mirror of
https://github.com/wassname/blender_ipython.git
synced 2026-09-09 11:18:46 +08:00
more generic blender_ipython.py
This commit is contained in:
@@ -1,2 +1,5 @@
|
|||||||
.*
|
.*
|
||||||
*~
|
*~
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
|||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.argv[1:2] == ['kernel']:
|
||||||
|
from blender_ipython_kernel import launch_kernel
|
||||||
|
launch_kernel(sys.argv[1:])
|
||||||
|
else:
|
||||||
|
from os.path import abspath, dirname, join as pathjoin
|
||||||
|
from pkg_resources import load_entry_point
|
||||||
|
|
||||||
|
# use wrapper script for starting python processes
|
||||||
|
# the wrapper will defer execution to blender, if it was used to start a new kernel
|
||||||
|
sys.executable = pathjoin(dirname(abspath(__file__)), 'blender_ipython_wrapper.py')
|
||||||
|
|
||||||
|
sys.exit(load_entry_point('ipython', 'console_scripts', 'ipython3')())
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import distutils.spawn
|
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
blender = distutils.spawn.find_executable("blender")
|
|
||||||
tempscript = tempfile.mktemp()+"_blender_ipython.py"
|
|
||||||
|
|
||||||
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()
|
|
||||||
""" % sys.argv[1:])
|
|
||||||
|
|
||||||
try:
|
|
||||||
print("starting:", blender, '-b', '-P', tempscript)
|
|
||||||
sys.exit(subprocess.call([blender, '-b', '-P', tempscript]))
|
|
||||||
finally:
|
|
||||||
os.remove(tempscript)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from os.path import abspath, dirname, join as pathjoin
|
|
||||||
from IPython.frontend.html.notebook.notebookapp import launch_new_instance
|
|
||||||
|
|
||||||
sys.executable = pathjoin(dirname(abspath(__file__)), 'blender_ipython_kernel.py')
|
|
||||||
|
|
||||||
launch_new_instance()
|
|
||||||
Executable
+39
@@ -0,0 +1,39 @@
|
|||||||
|
#!/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()
|
||||||
Reference in New Issue
Block a user