diff --git a/docs/source/conf.py b/docs/source/conf.py index 4f38585..410024d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -40,8 +40,13 @@ "sphinxcontrib_trio", "enum_tools.autoenum", "sphinxext.opengraph", + "sphinx_toolbox.more_autodoc.typehints", ] +intersphinx_mapping = { + "py": ("https://docs.python.org/3", None), +} + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] diff --git a/docs/source/generate_style_list.py b/docs/source/generate_style_list.py index 26efe56..633b225 100644 --- a/docs/source/generate_style_list.py +++ b/docs/source/generate_style_list.py @@ -36,7 +36,7 @@ def generate_style_list(): last_col_heading=False, style=styles[style], ) - style_heading = f"`{style}`\n" + "~" * len(f"`{style}`") + style_heading = f".. _PresetStyle.{style}:\n\n`{style}`\n" + "~" * len(f"`{style}`") output_example = indent_all_lines(full + "\n\n" + body_only) style_list += f"{style_heading}\n\n.. code-block:: none\n\n{output_example}\n\n" # put it all together diff --git a/docs/source/styles.rst b/docs/source/styles.rst index e945461..449703a 100644 --- a/docs/source/styles.rst +++ b/docs/source/styles.rst @@ -5,6 +5,8 @@ Preset styles .. contents:: +.. _PresetStyle.ascii: + `ascii` ~~~~~~~ @@ -26,6 +28,8 @@ Preset styles | 2 | 30 40 35 30 | +---+-------------------+ +.. _PresetStyle.ascii_borderless: + `ascii_borderless` ~~~~~~~~~~~~~~~~~~ @@ -41,6 +45,8 @@ Preset styles 1 | 30 40 35 30 2 | 30 40 35 30 +.. _PresetStyle.ascii_box: + `ascii_box` ~~~~~~~~~~~ @@ -62,6 +68,8 @@ Preset styles | 2 | 30 | 40 | 35 | 30 | +---+----+----+----+----+ +.. _PresetStyle.ascii_compact: + `ascii_compact` ~~~~~~~~~~~~~~~ @@ -81,6 +89,8 @@ Preset styles | 2 | 30 40 35 30 | +---+-------------------+ +.. _PresetStyle.ascii_double: + `ascii_double` ~~~~~~~~~~~~~~ @@ -102,6 +112,8 @@ Preset styles | 2 | 30 40 35 30 | +---+-------------------+ +.. _PresetStyle.ascii_minimalist: + `ascii_minimalist` ~~~~~~~~~~~~~~~~~~ @@ -123,6 +135,8 @@ Preset styles 2 | 30 40 35 30 ----------------------- +.. _PresetStyle.ascii_simple: + `ascii_simple` ~~~~~~~~~~~~~~ @@ -142,6 +156,8 @@ Preset styles 2 | 30 40 35 30 === ==== ==== ==== ==== +.. _PresetStyle.borderless: + `borderless` ~~~~~~~~~~~~ @@ -157,6 +173,8 @@ Preset styles 1 ┃ 30 40 35 30 2 ┃ 30 40 35 30 +.. _PresetStyle.double: + `double` ~~~~~~~~ @@ -178,6 +196,8 @@ Preset styles ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ +.. _PresetStyle.double_box: + `double_box` ~~~~~~~~~~~~ @@ -199,6 +219,8 @@ Preset styles ║ 2 ║ 30 ║ 40 ║ 35 ║ 30 ║ ╚═══╩════╩════╩════╩════╝ +.. _PresetStyle.double_compact: + `double_compact` ~~~~~~~~~~~~~~~~ @@ -218,6 +240,8 @@ Preset styles ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ +.. _PresetStyle.double_thin_compact: + `double_thin_compact` ~~~~~~~~~~~~~~~~~~~~~ @@ -237,6 +261,8 @@ Preset styles ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ +.. _PresetStyle.markdown: + `markdown` ~~~~~~~~~~ @@ -252,6 +278,8 @@ Preset styles | 1 | 30 | 40 | 35 | 30 | | 2 | 30 | 40 | 35 | 30 | +.. _PresetStyle.minimalist: + `minimalist` ~~~~~~~~~~~~ @@ -273,6 +301,8 @@ Preset styles 2 │ 30 40 35 30 ─────────────────────── +.. _PresetStyle.simple: + `simple` ~~~~~~~~ @@ -292,6 +322,8 @@ Preset styles 2 ║ 30 40 35 30 ═══ ════ ════ ════ ════ +.. _PresetStyle.thick: + `thick` ~~~~~~~ @@ -313,6 +345,8 @@ Preset styles ┃ 2 ┃ 30 40 35 30 ┃ ┗━━━┻━━━━━━━━━━━━━━━━━━━┛ +.. _PresetStyle.thick_box: + `thick_box` ~~~~~~~~~~~ @@ -334,6 +368,8 @@ Preset styles ┃ 2 ┃ 30 ┃ 40 ┃ 35 ┃ 30 ┃ ┗━━━┻━━━━┻━━━━┻━━━━┻━━━━┛ +.. _PresetStyle.thick_compact: + `thick_compact` ~~~~~~~~~~~~~~~ @@ -353,6 +389,8 @@ Preset styles ┃ 2 ┃ 30 40 35 30 ┃ ┗━━━┻━━━━━━━━━━━━━━━━━━━┛ +.. _PresetStyle.thin: + `thin` ~~~~~~ @@ -374,6 +412,8 @@ Preset styles │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ +.. _PresetStyle.thin_box: + `thin_box` ~~~~~~~~~~ @@ -395,6 +435,8 @@ Preset styles │ 2 │ 30 │ 40 │ 35 │ 30 │ └───┴────┴────┴────┴────┘ +.. _PresetStyle.thin_compact: + `thin_compact` ~~~~~~~~~~~~~~ @@ -414,6 +456,8 @@ Preset styles │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ +.. _PresetStyle.thin_compact_rounded: + `thin_compact_rounded` ~~~~~~~~~~~~~~~~~~~~~~ @@ -433,6 +477,8 @@ Preset styles │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ +.. _PresetStyle.thin_double: + `thin_double` ~~~~~~~~~~~~~ @@ -454,6 +500,8 @@ Preset styles │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ +.. _PresetStyle.thin_double_rounded: + `thin_double_rounded` ~~~~~~~~~~~~~~~~~~~~~ @@ -475,6 +523,8 @@ Preset styles │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ +.. _PresetStyle.thin_rounded: + `thin_rounded` ~~~~~~~~~~~~~~ @@ -496,6 +546,8 @@ Preset styles │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ +.. _PresetStyle.thin_thick: + `thin_thick` ~~~~~~~~~~~~ @@ -517,6 +569,8 @@ Preset styles │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ +.. _PresetStyle.thin_thick_rounded: + `thin_thick_rounded` ~~~~~~~~~~~~~~~~~~~~ diff --git a/table2ascii/table_style.py b/table2ascii/table_style.py index d3c9b93..2239616 100644 --- a/table2ascii/table_style.py +++ b/table2ascii/table_style.py @@ -65,10 +65,10 @@ def from_string(cls, string: str) -> "TableStyle": Create a TableStyle from a string Args: - string (:class:`str`): The string to create the TableStyle from + string: The string to create the TableStyle from Returns: - :class:`TableStyle`: A TableStyle object + A TableStyle object Example:: diff --git a/table2ascii/table_to_ascii.py b/table2ascii/table_to_ascii.py index 51a4768..b0f07bf 100644 --- a/table2ascii/table_to_ascii.py +++ b/table2ascii/table_to_ascii.py @@ -21,10 +21,10 @@ def __init__( Validate arguments and initialize fields Args: - header (Optional[List[Any]]): The values in the header of the table - body (Optional[List[List[Any]]]): The rows of values in the body of the table - footer (Optional[List[Any]]): The values in the footer of the table - options (Options): The options for the table + header: The values in the header of the table + body: The rows of values in the body of the table + footer: The values in the footer of the table + options: The options for the table """ # initialize fields self.__header = header @@ -76,7 +76,7 @@ def __count_columns(self) -> int: provided header, footer, and body lists. Returns: - int: The number of columns in the table + The number of columns in the table """ if self.__header: return len(self.__header) @@ -92,7 +92,7 @@ def __auto_column_widths(self) -> List[int]: each column in the table with 1 space of padding on each side. Returns: - List[int]: The minimum number of characters needed for each column + The minimum number of characters needed for each column """ def widest_line(text: str) -> int: @@ -117,12 +117,12 @@ def __pad(self, cell_value: Any, width: int, alignment: Alignment) -> str: Pad a string of text to a given width with specified alignment Args: - cell_value (Any): The text in the cell to pad - width (int): The width in characters to pad to - alignment (Alignment): The alignment to use + cell_value: The text in the cell to pad + width: The width in characters to pad to + alignment: The alignment to use Returns: - str: The padded text + The padded text """ text = str(cell_value) if alignment == Alignment.LEFT: @@ -150,7 +150,7 @@ def __row_to_ascii( Assembles a line of text in the ascii table Returns: - str: The line in the ascii table + The line in the ascii table """ output = "" # find the maximum number of lines a single cell in the column has (minimum of 1) @@ -203,7 +203,7 @@ def __top_edge_to_ascii(self) -> str: Assembles the top edge of the ascii table Returns: - str: The top edge of the ascii table + The top edge of the ascii table """ return self.__row_to_ascii( left_edge=self.__style.top_left_corner, @@ -218,7 +218,7 @@ def __bottom_edge_to_ascii(self) -> str: Assembles the bottom edge of the ascii table Returns: - str: The bottom edge of the ascii table + The bottom edge of the ascii table """ return self.__row_to_ascii( left_edge=self.__style.bottom_left_corner, @@ -233,7 +233,7 @@ def __heading_row_to_ascii(self, row: List) -> str: Assembles the header or footer row line of the ascii table Returns: - str: The header or footer row line of the ascii table + The header or footer row line of the ascii table """ return self.__row_to_ascii( left_edge=self.__style.left_and_right_edge, @@ -248,7 +248,7 @@ def __heading_sep_to_ascii(self) -> str: Assembles the seperator below the header or above footer of the ascii table Returns: - str: The seperator line + The seperator line """ return self.__row_to_ascii( left_edge=self.__style.heading_row_left_tee, @@ -263,7 +263,7 @@ def __body_to_ascii(self, body: List[List[Any]]) -> str: Assembles the body of the ascii table Returns: - str: The body of the ascii table + The body of the ascii table """ separation_row = self.__row_to_ascii( left_edge=self.__style.row_left_tee, @@ -288,7 +288,7 @@ def to_ascii(self) -> str: Generates a formatted ASCII table Returns: - str: The generated ASCII table + The generated ASCII table """ # top row of table table = self.__top_edge_to_ascii() @@ -324,27 +324,28 @@ def table2ascii( Convert a 2D Python table to ASCII text Args: - header (Optional[List[Any]]): List of column values in the table's header row. - If not specified, the table will not have a header row. - body (Optional[List[List[Any]]]): 2-dimensional list of values in the table's body. - If not specified, the table will not have a body. - footer (Optional[List[Any]]): List of column values in the table's footer row. - If not specified, the table will not have a footer row. - first_col_heading (:class:`bool`): Whether to add a header column separator after the first - column. Defaults to ``False``. - last_col_heading (:class:`bool`): Whether to add a header column separator before the last - column. Defaults to ``False``. - column_widths (Optional[List[Optional[:class:`int`]]]): List of widths in characters for each - column. Any value of ``None`` indicates that the column width should be determined automatically. - If ``column_widths`` is set to ``None``, all columns will be automatically sized. Defaults to ``None``. - alignments (Optional[List[:class:`Alignment`]]): List of alignments for each column - (ex. ``[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]``). If not specified or set to ``None``, - all columns will be center-aligned. Defaults to ``None``. - style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported). - Defaults to :data:`PresetStyle.double_thin_compact`. + header: List of column values in the table's header row. If not specified, + the table will not have a header row. + body: 2-dimensional list of values in the table's body. If not specified, + the table will not have a body. + footer: List of column values in the table's footer row. If not specified, + the table will not have a footer row. + first_col_heading: Whether to add a header column separator after the first column. + Defaults to :py:obj:`False`. + last_col_heading: Whether to add a header column separator before the last column. + Defaults to :py:obj:`False`. + column_widths: List of widths in characters for each column. Any value of :py:obj:`None` + indicates that the column width should be determined automatically. If :py:obj:`None` + is passed instead of a :py:obj:`~typing.List`, all columns will be automatically sized. + Defaults to :py:obj:`None`. + alignments: List of alignments for each column + (ex. ``[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]``). If not specified or set to + :py:obj:`None`, all columns will be center-aligned. Defaults to :py:obj:`None`. + style: Table style to use for styling (preset styles can be imported). + Defaults to :ref:`PresetStyle.double_thin_compact `. Returns: - :class:`str`: The generated ASCII table + The generated ASCII table """ return TableToAscii( header,