diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-21 02:39:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-21 02:39:29 +0300 |
commit | c30149991c9417106577e2d96112b16433910215 (patch) | |
tree | 9b686c141ddf2c9346ebe0beb3b3cfc3aaacf73f /source/creator | |
parent | 55a0e21a03e88e5489dd6f53a91b6f3a6f770d9a (diff) |
Experimental option to build blender as a python module, rather then blender embedding python.
CMake build option WITH_PYTHON_MODULE, will build ./bin/bpy.so
This allows 'bpy' to be imported from python or other applications/IDE's which embed python, eg:
python -c "import bpy ; bpy.ops.render.render(write_still=True)"
This runs in background mode and has similar restrictions to running a script:
blender --background --python test.py
TODO:
- install to site-packages with blender scripts
- add support for imp.reload()
Diffstat (limited to 'source/creator')
-rw-r--r-- | source/creator/CMakeLists.txt | 17 | ||||
-rw-r--r-- | source/creator/creator.c | 24 |
2 files changed, 36 insertions, 5 deletions
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 9e52f188195..f74dc655764 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -127,8 +127,21 @@ if(WITH_BUILDINFO) endif() # message(STATUS "Configuring blender") - -add_executable(blender ${EXETYPE} ${SRC}) +if(WITH_PYTHON_MODULE) + add_definitions(-DWITH_PYTHON_MODULE) + + # creates ./bin/bpy.so which can be imported as a python module. + add_library(blender SHARED ${SRC}) + set_target_properties( + blender + PROPERTIES + PREFIX "" + OUTPUT_NAME bpy + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ + ) +else() + add_executable(blender ${EXETYPE} ${SRC}) +endif() # Post build steps for bundling/packaging. diff --git a/source/creator/creator.c b/source/creator/creator.c index 8dd1ed86e3a..48157de91eb 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -154,6 +154,7 @@ static void fpe_handler(int UNUSED(sig)) } #endif +#ifdef WITH_PYTHON_MODULE /* handling ctrl-c event in console */ static void blender_esc(int sig) { @@ -170,6 +171,7 @@ static void blender_esc(int sig) count++; } } +#endif /* buildinfo can have quotes */ #ifdef BUILD_DATE @@ -1111,12 +1113,21 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) } -int main(int argc, char **argv) +#ifdef WITH_PYTHON_MODULE +/* allow python module to call main */ +#define main main_python +#endif + +int main(int argc, const char **argv) { SYS_SystemHandle syshandle; bContext *C= CTX_create(); bArgs *ba; +#ifdef WITH_PYTHON_MODULE +#undef main +#endif + #ifdef WITH_BINRELOC br_init( NULL ); #endif @@ -1192,10 +1203,13 @@ int main(int argc, char **argv) setuid(getuid()); /* end superuser */ #endif - +#ifdef WITH_PYTHON_MODULE + G.background= 1; /* python module mode ALWAYS runs in background mode (for now) */ +#else /* for all platforms, even windos has it! */ if(G.background) signal(SIGINT, blender_esc); /* ctrl c out bg render */ - +#endif + /* background render uses this font too */ BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size); @@ -1248,6 +1262,10 @@ int main(int argc, char **argv) BLI_argsFree(ba); +#ifdef WITH_PYTHON_MODULE + return 0; /* keep blender in background mode running */ +#endif + if(G.background) { /* actually incorrect, but works for now (ton) */ WM_exit(C); |