From 3200929bde52d0806b9893a297d97d5dd43ba47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu> Date: Fri, 15 Dec 2017 16:47:50 +0100 Subject: [PATCH] Added support for passing Python scripts to Blender in task definitions. --- CHANGELOG.md | 1 + flamenco_worker/commands.py | 2 ++ tests/test_commands_blender_render.py | 40 +++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05601d6..7f4f4070 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 573c139f..9e60db05 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 719ca54a..d5a3e84b 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, + ) -- GitLab