in setup.py [0:0]
def run(self) -> None:
from hpc.autoscale.node import constraints
from hpc.autoscale.node.constraints import NodeConstraint # noqa: N812
with open("README.md", "w") as fw:
with open("README.md.in") as fr:
print(fr.read(), file=fw)
print("# Node Properties", file=fw)
print(file=fw)
from hpc.autoscale.node import node as nodelib
print("| Property | Type | Description |", file=fw)
print("| :--- | :--- | :--- |", file=fw)
for prop_name in sorted(nodelib.QUERYABLE_PROPERTIES):
prop = getattr(nodelib.Node, prop_name)
sig = inspect.signature(prop.fget)
ra = sig.return_annotation
return_type: str
if hasattr(ra, "__name__"):
return_type = ra.__name__
elif hasattr(ra, "_name"):
optional = False
inner_types = [x.__name__ for x in ra.__args__]
if "NoneType" in inner_types:
optional = True
inner_types = [x for x in inner_types if x != "NoneType"]
return_type = "\\|".join(inner_types)
if optional:
return_type = "Optional[{}]".format(return_type)
else:
return_type = str(ra)
print(
"| node.{} | {} | {} |".format(
prop_name, return_type, prop.__doc__
),
file=fw,
)
print(file=fw)
print(file=fw)
print("# Constraints", file=fw)
print(file=fw)
for attr in dir(constraints):
if not attr[0].isupper():
continue
value = getattr(constraints, attr)
if not isinstance(value, type):
continue
if inspect.isabstract(value):
continue
if not issubclass(value, NodeConstraint):
continue
if not value.__doc__:
continue
print(file=fw)
print(file=fw)
print("##", value.__name__, file=fw)
print(file=fw)
for line in (value.__doc__ or "").splitlines(keepends=False):
if len(line) > 4 and line[:4] == " ":
line = line[4:]
print(line, file=fw)
print(file=fw)
print("# Contributing", file=fw)
print(file=fw)
print(