diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
commit | c9ef4ed560a5de28fce031882257b6741565284e (patch) | |
tree | 07afa40629447df997726efd4de84d5987ff5e50 /docs | |
parent | Initial commit. (diff) | |
download | cli-helpers-upstream.tar.xz cli-helpers-upstream.zip |
Adding upstream version 2.3.1.upstream/2.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/Makefile | 20 | ||||
-rw-r--r-- | docs/source/api.rst | 23 | ||||
-rw-r--r-- | docs/source/authors.rst | 1 | ||||
-rw-r--r-- | docs/source/changelog.rst | 1 | ||||
-rw-r--r-- | docs/source/conf.py | 202 | ||||
-rw-r--r-- | docs/source/contributing.rst | 1 | ||||
-rw-r--r-- | docs/source/index.rst | 30 | ||||
-rw-r--r-- | docs/source/license.rst | 13 | ||||
-rw-r--r-- | docs/source/quickstart.rst | 153 |
9 files changed, 444 insertions, 0 deletions
diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..4efb828 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = CLIHelpers +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
\ No newline at end of file diff --git a/docs/source/api.rst b/docs/source/api.rst new file mode 100644 index 0000000..a95d314 --- /dev/null +++ b/docs/source/api.rst @@ -0,0 +1,23 @@ +API +=== + +.. automodule:: cli_helpers + +Tabular Output +-------------- + +.. automodule:: cli_helpers.tabular_output + :members: + :imported-members: + +Preprocessors ++++++++++++++ + +.. automodule:: cli_helpers.tabular_output.preprocessors + :members: + +Config +------ + +.. automodule:: cli_helpers.config + :members: diff --git a/docs/source/authors.rst b/docs/source/authors.rst new file mode 100644 index 0000000..5078189 --- /dev/null +++ b/docs/source/authors.rst @@ -0,0 +1 @@ +.. include:: ../../AUTHORS diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst new file mode 100644 index 0000000..e272c5a --- /dev/null +++ b/docs/source/changelog.rst @@ -0,0 +1 @@ +.. include:: ../../CHANGELOG diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..cf99ea6 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# CLI Helpers documentation build configuration file, created by +# sphinx-quickstart on Mon Apr 17 20:26:02 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import ast +from collections import OrderedDict + +# import os +import re + +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.viewcode"] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +html_sidebars = { + "**": [ + "about.html", + "navigation.html", + "relations.html", + "searchbox.html", + "donate.html", + ] +} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = ".rst" + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = "CLI Helpers" +author = "dbcli" +description = "Python helpers for common CLI tasks" +copyright = "2017, dbcli" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +_version_re = re.compile(r"__version__\s+=\s+(.*)") +with open("../../cli_helpers/__init__.py", "rb") as f: + version = str( + ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)) + ) + +# The full version, including alpha/beta/rc tags. +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. + +nav_links = OrderedDict( + ( + ("CLI Helpers at GitHub", "https://github.com/dbcli/cli_helpers"), + ("CLI Helpers at PyPI", "https://pypi.org/project/cli_helpers"), + ("Issue Tracker", "https://github.com/dbcli/cli_helpers/issues"), + ) +) + +html_theme_options = { + "description": description, + "github_user": "dbcli", + "github_repo": "cli_helpers", + "github_banner": False, + "github_button": False, + "github_type": "watch", + "github_count": False, + "extra_nav_links": nav_links, +} + + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = "CLIHelpersdoc" + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, "CLIHelpers.tex", "CLI Helpers Documentation", "dbcli", "manual"), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [(master_doc, "clihelpers", "CLI Helpers Documentation", [author], 1)] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "CLIHelpers", + "CLI Helpers Documentation", + author, + "CLIHelpers", + description, + "Miscellaneous", + ), +] + + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), + "py2": ("https://docs.python.org/2", None), + "pymysql": ("https://pymysql.readthedocs.io/en/latest/", None), + "numpy": ("https://docs.scipy.org/doc/numpy", None), + "configobj": ("https://configobj.readthedocs.io/en/latest", None), +} + +linkcheck_ignore = ["https://github.com/psf/black.*"] diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst new file mode 100644 index 0000000..ac7b6bc --- /dev/null +++ b/docs/source/contributing.rst @@ -0,0 +1 @@ +.. include:: ../../CONTRIBUTING.rst diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..09035fe --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,30 @@ +Welcome to CLI Helpers +====================== + +.. include:: ../../README.rst + :start-after: start-body + :end-before: end-body + +Installation +------------ +You can get the library directly from `PyPI <https://pypi.org/>`_:: + + $ pip install cli_helpers + +User Guide +---------- +.. toctree:: + :maxdepth: 2 + + quickstart + contributing + changelog + authors + license + +API +--- +.. toctree:: + :maxdepth: 2 + + api diff --git a/docs/source/license.rst b/docs/source/license.rst new file mode 100644 index 0000000..caa73a3 --- /dev/null +++ b/docs/source/license.rst @@ -0,0 +1,13 @@ +License +======= + +CLI Helpers is licensed under the BSD 3-clause license. This basically means +you can do what you'd like with the source code as long as you include a copy +of the license, don't modify the conditions, and keep the disclaimer around. +Plus, you can't use the authors' names to promote your software without their +written consent. + +License Text +++++++++++++ + +.. include:: ../../LICENSE diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst new file mode 100644 index 0000000..b304de2 --- /dev/null +++ b/docs/source/quickstart.rst @@ -0,0 +1,153 @@ +Quickstart +========== + +Displaying Tabular Data +----------------------- + + +The Basics +++++++++++ + +CLI Helpers provides a simple way to display your tabular data (columns/rows) in a visually-appealing manner:: + + >>> from cli_helpers import tabular_output + + >>> data = [[1, 'Asgard', True], [2, 'Camelot', False], [3, 'El Dorado', True]] + >>> headers = ['id', 'city', 'visited'] + + >>> print("\n".join(tabular_output.format_output(iter(data), headers, format_name='simple'))) + + id city visited + ---- --------- --------- + 1 Asgard True + 2 Camelot False + 3 El Dorado True + +Let's take a look at what we did there. + +1. We imported the :mod:`~cli_helpers.tabular_output` module. This module gives us access to the :func:`~cli_helpers.tabular_output.format_output` function. + +2. Next we generate some data. Plus, we need a list of headers to give our data some context. + +3. We format the output using the display format ``simple``. That's a nice looking table! + + +Display Formats ++++++++++++++++ + +To display your data, :mod:`~cli_helpers.tabular_output` uses +`tabulate <https://bitbucket.org/astanin/python-tabulate>`_, +`terminaltables <https://robpol86.github.io/terminaltables/>`_, :mod:`csv`, +and its own vertical table layout. + +The best way to see the various display formats is to use the +:class:`~cli_helpers.tabular_output.TabularOutputFormatter` class. This is +what the :func:`~cli_helpers.tabular_output.format_output` function in our +first example uses behind the scenes. + +Let's get a list of all the supported format names:: + + >>> from cli_helpers.tabular_output import TabularOutputFormatter + >>> formatter = TabularOutputFormatter() + >>> formatter.supported_formats + ('vertical', 'csv', 'tsv', 'mediawiki', 'html', 'latex', 'latex_booktabs', 'textile', 'moinmoin', 'jira', 'plain', 'minimal', 'simple', 'grid', 'fancy_grid', 'pipe', 'orgtbl', 'psql', 'psql_unicode', 'rst', 'ascii', 'double', 'github') + +You can format your data in any of those supported formats. Let's take the +same data from our first example and put it in the ``fancy_grid`` format:: + + >>> data = [[1, 'Asgard', True], [2, 'Camelot', False], [3, 'El Dorado', True]] + >>> headers = ['id', 'city', 'visited'] + >>> print("\n".join(formatter.format_output(iter(data), headers, format_name='fancy_grid'))) + ╒══════╤═══════════╤═══════════╕ + │ id │ city │ visited │ + ╞══════╪═══════════╪═══════════╡ + │ 1 │ Asgard │ True │ + ├──────┼───────────┼───────────┤ + │ 2 │ Camelot │ False │ + ├──────┼───────────┼───────────┤ + │ 3 │ El Dorado │ True │ + ╘══════╧═══════════╧═══════════╛ + +That was easy! How about CLI Helper's vertical table layout? + + >>> print("\n".join(formatter.format_output(iter(data), headers, format_name='vertical'))) + ***************************[ 1. row ]*************************** + id | 1 + city | Asgard + visited | True + ***************************[ 2. row ]*************************** + id | 2 + city | Camelot + visited | False + ***************************[ 3. row ]*************************** + id | 3 + city | El Dorado + visited | True + + +Default Format +++++++++++++++ + +When you create a :class:`~cli_helpers.tabular_output.TabularOutputFormatter` +object, you can specify a default formatter so you don't have to pass the +format name each time you want to format your data:: + + >>> formatter = TabularOutputFormatter(format_name='plain') + >>> print("\n".join(formatter.format_output(iter(data), headers))) + id city visited + 1 Asgard True + 2 Camelot False + 3 El Dorado True + +.. TIP:: + You can get or set the default format whenever you'd like through + :data:`TabularOutputFormatter.format_name <cli_helpers.tabular_output.TabularOutputFormatter.format_name>`. + + +Passing Options to the Formatters ++++++++++++++++++++++++++++++++++ + +Many of the formatters have settings that can be tweaked by passing +an optional argument when you format your data. For example, +if we wanted to enable or disable number parsing on any of +`tabulate's <https://bitbucket.org/astanin/python-tabulate>`_ +formats, we could:: + + >>> data = [[1, 1.5], [2, 19.605], [3, 100.0]] + >>> headers = ['id', 'rating'] + >>> print("\n".join(format_output(iter(data), headers, format_name='simple', disable_numparse=True))) + id rating + ---- -------- + 1 1.5 + 2 19.605 + 3 100.0 + >>> print("\n".join(format_output(iter(data), headers, format_name='simple', disable_numparse=False))) + id rating + ---- -------- + 1 1.5 + 2 19.605 + 3 100 + + +Lists and tuples and bytearrays. Oh my! ++++++++++++++++++++++++++++++++++++++++ + +:mod:`~cli_helpers.tabular_output` supports any :term:`iterable`, not just +a :class:`list` or :class:`tuple`. You can use a :class:`range`, +:func:`enumerate`, a :class:`str`, or even a :class:`bytearray`! Here is a +far-fetched example to prove the point:: + + >>> step = 3 + >>> data = [range(n, n + step) for n in range(0, 9, step)] + >>> headers = 'abc' + >>> print("\n".join(format_output(iter(data), headers, format_name='simple'))) + a b c + --- --- --- + 0 1 2 + 3 4 5 + 6 7 8 + +Real life examples include a PyMySQL +:class:`Cursor <pymysql:pymysql.cursors.Cursor>` with +database results or +NumPy :class:`ndarray <numpy:numpy.ndarray>` with data points. |