implement file configs in main config

This commit is contained in:
Maximilian Keßler 2022-02-18 16:49:06 +01:00
parent d41ecb2398
commit 6db991acc7
4 changed files with 25 additions and 3 deletions

View file

@ -159,13 +159,20 @@ class PyTeXBuilder:
files = self.source_root.glob('*') files = self.source_root.glob('*')
for file in files: for file in files:
if self.is_supported_file(file.name): if self.is_supported_file(file.name):
config = self.pytex_config.sub_config(
file.name.split('.', 1)[0]
)
config.merge_with(
self.pytex_config.default_formatting_config,
strict=False
)
self._pytex_files.append( self._pytex_files.append(
PyTeXSourceFile( PyTeXSourceFile(
relative_path=RelativePath( relative_path=RelativePath(
self.source_root, self.source_root,
file file
), ),
default_config=self.pytex_config.default_formatting_config, default_config=config,
git_version_info=self._git_version_info, git_version_info=self._git_version_info,
target=self._build_target_type.to_target() target=self._build_target_type.to_target()
) )

View file

@ -96,3 +96,17 @@ class PyTeXConfig(Config):
return FormattingConfig() return FormattingConfig()
else: else:
return self._default_formatting_config return self._default_formatting_config
@property
def sub_configs(self) -> Dict:
if self._configs is None:
return {}
else:
return self._configs
def sub_config(self, name: str) -> FormattingConfig:
if name in self.sub_configs.keys():
return FormattingConfig.from_json(self.sub_configs[name])
else:
return FormattingConfig()

View file

@ -58,7 +58,8 @@ def clean_dict(dictionary: Dict) -> Optional[Dict]:
class Config: class Config:
def merge_with(self, other: Config, strict: bool = False): def merge_with(self, other: Config, strict: bool = False):
""" """
Merges the other config into this one Merges the other config into this one.
In conflicts, the called-on instance takes effect
:param other: :param other:
:param strict: whether conflicting options are allowed or not :param strict: whether conflicting options are allowed or not
:return: self :return: self

View file

@ -25,7 +25,7 @@ builder = PyTeXBuilder(conf_path)
builder.build_tex_sources() builder.build_tex_sources()
builder.build_tex_files() # builder.build_tex_files()
pass pass