fix some type errors
This commit is contained in:
parent
91bcb64be5
commit
582d6670b8
4 changed files with 31 additions and 21 deletions
|
@ -14,38 +14,46 @@ class GitVersionInfo(Config):
|
||||||
self._pytex_version: Optional[RepoStatusInfo] = None
|
self._pytex_version: Optional[RepoStatusInfo] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Optional[Dict]):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
filled_content = self._fill_keys(content)
|
||||||
self._repo_version = RepoStatusInfo.from_json(
|
self._repo_version = RepoStatusInfo.from_json(
|
||||||
content[YAML_REPO]
|
filled_content[YAML_REPO]
|
||||||
)
|
)
|
||||||
self._pytex_version = RepoStatusInfo.from_json(
|
self._pytex_version = RepoStatusInfo.from_json(
|
||||||
content[YAML_PYTEX]
|
filled_content[YAML_PYTEX]
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_json(self) -> Dict:
|
def to_json(self) -> Dict:
|
||||||
return {
|
return {
|
||||||
YAML_PYTEX: self._pytex_version.to_json(),
|
YAML_PYTEX: self.pytex_version.to_json(),
|
||||||
YAML_REPO: self._repo_version.to_json()
|
YAML_REPO: self.repo_version.to_json()
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pytex_version(self) -> Optional[RepoStatusInfo]:
|
def pytex_version(self) -> RepoStatusInfo:
|
||||||
if self._pytex_version is None:
|
if self._pytex_version is None:
|
||||||
return None
|
return RepoStatusInfo()
|
||||||
else:
|
else:
|
||||||
return self._pytex_version
|
return self._pytex_version
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repo_version(self) -> Optional[RepoStatusInfo]:
|
def repo_version(self) -> RepoStatusInfo:
|
||||||
if self._repo_version is None:
|
if self._repo_version is None:
|
||||||
return None
|
return RepoStatusInfo()
|
||||||
else:
|
else:
|
||||||
return self._repo_version
|
return self._repo_version
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_pytex_version(self) -> bool:
|
||||||
|
return self._pytex_version is None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_repo_version(self) -> bool:
|
||||||
|
return self._repo_version is None
|
||||||
|
|
||||||
|
|
||||||
class FormattingConfig(Config):
|
class FormattingConfig(Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._naming_scheme: Optional[Union[NamingScheme, str]] = None
|
self._naming_scheme: Optional[NamingScheme] = None
|
||||||
self._license: Optional[GenericText] = None
|
self._license: Optional[GenericText] = None
|
||||||
self._description: Optional[str] = None
|
self._description: Optional[str] = None
|
||||||
|
|
||||||
|
@ -74,9 +82,9 @@ class FormattingConfig(Config):
|
||||||
self._tex_flavour: Optional[TeXFlavour] = None
|
self._tex_flavour: Optional[TeXFlavour] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Optional[Dict]):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
filled_content = self._fill_keys(content)
|
||||||
|
|
||||||
info = content[YAML_INFO]
|
info = filled_content[YAML_INFO]
|
||||||
self._author = info[YAML_AUTHOR]
|
self._author = info[YAML_AUTHOR]
|
||||||
self._naming_scheme = info[YAML_NAMING_SCHEME]
|
self._naming_scheme = info[YAML_NAMING_SCHEME]
|
||||||
self._tex_flavour = info[YAML_TEX_FLAVOUR]
|
self._tex_flavour = info[YAML_TEX_FLAVOUR]
|
||||||
|
@ -84,7 +92,7 @@ class FormattingConfig(Config):
|
||||||
self._description = info[YAML_DESCRIPTION]
|
self._description = info[YAML_DESCRIPTION]
|
||||||
self._version = info[YAML_VERSION]
|
self._version = info[YAML_VERSION]
|
||||||
|
|
||||||
header = content[YAML_HEADER]
|
header = filled_content[YAML_HEADER]
|
||||||
extra = header[YAML_EXTRA]
|
extra = header[YAML_EXTRA]
|
||||||
self._include_extra_header = extra[YAML_INCLUDE_EXTRA_HEADER]
|
self._include_extra_header = extra[YAML_INCLUDE_EXTRA_HEADER]
|
||||||
self._extra_header = GenericText(
|
self._extra_header = GenericText(
|
||||||
|
@ -113,7 +121,7 @@ class FormattingConfig(Config):
|
||||||
license_[YAML_PATH] if license_[YAML_PATH] else license_[YAML_TEXT]
|
license_[YAML_PATH] if license_[YAML_PATH] else license_[YAML_TEXT]
|
||||||
)
|
)
|
||||||
|
|
||||||
docstrip = content[YAML_DOCSTRIP]
|
docstrip = filled_content[YAML_DOCSTRIP]
|
||||||
self._include_drv = docstrip[YAML_INCLUDE_DRV]
|
self._include_drv = docstrip[YAML_INCLUDE_DRV]
|
||||||
self._include_ins = docstrip[YAML_INCLUDE_INS]
|
self._include_ins = docstrip[YAML_INCLUDE_INS]
|
||||||
self._docstrip_guards = docstrip[YAML_DOCSTRIP_GUARDS]
|
self._docstrip_guards = docstrip[YAML_DOCSTRIP_GUARDS]
|
||||||
|
|
|
@ -12,7 +12,7 @@ class GenericText:
|
||||||
self._path = None
|
self._path = None
|
||||||
self._initialized = True
|
self._initialized = True
|
||||||
elif isinstance(content, Path) or isinstance(content, str):
|
elif isinstance(content, Path) or isinstance(content, str):
|
||||||
self._content: Optional[List[str]] = None
|
self._content = None
|
||||||
self._path = Path(content)
|
self._path = Path(content)
|
||||||
self._initialized = True
|
self._initialized = True
|
||||||
else:
|
else:
|
||||||
|
@ -24,6 +24,8 @@ class GenericText:
|
||||||
def text(self) -> List[str]:
|
def text(self) -> List[str]:
|
||||||
if self._initialized:
|
if self._initialized:
|
||||||
if self._content is None:
|
if self._content is None:
|
||||||
|
if self._path is None:
|
||||||
|
raise NotImplementedError # Programming error
|
||||||
try:
|
try:
|
||||||
with open(self._path, 'r') as file:
|
with open(self._path, 'r') as file:
|
||||||
self._content = file.readlines()
|
self._content = file.readlines()
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Argument(MacroReplacementAtomIF, Enum):
|
||||||
six = 6
|
six = 6
|
||||||
|
|
||||||
|
|
||||||
class MacroReplacement(str):
|
class MacroReplacement:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
replacement: str,
|
replacement: str,
|
||||||
|
|
|
@ -13,11 +13,11 @@ class RepoStatusInfo(Config):
|
||||||
self._version: Optional[str] = None
|
self._version: Optional[str] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Optional[Dict]):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
filled_content: Dict = self._fill_keys(content)
|
||||||
self._branch = content[JSON_BRANCH]
|
self._branch = filled_content[JSON_BRANCH]
|
||||||
self._dirty = content[JSON_DIRTY]
|
self._dirty = filled_content[JSON_DIRTY]
|
||||||
self._commit_hash = content[JSON_COMMIT_HASH]
|
self._commit_hash = filled_content[JSON_COMMIT_HASH]
|
||||||
self._version = content[JSON_VERSION]
|
self._version = filled_content[JSON_VERSION]
|
||||||
|
|
||||||
def to_json(self) -> Dict:
|
def to_json(self) -> Dict:
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue