-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from desihub/render-columns
Render standard column definitions in ReadTheDocs
- Loading branch information
Showing
26 changed files
with
266 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ MANIFEST | |
|
||
# Mac OSX | ||
.DS_Store | ||
|
||
# Generated files | ||
doc/column_descriptions.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
jinja2>3.1 | ||
sphinx-toolbox | ||
sphinx-rtd-theme>1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
# -*- coding: utf-8 -*- | ||
""" | ||
===================== | ||
desidatamodel.columns | ||
===================== | ||
Render the standard column descriptions file. | ||
""" | ||
import csv | ||
import sys | ||
import importlib.resources as ir | ||
import jinja2 | ||
|
||
|
||
def format_columns(rows): | ||
"""Does something. | ||
Parameters | ||
---------- | ||
rows : iterable | ||
An iterable containing rows with any number of columns. | ||
Returns | ||
------- | ||
:class:`tuple` | ||
A tuple containing a format string, and an RST-style table separator. | ||
""" | ||
lengths = list() | ||
for row in rows: | ||
for k, col in enumerate(row): | ||
try: | ||
if len(col) > lengths[k]: | ||
lengths[k] = len(col) | ||
except IndexError: | ||
lengths.append(len(col)) | ||
format_string = " ".join(["{{{0}:{1}}}".format(k, c) for k, c in enumerate(lengths)]) | ||
separator = ' '.join(['='*k for k in lengths]) | ||
return (format_string, separator) | ||
|
||
|
||
def main(): | ||
"""Entry point for command-line scripts. | ||
Returns | ||
------- | ||
:class:`int` | ||
An integer suitable for passing to :func:`sys.exit`. | ||
""" | ||
env = jinja2.Environment(loader=jinja2.PackageLoader('desidatamodel', package_path='data'), | ||
trim_blocks=True) | ||
template = env.get_template('column_descriptions.rst') | ||
columns = ir.files('desidatamodel') / 'data' / 'column_descriptions.csv' | ||
with open(columns, newline='') as cf: | ||
reader = csv.reader(cf) | ||
format_string, separator = format_columns(reader) | ||
cf.seek(0) | ||
print(template.render(reader=reader, format_string=format_string, separator=separator)) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
============================ | ||
Standard Column Descriptions | ||
============================ | ||
|
||
This file is an auto-generated version of `column_descriptions.csv`_, | ||
which contains the descriptions of table column names regardless of | ||
what file(s) they appear in. | ||
|
||
.. _`column_descriptions.csv`: https://github.com/desihub/desidatamodel/blob/main/py/desidatamodel/data/column_descriptions.csv | ||
|
||
{% for row in reader %} | ||
{% if loop.first %} | ||
{{ separator }} | ||
{% endif %} | ||
{{ format_string.format(*row) }} | ||
{% if loop.first %} | ||
{{ separator }} | ||
{% endif %} | ||
{% if loop.last %} | ||
{{ separator }} | ||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.