cape.tnakit.rstutils
: Tools for writing ReST files¶
This module contains tools to write text formatted for reStructuredText
(reST). This includes various markup options and tools for creating the
directives to include images. Of particular interest are the functions
rst_image_table_lines()
and rst_image_table()
, which
simplifies the important task of creating a table that includes several
images.
- cape.tnakit.rstutils.py2rst(v, **kw)¶
Convert a generic Python object to reST text
- Call:
>>> txt = py2rst(v, **kw)
- Inputs:
- Outputs:
- txt:
str
Marked up reST text
- txt:
- Versions:
2019-04-25
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_any_repr(v, markup=True)¶
Convert a Python to reST text using
repr()
- Call:
>>> txt = py2rst_any_repr(v, markup=True)
- Inputs:
- v: any
Quantity to convert using
repr()
- markup: {
True
} |False
Whether or not to add backticks around converted text
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-04-25
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_any_str(v, markup=True)¶
Convert a Python to reST text using
str()
- Call:
>>> txt = py2rst_any_str(v, markup=True)
- Inputs:
- v: any
Quantity to convert using
repr()
- markup: {
True
} |False
Whether or not to add backticks around converted text
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-04-25
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_dict(v, **kw)¶
Convert a
dict
to reST text- Call:
>>> txt = py2rst_dict(v, **kw)
- Inputs:
- v:
dict
Python dictionary to convert to reST text
- alignfields:
True
| {False
} Option to align right-hand side if text fits on one row
- sort:
True
| {False
} Whether or not to sort dictionary keys
- sortkey: {
None
} |function
Function to use for sorting if sort is
True
- sortreverse:
True
| {False
} Option to reverse the sort if sort is
True
- markup:
True
| {False
} Default value for option to add backticks
- indent: {
0
} |int
≥ 0 Number of spaces of indentation
- hang: {indent} |
int
≥ 0 Number of spaces of indent for continuation lines
- tab: {
4
} |int
≥ 0 Number of spaces to add to deeper indentation levels
- maxcols: {
79
} |int
> 0 Maximum number of columns in a line
- markuplength: {
50
} |int
≥ 0 Cutoff length for default marked strings
- fmt:
True
|False
- markups:
dict
[bool
] Specific markup for types
"int"
,"float"
,"None"
,"str"
,"__repr__"
, and"__str__"
- fmts:
dict
[str
] Specific fmt for types
"int"
and/or"float"
- v:
- Versions:
2019-04-25
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_float(x, markup=False, fmt='%s')¶
Convert a Python
float
to reST text- Call:
>>> txt = py2rst_float(x, markup=False, fmt="%s")
- Inputs:
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-04-24
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_int(i, markup=False, fmt='%s')¶
Convert a Python
int
to reST text- Call:
>>> txt = py2rst_int(i, markup=False, fmt="%s")
- Inputs:
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-04-24
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_list(V, **kw)¶
Convert a list to reST text
- Call:
>>> txt = py2rst_list(V, **kw)
- Inputs:
- V:
list
|tuple
List of Python quantitites to convert
- markup:
True
| {False
} Default value for option to add backticks
- indent: {
0
} |int
≥ 0 Number of spaces of indentation
- hang: {indent} |
int
≥ 0 Number of spaces of indent for continuation lines
- maxcols: {
79
} |int
> 0 Maximum number of columns in a line
- markuplength: {
50
} |int
≥ 0 Cutoff length for default marked strings
- fmt:
True
|False
- markups:
dict
[bool
] Specific markup for types
"int"
,"float"
,"None"
,"str"
,"__repr__"
, and"__str__"
- fmts:
dict
[str
] Specific fmt for types
"int"
and/or"float"
- strlist:
True
| {False
} Option to always use list for lists of strings
- V:
- Versions:
2019-04-25
@ddalle
: Versopm 1.02021-03-24
@ddalle
: Version 1.1; strlist option
- cape.tnakit.rstutils.py2rst_mod(mod, markup=True)¶
Convert a Python module to reST text
- Call:
>>> txt = py2rst_mod(mod, markup=True)
- Inputs:
- mod:
module
A Python module
- markup: {
True
} |False
Option to use reST
:mod:
role
- mod:
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-12-27
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_none(markup=True)¶
Convert Python
None
to reST text- Call:
>>> txt = py2rst_none(markup=True)
- Inputs:
- markup: {
True
} |False
Whether or not to add backticks around converted text
- markup: {
- Outputs:
- txt:
str
Text representation for reST
- txt:
- Versions:
2019-04-24
@ddalle
: Version 1.0
- cape.tnakit.rstutils.py2rst_str(s, **kw)¶
Convert a Python
str
to reST text- Call:
>>> txt = py2rst_str(s, **kw)
- Inputs:
- Outputs:
- txt:
str
Marked up reST text
- txt:
- Versions:
2019-04-25
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_directive_option(k, v)¶
Convert an option name and value to an reST directive option
- cape.tnakit.rstutils.rst_figure(ffig, caption, **kw)¶
Write the reST command to include an image
- Call:
>>> txt = rst_figure(ffig, caption, **kw)
- Inputs:
- ffig:
str
Name of image to include (often like
"myimage.*"
)- caption:
str
|unicode
Caption to use to describe figure
- tab: {
" "
} |int
Indent character for a tab (default is 4 spaces)
- indent: {tab} |
str
Indentation to place before each line
- width: {
None
} |str
Image width option value
- maxcol, maxcols, cwidth: {
79
} |int
> 0 Column number at which to wrap caption
- ffig:
- See Also:
- Outputs:
- txt:
str
Text of directive
- txt:
- Versions:
2019-02-24
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_image(ffig, caption=None, **kw)¶
Write the reST command to include an image
- Call:
>>> txt = rst_image(ffig, caption=None, **kw)
- Inputs:
- See Also:
- Outputs:
- txt:
str
Text of directive
- txt:
- Versions:
2019-02-24
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_image_lines(ffig, directive='image', **kw)¶
Write the reST command to include a figure
- Call:
>>> lines = rst_image_lines(ffig, directive="image", **kw)
- Inputs:
- ffig:
str
Name of image to include (often like
"myimage.*"
)- directive: {
"image"
} |"figure"
Which image-inclusion command to use
- tab: {
" "
} |int
Indent character for a tab (default is 4 spaces)
- sub, tag: {
None
} |str
Abbreviated name to use for a substitution instruction
- width: {
None
} |str
Image width option value
- name: {
None
} |str
Reference “name” to be used by later
:ref:
calls- target: {
None
} |str
URI for clickable image
- alt: {
None
} |str
Alternate text if image cannot be displayed
- figwidth: {
None
} |str
Width for figure, which contains an image (
"figure"
only)- maxcol, maxcols, cwidth: {
79
} |int
> 0 Column number at which to wrap
- ffig:
- Outputs:
- Versions:
2019-02-22
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_image_table(imgtable, caption=None, directive='table', **kw)¶
Process lines used to create a reST table of images
- Call:
>>> txt = rst_image_table(imgtable, **kw)
- Inputs:
- Outputs:
- Versions:
2019-02-26
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_image_table_lines(imgtable, **kw)¶
Process lines used to create a reST table of images
- Call:
>>> lines, subs = rst_image_table_lines(imgtable, **kw)
- Inputs:
- Outputs:
- Versions:
2019-02-26
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_param_list(keys, types, descrs, alts={}, **kw)¶
Write a docstring for a list of parameters
- Call:
>>> txt = rst_param_list(keys, types, descrs, alts={}, **kw)
- Inputs:
- keys:
list
[str
] List of parameters to describe
- types:
dict
[str
] Docstring of types for each key in keys
- descrs:
dict
[str
] Docstring of descriptions for each key in keys
- alts: {
{}
} |dict
[str
] Dictionary of optional names for certain keys
- indent: {
4
} |int
> 0 Indent spaces for each line
- tab: {
4
} |int
> 0 Additional spaces for further indentation
- width: {
72
} |int
Maximum width for line of text (including spaces)
- strict: {
True
} |False
If
False
, skip keys with missing type or description
- keys:
- Outputs:
- txt:
str
Text in CAPE docstring format describing keys
- txt:
- Versions:
2019-12-19
@ddalle
: Version 1.0
- cape.tnakit.rstutils.rst_title(title, char='-', margin=2, before=False)¶
Create an ReST title from string
This adds characters before (optionally) and after the title, creating valid syntax for ReStructuredText titles. Examples of valid titles with the input string
"Sample Title"
are shown below:Sample Title -------------- ============== Sample Title ============== ************ Sample Title ************
- Call:
>>> txt = rst_title(title, char="-", margin=2, before=False)
- Inputs:
- Outputs:
- txt:
str
|unicode
String with title, adornment line(s), and 2 or 3 newline chars
- txt:
- Versions:
2019-02-22
@ddalle
: Version 1.0
- cape.tnakit.rstutils.unpack_image_cell(cell)¶
Unpack contents of an image table cell
- Call:
>>> ffig, cap, kwj = unpack_image_cell(cell) >>> ffig, cap, kwj = unpack_image_cell(ffig) >>> ffig, cap, kwj = unpack_image_cell((ffig,)) >>> ffig, cap, kwj = unpack_image_cell((ffig, cap)) >>> ffig, cap, kwj = unpack_image_cell((ffig, kwj)) >>> ffig, cap, kwj = unpack_image_cell((ffig, cap, kwj))
- Inputs:
- Outputs:
- Versions:
2019-02-25
@ddalle
: Version 1.0