Skip to content

Commit

Permalink
migrate gen_format_overview_classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jandom committed Aug 20, 2023
1 parent 60024f4 commit ba7b387
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions doc/source/scripts/gen_format_overview_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _write(fmt, handlers, key):
},
)
self.table_writer.get_lines_and_write_table()
self.table_writer.fields["keys"] = list(zip(*input_items))[2]


class CoordinateReaders:
Expand Down Expand Up @@ -135,25 +136,28 @@ def _forces(fmt, handlers, key):
self.table_writer.get_lines_and_write_table()


class SphinxClasses(TableWriter):
filename = "formats/reference/classes/{}.txt"

class SphinxClasses:
def __init__(self, fmt):
self.filename = self.filename.format(fmt)
self.fmt = fmt
super(SphinxClasses, self).__init__()
def _generate_lines():
lines = []
for label, klass in sorted(FILE_TYPES[fmt].items()):
lines.append(
[
"**{}**".format(label),
base.sphinx_class(klass=klass, tilde=False),
]
)
return lines

def get_lines(self):
lines = []
for label, klass in sorted(FILE_TYPES[self.fmt].items()):
lines.append(
["**{}**".format(label), self.sphinx_class(klass, tilde=False)]
)
self.lines = lines
self.table_writer = TableWriter(
filename="formats/reference/classes/{}.txt".format(fmt),
generate_lines=_generate_lines,
)
self.table_writer.get_lines_and_write_table()


if __name__ == "__main__":
ov = FormatOverview()
CoordinateReaders()
for key in set(ov.fields["keys"]):
for key in set(ov.table_writer.fields["keys"]):
SphinxClasses(key)
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def test_CoordinateReaders(snapshot):
def test_SphinxClasses(snapshot):
with patch("builtins.open"):
sc = SphinxClasses("PDB")
assert sc.lines == snapshot
assert sc.table_writer.lines == snapshot

0 comments on commit ba7b387

Please sign in to comment.