diff --git a/CHANGELOG.md b/CHANGELOG.md index f05601d66ff697d346876e96eb5d8da0cafaf89c..7f4f40703d04bb6eb54c3b9915d5601cd2396049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ changed functionality, fixed bugs). - Added `--single` or `-1` CLI option to shut down the Worker after executing a single task. - Added `--test` or `-t` CLI option to start in testing mode. See Flamenco documentation for more details. Requires Flamenco Manager 2.1.0+. +- Added support for passing Python scripts to Blender in task definitions. ## Version 2.0.8 (released 2017-09-07) diff --git a/flamenco_worker/commands.py b/flamenco_worker/commands.py index 573c139f04e7081719152e993ad33f99e19d5664..9e60db05f3abb3b77e64a2ffc9dcb7430bd6bd22 100644 --- a/flamenco_worker/commands.py +++ b/flamenco_worker/commands.py @@ -565,6 +565,8 @@ class BlenderRenderCommand(AbstractSubprocessCommand): '--background', settings['filepath'], ] + if settings.get('python_expr'): + cmd.extend(['--python-expr', settings['python_expr']]) if settings.get('render_output'): cmd.extend(['--render-output', settings['render_output']]) if settings.get('format'): diff --git a/tests/test_commands_blender_render.py b/tests/test_commands_blender_render.py index 719ca54a3092fcef410adca195b2df6720f8c532..d5a3e84b8694145eff29924915cf2efc8389581e 100644 --- a/tests/test_commands_blender_render.py +++ b/tests/test_commands_blender_render.py @@ -1,3 +1,6 @@ +from pathlib import Path +import subprocess + from unittest.mock import patch, call from test_runner import AbstractCommandTest @@ -67,8 +70,6 @@ class BlenderRenderTest(AbstractCommandTest): def test_cli_args(self): """Test that CLI arguments in the blender_cmd setting are handled properly.""" - from pathlib import Path - import subprocess from mock_responses import CoroMock filepath = str(Path(__file__).parent) @@ -100,3 +101,38 @@ class BlenderRenderTest(AbstractCommandTest): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) + + def test_python_expr(self): + from mock_responses import CoroMock + + filepath = str(Path(__file__).parent) + settings = { + # Point blender_cmd to this file so that we're sure it exists. + 'blender_cmd': '%s --with --cli="args for CLI"' % __file__, + 'python_expr': 'print("yay in \'quotes\'")', + 'chunk_size': 100, + 'frames': '1..2', + 'format': 'JPEG', + 'filepath': filepath, + } + + cse = CoroMock(...) + cse.coro.return_value.wait = CoroMock(return_value=0) + with patch('asyncio.create_subprocess_exec', new=cse) as mock_cse: + self.loop.run_until_complete(self.cmd.run(settings)) + + mock_cse.assert_called_once_with( + __file__, + '--with', + '--cli=args for CLI', + '--enable-autoexec', + '-noaudio', + '--background', + filepath, + '--python-expr', 'print("yay in \'quotes\'")', + '--render-format', 'JPEG', + '--render-frame', '1..2', + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + )