Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sphinx support for autogen API docs. #11

Merged
merged 1 commit into from
Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ tag = True
commit = True

[bumpversion:file:ulid/__init__.py]

[bumpversion:file:docs/conf.py]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ clean-pyc: ## Remove local python cache files.
@find . -name '*.pyo' -exec rm -f {} +
@find . -name '*~' -exec rm -f {} +

.PHONY: docs
docs: ## Build project documentation.
@make -C docs html

.phony: help
help: ## Print Makefile usage.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = ulid
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)
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: ulid.api
:members:
:inherited-members:
3 changes: 3 additions & 0 deletions docs/base32.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: ulid.base32
:members:
:inherited-members:
157 changes: 157 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""
docs/conf
~~~~~~~~~

Configuration for Sphinx documentation.
"""
import datetime
import os
import sys

import sphinx_rtd_theme

from sphinx.ext.autodoc import ModuleLevelDocumenter, DataDocumenter


sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('.'))


# 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.todo',
'sphinx.ext.coverage',
'sphinx.ext.autosummary',
'sphinx.ext.githubpages']

# 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_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'ulid'
copyright = '{}, Andrew Hawker'.format(datetime.datetime.now().year)
author = 'Andrew Hawker'

# 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.
#
# The short X.Y version.
version = '0.0.2'
# 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 = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# Autodoc configuration
autoclass_content = "both"
autodoc_member_order = 'bysource'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

html_show_sphinx = False
html_use_modindex = False
html_show_sourcelink = False

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# 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']

# Output file base name for HTML help builder.
htmlhelp_basename = '{}doc'.format(project)

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, 'ulid.tex', 'ulid Documentation',
'Andrew Hawker', 'manual'),
]

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ulid', 'ulid Documentation',
[author], 1)
]

# 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, 'ulid', 'ulid Documentation',
author, 'ulid', 'Universally Unique Lexicographically Sortable Identifier',
'Miscellaneous'),
]

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

# Bibliographic Dublin Core info.
epub_title = project
epub_author = author
epub_publisher = author
epub_copyright = copyright

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

# Disable displaying module member values.
DataDocumenter.add_directive_header = lambda s, sig: ModuleLevelDocumenter.add_directive_header(s, sig)
3 changes: 3 additions & 0 deletions docs/hints.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: ulid.hints
:members:
:inherited-members:
18 changes: 18 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:orphan:

ulid
====

Universally Unique Lexicographically Sortable Identifier.

Modules
=======

.. toctree::
:maxdepth: 1
:titlesonly:

api.py - Defines the public package interface. <api>
base32.py - Functionality for encoding/decoding ULID strings/bytes using Base32 format. <base32>
hints.py - Contains type hint definitions across modules in the package. <hints>
ulid.py - Object representation of a ULID. <ulid>
36 changes: 36 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
set SPHINXPROJ=ulid

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
3 changes: 3 additions & 0 deletions docs/ulid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: ulid.ulid
:members:
:inherited-members:
8 changes: 8 additions & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ulid/requirements/docs.txt
#
# Requirements for generating package documentation.

-r base.txt

sphinx==1.5.2
sphinx_rtd_theme
34 changes: 17 additions & 17 deletions ulid/base32.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Functionality for encoding/decoding ULID strings/bytes using Base32 format.

.. note:: This module makes the trade-off of code duplication for inline
computations over multiple function calls for performance reasons. I'll
check metrics in the future to see how much it helps and if it's worth
it to maintain.
computations over multiple function calls for performance reasons. I'll
check metrics in the future to see how much it helps and if it's worth
it to maintain.

`Base32 Documentation <http://www.crockford.com/wrmg/base32.html>`
`NUlid Project <https://github.com/RobThree/NUlid>`
* `Base32 Documentation <http://www.crockford.com/wrmg/base32.html>`
* `NUlid Project <https://github.com/RobThree/NUlid>`
"""
import array

