fix some type errors

This commit is contained in:
Maximilian Keßler 2022-02-08 17:40:08 +01:00
parent 6cd8d9655d
commit a0dbb3882e
6 changed files with 36 additions and 31 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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
]
}

View file

@ -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]