pudl.convert.datapkg_to_rst module

Module to convert json metadata into rst files.

All of the information about the transformed pudl tables, namely their fields types and descriptions, resides in the datapackage metadata. This module makes that information available to users, without duplicating any data, by converting json metadata files into documentation-compatible rst files. The functions serve to extract the field names, field data types, and field descriptions of each pudl table and outputs them in a manner that automatically updates the read-the-docs.

pudl.convert.datapkg_to_rst.RST_TEMPLATE = '\n===============================================================================\nPUDL Data Dictionary\n===============================================================================\n\nThe following data tables have been cleaned and transformed by our ETL process.\n\n{% for resource in resources %}\n.. _{{ resource.name }}:\n\n-------------------------------------------------------------------------------\n{{ resource.name }}\n-------------------------------------------------------------------------------\n\n{{ resource.description | wordwrap(78)}}\n`Browse or query this table in Datasette. <https://data.catalyst.coop/pudl/{{ resource.name }}>`__\n\n.. list-table::\n  :widths: auto\n  :header-rows: 1\n\n  * - **Field Name**\n    - **Type**\n    - **Description**{% for field in resource.schema.fields %}\n  * - {{ field.name }}\n    - {{ field.type }}{% if field.description %}\n    - {{ field.description }}{% else %}\n    - N/A{% endif %}{% endfor %}\n{% endfor %}\n'

A template to map data from a json dictionary into one rst file. Contains multiple tables seperated by headers.

pudl.convert.datapkg_to_rst.datapkg2rst(meta_json, meta_rst, ignore=None)[source]

Convert json metadata to a single rst file.

pudl.convert.datapkg_to_rst.logger = <Logger pudl.convert.datapkg_to_rst (WARNING)>

The following templates map json data into one long rst file seperated by table titles and document links (RST_TEMPLATE)

It’s important for the templates that the json data do not contain excess white space either at the beginning or the end of each value.

pudl.convert.datapkg_to_rst.main()[source]

Run conversion from json to rst.

pudl.convert.datapkg_to_rst.parse_command_line(argv)[source]

Parse command line arguments. See the -h option.

Parameters

argv (str) – Command line arguments, including caller filename.

Returns

Dictionary of command line arguments and their parsed values.

Return type

dict