Skip to content

Commit

Permalink
Let sphinx generate docstring documentation (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo committed Jul 3, 2018
1 parent f6ae433 commit 46c1208
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 56 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

Process Firefox versions numbers. Tell whether they are valid or not, whether they are nightlies or regular releases, whether this version precedes that other.

## Documentation

https://mozilla-version.readthedocs.io/en/latest/

## Get the code

Just install it from pip:
Expand Down
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 = mozilla-version
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)
1 change: 1 addition & 0 deletions docs/README.md
191 changes: 191 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# -*- coding: utf-8 -*-
#
# mozilla-version documentation build configuration file, created by
# sphinx-quickstart on Tue Jul 3 10:24:35 2018.
#
# 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.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))


# -- Project information -----------------------------------------------------

project = 'mozilla-version'
copyright = '2018, Mozilla Release Engineering'
author = 'Mozilla Release Engineering'

with open("../version.txt") as filehandle:
# The short X.Y version
version = filehandle.read()
# The full version, including alpha/beta/rc tags
release = version


# -- 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.napoleon',
'sphinx.ext.doctest',
'm2r',
]

# Napoleon settings
napoleon_google_docstring = True
napoleon_numpy_docstring = False
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True

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

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

# 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.
#
# html_theme_options = {}

# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
html_title = '{} {}'.format(project, release)

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

# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
html_last_updated_fmt = '%Y-%m-%d'

# 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 = 'mozilla-versiondoc'


# -- 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, 'mozilla-version.tex', 'mozilla-version Documentation',
'Mozilla Release Engineering', '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, 'mozilla-version', 'mozilla-version 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, 'mozilla-version', 'mozilla-version Documentation',
author, 'mozilla-version', 'One line description of project.',
'Miscellaneous'),
]


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
24 changes: 24 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. mozilla-version documentation master file, created by
sphinx-quickstart on Tue Jul 3 10:26:11 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to mozilla-version's documentation!
===========================================

.. mdinclude:: README.md

.. toctree::
:maxdepth: 2
:caption: Contents:

mozilla_version



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
31 changes: 31 additions & 0 deletions docs/mozilla_version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mozilla_version package
=======================

Submodules
----------

mozilla_version.firefox module
------------------------------

.. automodule:: mozilla_version.firefox
:members:
:undoc-members:
:show-inheritance:


mozilla_version.version module
------------------------------

.. automodule:: mozilla_version.version
:members:
:undoc-members:
:show-inheritance:


mozilla_version.errors module
-----------------------------

.. automodule:: mozilla_version.errors
:members:
:undoc-members:
:show-inheritance:
38 changes: 19 additions & 19 deletions mozilla_version/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@


class InvalidVersionError(ValueError):
"""Error when `version_string` doesn't match the pattern of a valid version number."""
"""Error when `version_string` doesn't match the pattern of a valid version number.
def __init__(self, version_string):
"""Constructor.
Args:
version_string (str): The string it was unable to match.
"""

Args:
version_string (str): The string it was unable to match.
"""
def __init__(self, version_string):
"""Constructor."""
super(InvalidVersionError, self).__init__(
'Version "{}" does not match the pattern of a valid version'.format(version_string)
)


class NoVersionTypeError(ValueError):
"""Error when `version_string` matched the pattern, but was unable to find its type."""
"""Error when `version_string` matched the pattern, but was unable to find its type.
def __init__(self, version_string):
"""Constructor.
Args:
version_string (str): The string it was unable to guess the type.
"""

Args:
version_string (str): The string it was unable to guess the type.
"""
def __init__(self, version_string):
"""Constructor."""
super(NoVersionTypeError, self).__init__(
'Version "{}" matched the pattern of a valid version, but it is unable to find what type it is. \
This is likely a bug in mozilla-version'.format(version_string)
)


class MissingFieldError(ValueError):
"""Error when `version_string` lacks an expected field."""
"""Error when `version_string` lacks an expected field.
def __init__(self, version_string, field_name):
"""Constructor.
Args:
version_string (str): The string it was unable to extract a given field.
field_name (str): The name of the missing field.
"""

Args:
version_string (str): The string it was unable to extract a given field.
field_name (str): The name of the missing field.
"""
def __init__(self, version_string, field_name):
"""Constructor."""
super(MissingFieldError, self).__init__(
'Release "{}" does not contain a valid {}'.format(version_string, field_name)
)
Expand Down

0 comments on commit 46c1208

Please sign in to comment.