Skip to content

Commit

Permalink
feat: improve generated pyi style
Browse files Browse the repository at this point in the history
  • Loading branch information
JamzumSum committed Oct 20, 2022
1 parent dbf1d13 commit da81c6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "yacs-stubgen"
version = "0.2.1"
version = "0.2.2"
description = "Generate stub file for yacs config."
authors = ["JamzumSum <zzzzss990315@gmail.com>"]
license = "MIT"
Expand Down
18 changes: 17 additions & 1 deletion src/yacs_stubgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def _to_py_obj(cfg: CfgNode, cls_name: str):
return classes, d


class _BlackDumper(yaml.SafeDumper):
def write_line_break(self, data=None):
super().write_line_break(data)

if len(self.indents) == 1:
super().write_line_break()


def build_pyi(
cfg: CfgNode, path: Union[Path, str], cls_name="AutoConfig", var_name="cfg"
):
Expand All @@ -38,4 +46,12 @@ def build_pyi(
with open(path.with_suffix(".pyi"), "w") as f:
# f.write("from typing import *\n")
f.write("from yacs.config import CfgNode as CN\n\n")
yaml.safe_dump(d, f, sort_keys=False)
yaml.dump(
d,
f,
Dumper=_BlackDumper,
indent=4,
default_flow_style=False,
canonical=False,
sort_keys=False,
)

0 comments on commit da81c6c

Please sign in to comment.