From a0dbb3882e9565f41cf497fdbb1fdcc4e9dda977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 8 Feb 2022 17:40:08 +0100 Subject: [PATCH] fix some type errors --- PyTeX/build/build/build_dir_spec.py | 12 +++++------ PyTeX/build/build/builder.py | 4 ++-- PyTeX/build/build/pytex_config.py | 8 +++---- PyTeX/build/build/pytex_file.py | 21 ++++++++++++------- .../versioning/version_info/version_info.py | 20 +++++++++--------- PyTeX/format/simple_tex_formatter.py | 2 +- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/PyTeX/build/build/build_dir_spec.py b/PyTeX/build/build/build_dir_spec.py index d1986b4..2a4605f 100644 --- a/PyTeX/build/build/build_dir_spec.py +++ b/PyTeX/build/build/build_dir_spec.py @@ -21,13 +21,13 @@ class BuildDirConfig(Config): self._wrapper_dir: Optional[PurePath] = wrapper_dir def set_from_json(self, content: Optional[Dict]): - content = self._fill_keys(content) + filled_content = self._fill_keys(content) - self._tex_source_root = Path(content[YAML_TEX_SOURCE_ROOT]) - self._pytex_source_root = Path(content[YAML_PYTEX_SOURCE_ROOT]) - self._build_root = Path(content[YAML_BUILD_ROOT]) - self._doc_root = Path(content[YAML_DOC_ROOT]) - self._wrapper_dir = Path(content[YAML_WRAPPER_DIR]) + self._tex_source_root = Path(filled_content[YAML_TEX_SOURCE_ROOT]) + self._pytex_source_root = Path(filled_content[YAML_PYTEX_SOURCE_ROOT]) + self._build_root = Path(filled_content[YAML_BUILD_ROOT]) + self._doc_root = Path(filled_content[YAML_DOC_ROOT]) + self._wrapper_dir = Path(filled_content[YAML_WRAPPER_DIR]) def to_json(self) -> Dict: return { diff --git a/PyTeX/build/build/builder.py b/PyTeX/build/build/builder.py index 28c735b..a56e40b 100644 --- a/PyTeX/build/build/builder.py +++ b/PyTeX/build/build/builder.py @@ -22,8 +22,8 @@ class PyTeXBuilder: self._pytex_config = PyTeXConfig.from_yaml(config_file) self._root_dir: Optional[Path] = config_file.parent else: - self._pytex_config: Optional[PyTeXConfig] = pytex_config - self._root_dir: Optional[Path] = root_dir + self._pytex_config = pytex_config + self._root_dir = root_dir # Non-public attributes self._version_info: Optional[FileVersionInfo] = None diff --git a/PyTeX/build/build/pytex_config.py b/PyTeX/build/build/pytex_config.py index 6d5df0f..45f4a77 100644 --- a/PyTeX/build/build/pytex_config.py +++ b/PyTeX/build/build/pytex_config.py @@ -39,9 +39,9 @@ class PyTeXConfig(Config): } def set_from_json(self, content: Optional[Dict]): - content = self._fill_keys(content) + filled_content = self._fill_keys(content) - build = content[YAML_BUILD] + build = filled_content[YAML_BUILD] self._build_dir_specification = BuildDirConfig.from_json(build[YAML_DIRS]) self._recursive = build[YAML_RECURSIVE] self._clean_old_files = build[YAML_CLEAN_OLD_FILES] @@ -50,10 +50,10 @@ class PyTeXConfig(Config): self._force_mode = build[YAML_FORCE_MODE] self._default_formatting_config = FormattingConfig.from_json( - content[YAML_DEFAULT] + filled_content[YAML_DEFAULT] ) - self._configs = content[YAML_CONFIGS] + self._configs = filled_content[YAML_CONFIGS] @property def build_dir_specification(self): diff --git a/PyTeX/build/build/pytex_file.py b/PyTeX/build/build/pytex_file.py index 5474c0c..340f193 100644 --- a/PyTeX/build/build/pytex_file.py +++ b/PyTeX/build/build/pytex_file.py @@ -5,6 +5,7 @@ from .relative_path import RelativePath from PyTeX.format.formatterif import FormatterIF from PyTeX.build.build.enums import PyTeXFileType from .hashing import md5 +from ...format.formatting_config import FormattingConfig class PyTeXSourceFile: @@ -35,35 +36,39 @@ class PyTeXSourceFile: return self._relative_path @property - def pytex_file_type(self) -> PyTeXFileType: + def pytex_file_type(self) -> Optional[PyTeXFileType]: return self._pytex_file_type @property def output_files(self) -> List[RelativePath]: - files = self.formatter.output_files - files = [ + if self._formatter is None: + raise NotImplementedError # TODO + files: List[str] = self._formatter.output_files + paths = [ self._relative_path.with_name(filename) for filename in files ] - return files + return paths @property - def formatter(self) -> FormatterIF: + def formatter(self) -> Optional[FormatterIF]: return self._formatter @formatter.setter def formatter(self, formatter): self._formatter = formatter - def format(self, target_root: Union[Path, RelativePath]) -> Optional[List[Tuple[RelativePath, Dict]]]: + def format(self, target_root: Union[Path, RelativePath]) -> List[Tuple[RelativePath, FormattingConfig]]: + if self._formatter is None: + raise NotImplementedError # TODO try: configs = self._formatter.format( target_root.path if isinstance(target_root, RelativePath) else target_root ) except Exception as e: raise NotImplementedError - configs = [ + rel_configs = [ (self._relative_path.with_name(filename), config) for [filename, config] in configs ] - return configs + return rel_configs diff --git a/PyTeX/build/versioning/version_info/version_info.py b/PyTeX/build/versioning/version_info/version_info.py index 396e704..bb974a7 100644 --- a/PyTeX/build/versioning/version_info/version_info.py +++ b/PyTeX/build/versioning/version_info/version_info.py @@ -17,13 +17,13 @@ class FileVersionInfo(Config): self._build_time: Optional[str] = None def set_from_json(self, content: Optional[Dict]): - content = self._fill_keys(content) - self._relative_name = content[JSON_RELATIVE_NAME] - self._file_hash = content[JSON_FILE_HASH] - self._sources_hash = content[JSON_SOURCES_HASH] - self._build_time = content[JSON_BUILD_TIME] + filled_content = self._fill_keys(content) + self._relative_name = filled_content[JSON_RELATIVE_NAME] + self._file_hash = filled_content[JSON_FILE_HASH] + self._sources_hash = filled_content[JSON_SOURCES_HASH] + self._build_time = filled_content[JSON_BUILD_TIME] self._repo_status_info = RepoStatusInfo.from_json( - content[JSON_REPO_STATUS_INFO] + filled_content[JSON_REPO_STATUS_INFO] ) def to_json(self) -> Dict: @@ -32,7 +32,7 @@ class FileVersionInfo(Config): JSON_FILE_HASH: self._file_hash, JSON_SOURCES_HASH: self._sources_hash, JSON_BUILD_TIME: self._build_time, - JSON_REPO_STATUS_INFO: self._repo_status_info.to_json() + JSON_REPO_STATUS_INFO: self.repo_status_info.to_json() } @property @@ -97,18 +97,18 @@ class VersionInfo(Config): self._file_versions: Optional[List[FileVersionInfo]] = None def set_from_json(self, content: Optional[Dict]): - content = self._fill_keys(content) + filled_content: Dict = self._fill_keys(content) self._pytex_dir_type = None # TODO self._file_versions = [ FileVersionInfo.from_json(entry) - for entry in content[JSON_FILE_VERSIONS] + for entry in filled_content[JSON_FILE_VERSIONS] ] def to_json(self) -> Dict: return { JSON_FILE_VERSIONS: [ file_version_info.to_json() - for file_version_info in self._file_versions + for file_version_info in self.file_versions ] } diff --git a/PyTeX/format/simple_tex_formatter.py b/PyTeX/format/simple_tex_formatter.py index 4717e22..7334084 100644 --- a/PyTeX/format/simple_tex_formatter.py +++ b/PyTeX/format/simple_tex_formatter.py @@ -19,7 +19,7 @@ class SimpleTeXFormatter(TexFormatter): return [] # TODO def dependencies(self) -> List[str]: - return [] # TODO + return [] # sty / cls file does not depend on anything def output_files(self) -> List[str]: return [self.input_file.with_suffix('').name]