diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..5128596 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = . +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) diff --git a/docs/_static/.gitkeep b/docs/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..fbb19c0 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,189 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""This is an autogenerated sphinx config module.""" +# pylint: disable=invalid-name +# pylint: disable=redefined-builtin +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# 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. +# +from os import environ +from os.path import abspath, join +from recommonmark.parser import CommonMarkParser + +# -- Project information ----------------------------------------------------- + +project = 'Pacifica Dispatcher Example' +copyright = '2019, David Brown' +author = 'David Brown' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '' + + +# -- 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.viewcode', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +source_parsers = { + '.md': CommonMarkParser, +} +source_suffix = ['.rst', '.md'] + +# The master toctree document. +master_doc = 'index' + +# 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 pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + + +# -- 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 = 'sphinx_rtd_theme' + +# 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. +# +# html_theme_options = {} + +# 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'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'PacificaDispatcherExampledoc' + + +# -- 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, 'PacificaDispatcherExample.tex', 'Pacifica Dispatcher Example Documentation', + 'David Brown', '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, 'pacificadispatcherexample', 'Pacifica Dispatcher Example 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, 'PacificaDispatcherExample', 'Pacifica Dispatcher Example Documentation', + author, 'PacificaDispatcherExample', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + +# -- Extension configuration ------------------------------------------------- +autodoc_default_options = { + 'member-order': 'bysource', + 'special-members': '__init__', + 'undoc-members': None, + 'exclude-members': '__weakref__' +} diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..abfbddf --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,80 @@ +# Configuration + +The Pacifica Core services require two configuration files. The REST +API utilizes [CherryPy](https://github.com/cherrypy) and review of +their +[configuration documentation](http://docs.cherrypy.org/en/latest/config.html) +is recommended. The service configuration file is a INI formatted +file containing configuration for database connections. + +## CherryPy Configuration File + +An example of UniqueID server CherryPy configuration: + +```ini +[global] +log.screen: True +log.access_file: 'access.log' +log.error_file: 'error.log' +server.socket_host: '0.0.0.0' +server.socket_port: 8051 + +[/] +request.dispatch: cherrypy.dispatch.MethodDispatcher() +tools.response_headers.on: True +tools.response_headers.headers: [('Content-Type', 'application/json')] +``` + +## Starting the Service + +Starting the UniqueID service can be done by two methods. However, +understanding the requirements and how they apply to REST services +is important to address as well. Using the +internal CherryPy server to start the service is recommended for +Windows platforms. For Linux/Mac platforms it is recommended to +deploy the service with +[uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/). + +### Deployment Considerations + +### CherryPy Server + +To make running the UniqueID service using the CherryPy's builtin +server easier we have a command line entry point. + +``` +$ pacifica-uniqueid --help +usage: pacifica-uniqueid [-h] [-c CONFIG] [-p PORT] [-a ADDRESS] + +Run the uniqueid server. + +optional arguments: + -h, --help show this help message and exit + -c CONFIG, --config CONFIG + cherrypy config file + -p PORT, --port PORT port to listen on + -a ADDRESS, --address ADDRESS + address to listen on +$ pacifica-uniqueid-cmd dbsync +$ pacifica-uniqueid +[09/Jan/2019:09:17:26] ENGINE Listening for SIGTERM. +[09/Jan/2019:09:17:26] ENGINE Bus STARTING +[09/Jan/2019:09:17:26] ENGINE Set handler for console events. +[09/Jan/2019:09:17:26] ENGINE Started monitor thread 'Autoreloader'. +[09/Jan/2019:09:17:26] ENGINE Serving on http://0.0.0.0:8051 +[09/Jan/2019:09:17:26] ENGINE Bus STARTED +``` + +### uWSGI Server + +To make running the UniqueID service using uWSGI easier we have a +module to be included as part of the uWSGI configuration. uWSGI is +very configurable and can use this module many different ways. Please +consult the +[uWSGI Configuration](https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html) +documentation for more complicated deployments. + +``` +$ pip install uwsgi +$ uwsgi --http-socket :8051 --master -p 1 --module pacifica.uniqueid.wsgi +``` diff --git a/docs/dispatcher_example.rst b/docs/dispatcher_example.rst new file mode 100644 index 0000000..ad5db85 --- /dev/null +++ b/docs/dispatcher_example.rst @@ -0,0 +1,15 @@ +Dispatcher Example Python Module +============================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + example.main + example.event_handlers + example.router + +.. automodule:: pacifica.dispatcher_example + :members: + :private-members: + :special-members: diff --git a/docs/example.event_handlers.rst b/docs/example.event_handlers.rst new file mode 100644 index 0000000..00e8089 --- /dev/null +++ b/docs/example.event_handlers.rst @@ -0,0 +1,7 @@ +Event Handlers Module +============================================= + +.. automodule:: pacifica.dispatcher_example.event_handlers + :members: + :private-members: + :special-members: diff --git a/docs/example.main.rst b/docs/example.main.rst new file mode 100644 index 0000000..c468a72 --- /dev/null +++ b/docs/example.main.rst @@ -0,0 +1,7 @@ +Main Module +============================================= + +.. automodule:: pacifica.dispatcher_example.__main__ + :members: + :private-members: + :special-members: diff --git a/docs/example.router.rst b/docs/example.router.rst new file mode 100644 index 0000000..b052094 --- /dev/null +++ b/docs/example.router.rst @@ -0,0 +1,7 @@ +Router Module +============================================= + +.. automodule:: pacifica.dispatcher_example.router + :members: + :private-members: + :special-members: diff --git a/docs/exampleusage.md b/docs/exampleusage.md new file mode 100644 index 0000000..a56da81 --- /dev/null +++ b/docs/exampleusage.md @@ -0,0 +1 @@ +# Example Usage diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..2686040 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,26 @@ +.. Pacifica UniqueID documentation master file, created by + sphinx-quickstart on Thu Dec 6 20:05:08 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Pacifica UniqueID's documentation! +============================================= + +The Pacifica UniqueID service provides unique auto-incrementing integers +to the Pacifica Core services. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + installation + configuration + exampleusage + dispatcher_example + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000..ec3c73f --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,36 @@ +# Installation + +The Pacifica software is available through PyPi so creating a virtual +environment to install is what is shown below. Please keep in mind +compatibility with the Pacifica Core services. + +## Installation in Virtual Environment + +These installation instructions are intended to work on both Windows, +Linux, and Mac platforms. Please keep that in mind when following the +instructions. + +Please install the appropriate tested version of Python for maximum +chance of success. + +### Linux and Mac Installation + +``` +mkdir ~/.virtualenvs +python -m virtualenv ~/.virtualenvs/pacifica +. ~/.virtualenvs/pacifica/bin/activate +cd working/clone/pacifica-dispatcher-example +pip install . +``` + +### Windows Installation + +This is done using PowerShell. Please do not use Batch Command. + +``` +mkdir "$Env:LOCALAPPDATA\virtualenvs" +python.exe -m virtualenv "$Env:LOCALAPPDATA\virtualenvs\pacifica" +& "$Env:LOCALAPPDATA\virtualenvs\pacifica\Scripts\activate.ps1" +cd working\clone\pacifica-dispatcher-example +pip install . +``` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..fe808ff --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/readthedocs.yml b/readthedocs.yml new file mode 100644 index 0000000..78b05bb --- /dev/null +++ b/readthedocs.yml @@ -0,0 +1,5 @@ +build: + image: latest +python: + version: 3.7 + pip_install: true diff --git a/requirements-dev.txt b/requirements-dev.txt index aec7e1e..8fa503d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,3 +6,5 @@ pre-commit pylint pytest setuptools +recommonmark +sphinx_rtd_theme