From 57bc0d56d7e741e1e99d96f14e7ab93232440a16 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 30 Jan 2021 09:13:47 +0100 Subject: Adding upstream version 2.1.0. Signed-off-by: Daniel Baumann --- docs/Makefile | 20 +++++ docs/source/api.rst | 23 +++++ docs/source/authors.rst | 1 + docs/source/changelog.rst | 1 + docs/source/conf.py | 200 +++++++++++++++++++++++++++++++++++++++++++ docs/source/contributing.rst | 1 + docs/source/index.rst | 30 +++++++ docs/source/license.rst | 13 +++ docs/source/quickstart.rst | 153 +++++++++++++++++++++++++++++++++ 9 files changed, 442 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/source/api.rst create mode 100644 docs/source/authors.rst create mode 100644 docs/source/changelog.rst create mode 100644 docs/source/conf.py create mode 100644 docs/source/contributing.rst create mode 100644 docs/source/index.rst create mode 100644 docs/source/license.rst create mode 100644 docs/source/quickstart.rst (limited to 'docs') 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..4944893 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,200 @@ +#!/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) +} 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 `_:: + + $ 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..0cbd45b --- /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(tabular_output.format_output(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 `_, +`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', 'simple', 'grid', 'fancy_grid', 'pipe', 'orgtbl', 'psql', '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(formatter.format_output(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(formatter.format_output(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(formatter.format_output(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 `. + + +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 `_ +formats, we could:: + + >>> data = [[1, 1.5], [2, 19.605], [3, 100.0]] + >>> headers = ['id', 'rating'] + >>> print(format_output(data, headers, format_name='simple', disable_numparse=True)) + id rating + ---- -------- + 1 1.5 + 2 19.605 + 3 100.0 + >>> print(format_output(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(format_output(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 ` with +database results or +NumPy :class:`ndarray ` with data points. -- cgit v1.2.3