dump useless stuff

This commit is contained in:
Maximilian Keßler 2022-02-06 15:11:45 +01:00
parent 12de6e43cb
commit 37353e8695
2 changed files with 79 additions and 1 deletions

View file

@ -0,0 +1,73 @@
from typing import Tuple, Union, List, Any, Optional
from PyTeX.format.enums import NamingScheme, TeXFlavour, TeXType, License
from PyTeX.format.generic_text import GenericText
from PyTeX.format.git_version_info import GitVersionInfo
def generate_properties(props):
props = [x if isinstance(x, Tuple) else (x, None) for x in props]
out = []
for [prop, default] in props:
out.append(
" @property\n"
" def {prop}(self) -> {type}:\n"
" if self._{prop} is None:\n"
" return {default}\n"
" else:\n"
" return self._{prop}\n".format(
prop=prop,
type=type(default).__name__,
default=str(default)
)
)
return '\n'.join(out)
if __name__ == "__main__":
out = generate_properties(
[
("naming_scheme", NamingScheme.prepend_author),
("license", []),
("include_extra_header", False),
("include_build_time", False),
("include_pytex_version", False),
("include_pytex_info_text", False),
("include_repo_version", False),
("include_repo_info_text", False),
("extra_header", []),
("author", "MISSING AUTHOR"),
("licenses", GenericText([])),
("version", "0.0.0"),
("extra_header_file", GenericText([])),
("pytex_version", "0.0.0"),
("extra_header_file", GenericText([])),
"pytex_version",
("pytex_info_text", GenericText([])),
"repo_version",
("repo_info_text", GenericText([])),
("include_drv", False),
("include_ins", False),
("use_docstrip_guards", [])
]
)
print(out)
def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]):
attributes = [
x if isinstance(x, Tuple) else (x, None) for x in attributes
]
def decorator(cls):
for [attribute, default_value] in attributes:
def get_attr(self, attribute=attribute, default_value=default_value):
if getattr(self, "_" + attribute) is not None:
return getattr(self, "_" + attribute)
else:
return default_value
prop = property(get_attr)
setattr(cls, attribute, prop)
return cls
return decorator

View file

@ -4,6 +4,8 @@ from PyTeX.build.build.build_dir_spec import BuildDirSpecification
from PyTeX.build.enums import * from PyTeX.build.enums import *
from PyTeX.build.paths import RelativePath from PyTeX.build.paths import RelativePath
from PyTeX.format.formatting_config import FormattingConfig
spec = BuildDirSpecification( spec = BuildDirSpecification(
source_root=Path('src'), source_root=Path('src'),
@ -33,5 +35,8 @@ p3 = p / p2
p4 = p.with_name('myname') p4 = p.with_name('myname')
print(p) print(p)
config: FormattingConfig = FormattingConfig()
config._naming_scheme = 'test'
n = config.naming_scheme