Expand Down Expand Up @@ -58,9 +58,9 @@ def encode(value: hints.Buffer) -> str:
Encode the given :class:`~bytes` instance to a :class:`~str` using Base32 encoding.

.. note:: You should only use this method if you've got a :class:`~bytes` instance
and you are unsure of what it represents. If you know the the _meaning_ of the
:class:`~bytes` instance, you should call the `encode_*` method explicitly for
better performance.
and you are unsure of what it represents. If you know the the _meaning_ of the
:class:`~bytes` instance, you should call the `encode_*` method explicitly for
better performance.

:param value: Bytes to encode
:type value: :class:`~bytes`, :class:`~bytearray`, or :class:`~memoryview`
Expand All @@ -86,7 +86,7 @@ def encode_ulid(value: hints.Buffer) -> str:
Encode the given buffer to a :class:`~str` using Base32 encoding.

.. note:: This uses an optimized strategy from the `NUlid` project for encoding ULID
bytes specifically and is not meant for arbitrary encoding.
bytes specifically and is not meant for arbitrary encoding.

:param value: Bytes to encode
:type value: :class:`~bytes`, :class:`~bytearray`, or :class:`~memoryview`
Expand Down Expand Up @@ -137,7 +137,7 @@ def encode_timestamp(timestamp: hints.Buffer) -> str:
are a timestamp in milliseconds.

.. note:: This uses an optimized strategy from the `NUlid` project for encoding ULID
bytes specifically and is not meant for arbitrary encoding.
bytes specifically and is not meant for arbitrary encoding.

:param timestamp: Bytes to encode
:type timestamp: :class:`~bytes`, :class:`~bytearray`, or :class:`~memoryview`
Expand Down Expand Up @@ -172,7 +172,7 @@ def encode_randomness(randomness: hints.Buffer) -> str:
are cryptographically secure random values.

.. note:: This uses an optimized strategy from the `NUlid` project for encoding ULID
bytes specifically and is not meant for arbitrary encoding.
bytes specifically and is not meant for arbitrary encoding.

:param randomness: Bytes to encode
:type randomness: :class:`~bytes`, :class:`~bytearray`, or :class:`~memoryview`
Expand Down Expand Up @@ -210,9 +210,9 @@ def decode(value: str) -> bytes:
Decode the given Base32 encoded :class:`~str` instance to :class:`~bytes`.

.. note:: You should only use this method if you've got a :class:`~str` instance
and you are unsure of what it represents. If you know the the _meaning_ of the
:class:`~str` instance, you should call the `decode_*` method explicitly for
better performance.
and you are unsure of what it represents. If you know the the _meaning_ of the
:class:`~str` instance, you should call the `decode_*` method explicitly for
better performance.

:param value: String to decode
:type value: :class:`~str`
Expand All @@ -239,7 +239,7 @@ def decode_ulid(value: str) -> bytes:
Decode the given Base32 encoded :class:`~str` instance to :class:`~bytes`.

.. note:: This uses an optimized strategy from the `NUlid` project for decoding ULID
strings specifically and is not meant for arbitrary decoding.
strings specifically and is not meant for arbitrary decoding.

:param value: String to decode
:type value: :class:`~str`
Expand Down Expand Up @@ -287,7 +287,7 @@ def decode_timestamp(timestamp: str) -> bytes:
are the timestamp in milliseconds.

.. note:: This uses an optimized strategy from the `NUlid` project for decoding ULID
strings specifically and is not meant for arbitrary decoding.
strings specifically and is not meant for arbitrary decoding.

:param timestamp: String to decode
:type timestamp: :class:`~str`
Expand Down Expand Up @@ -325,7 +325,7 @@ def decode_randomness(randomness: str) -> bytes:
are cryptographically secure random values.

.. note:: This uses an optimized strategy from the `NUlid` project for decoding ULID
strings specifically and is not meant for arbitrary decoding.
strings specifically and is not meant for arbitrary decoding.

:param randomness: String to decode
:type randomness: :class:`~str`
Expand Down