From 3a6832c4e5eda1ea8cd959fff5b60cc1027a2b7f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Sun, 27 Sep 2020 22:25:05 +0100 Subject: [PATCH] More robust fix for #15 --- src/ttblit/tool/packer.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ttblit/tool/packer.py b/src/ttblit/tool/packer.py index 9b201da..4e47052 100644 --- a/src/ttblit/tool/packer.py +++ b/src/ttblit/tool/packer.py @@ -3,6 +3,7 @@ import yaml from ..core.outputformat import CHeader, CSource, RawBinary +from ..core.palette import Palette from ..core.tool import Tool @@ -108,12 +109,8 @@ def run(self, args): elif file_options is None: file_options = {} - if 'palette' in file_options: - if not pathlib.Path(file_options['palette']).is_absolute(): - file_options['palette'] = self.working_path / file_options['palette'] - asset_sources.append( - AssetSource(input_files, builders=self.asset_builders, file_options=file_options) + AssetSource(input_files, builders=self.asset_builders, file_options=file_options, working_path=self.working_path) ) self.assets.append(AssetTarget( @@ -132,9 +129,10 @@ def run(self, args): class AssetSource(): supported_options = ('name', 'type') - def __init__(self, input_files, builders, file_options): + def __init__(self, input_files, builders, file_options, working_path): self.input_files = input_files self.asset_builders = builders + self.working_path = working_path self.builder_options = {} self.type = None self.name = None @@ -166,6 +164,21 @@ def build(self, format, prefix=None, output_file=None): builder, input_type = self.type.split('/') builder = self.asset_builders[builder] + # Now we know our target builder, one last iteration through the options + # allows some pre-processing stages to remap paths or other idiosyncrasies + # of the yml config format. + for option_name, option_value in builder.options.items(): + if option_name in self.builder_options: + option_type = builder.options[option_name] + if type(option_type) is tuple: + option_type, default_value = option_type + + # Ensure Palette and pathlib.Path type options for this asset builder + # are prefixed with the working directory if they are not absolute paths + if option_type in (Palette, pathlib.Path): + if not pathlib.Path(self.builder_options[option_name]).is_absolute(): + self.builder_options[option_name] = self.working_path / self.builder_options[option_name] + output = [] for file in self.input_files: