Translate OPEN_EXR DNA image format enum to EXR for CLI

Blender's `--render-format` CLI parameter generally takes the same names
as the `bpy.context.scene.render.image_settings.file_format` DNA parameter,
except when it comes to OpenEXR.

See https://developer.blender.org/D4502 for a proposal to make this
consistent.
This commit is contained in:
2019-03-12 14:18:04 +01:00
parent b6b14a1422
commit 60efef9df4
2 changed files with 49 additions and 1 deletions

View File

@@ -805,6 +805,20 @@ class AbstractBlenderCommand(AbstractSubprocessCommand):
self._last_activity_time = 0.0
def _format_dna_to_cli(self, format_for_dna: str) -> str:
"""Converts the DNA image format enum to a CLI -F argument for Blender.
The DNA enum value is generally the same as what would be passed on the
command line, except the EXR formats.
"""
# See https://developer.blender.org/D4502
dna_to_cli = {
'OPEN_EXR': 'EXR',
'OPEN_EXR_MULTILAYER': 'MULTILAYER',
}
return dna_to_cli.get(format_for_dna, format_for_dna)
def validate(self, settings: Settings):
blender_cmd, err = self._setting(settings, 'blender_cmd', True)
if err:
@@ -979,7 +993,7 @@ class BlenderRenderCommand(AbstractBlenderCommand):
if settings.get('render_output'):
cmd.extend(['--render-output', settings['render_output']])
if settings.get('format'):
cmd.extend(['--render-format', settings['format']])
cmd.extend(['--render-format', self._format_dna_to_cli(settings['format'])])
if settings.get('frames'):
cmd.extend(['--render-frame', settings['frames']])
return cmd

View File

@@ -108,6 +108,40 @@ class BlenderRenderTest(AbstractCommandTest):
stderr=subprocess.STDOUT,
)
def test_cli_openexr(self):
from tests.mock_responses import CoroMock
filepath = Path(__file__).parent.as_posix()
settings = {
# Point blender_cmd to this file so that we're sure it exists.
'blender_cmd': f'{self.thisfile!r} --with --cli="args for CLI"',
'chunk_size': 100,
'frames': '1..2',
'format': 'OPEN_EXR',
'filepath': filepath,
}
cse = CoroMock(...)
cse.coro.return_value.wait = CoroMock(return_value=0)
cse.coro.return_value.pid = 47
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(
self.thisfile,
'--with',
'--cli=args for CLI',
'--enable-autoexec',
'-noaudio',
'--background',
filepath,
'--render-format', 'EXR', # see https://developer.blender.org/D4502
'--render-frame', '1..2',
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
def test_python_expr(self):
from tests.mock_responses import CoroMock