Skip to content

Commit

Permalink
Preparing for API documentation on Read The Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 19, 2015
1 parent 23460dc commit f44d759
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 21 deletions.
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Makefile for rotate-backups
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: July 19, 2015
# URL: https://github.com/xolox/python-rotate-backups

WORKON_HOME ?= $(HOME)/.virtualenvs
VIRTUAL_ENV ?= $(WORKON_HOME)/rotate-backups
ACTIVATE = . $(VIRTUAL_ENV)/bin/activate

default:
@echo 'Makefile for rotate-backups'
@echo
@echo 'Usage:'
@echo
@echo ' make install install the package in a virtual environment'
@echo ' make reset recreate the virtual environment'
@echo ' make test run the test suite'
@echo ' make coverage run the tests, report coverage'
@echo ' make docs update documentation using Sphinx'
@echo ' make publish publish changes to GitHub/PyPI'
@echo ' make clean cleanup all temporary files'
@echo

install:
test -d "$(VIRTUAL_ENV)" || virtualenv "$(VIRTUAL_ENV)"
test -x "$(VIRTUAL_ENV)/bin/pip" || ($(ACTIVATE) && easy_install pip)
test -x "$(VIRTUAL_ENV)/bin/pip-accel" || ($(ACTIVATE) && pip install pip-accel)
$(ACTIVATE) && pip uninstall -y rotate-backups >/dev/null 2>&1 || true
$(ACTIVATE) && pip install --quiet --editable .

reset:
rm -Rf "$(VIRTUAL_ENV)"
make --no-print-directory clean install

test: install
test -x "$(VIRTUAL_ENV)/bin/py.test" || ($(ACTIVATE) && pip-accel install pytest)
$(ACTIVATE) && py.test -v
$(ACTIVATE) && make coverage
test -x "$(VIRTUAL_ENV)/bin/tox" || ($(ACTIVATE) && pip-accel install tox)
$(ACTIVATE) && tox

coverage: install
$(ACTIVATE) && pip-accel install coverage
$(ACTIVATE) && coverage run setup.py test
$(ACTIVATE) && coverage report
$(ACTIVATE) && coverage html

readme:
test -x "$(VIRTUAL_ENV)/bin/cog.py" || ($(ACTIVATE) && pip-accel install cogapp)
$(ACTIVATE) && cog.py -r README.rst

docs: install
test -x "$(VIRTUAL_ENV)/bin/sphinx-build" || ($(ACTIVATE) && pip-accel install sphinx)
$(ACTIVATE) && cd docs && sphinx-build -b html -d build/doctrees . build/html

publish:
git push origin && git push --tags origin
make clean && python setup.py sdist upload

clean:
rm -Rf *.egg *.egg-info .coverage build dist docs/build htmlcov
find -depth -type d -name __pycache__ -exec rm -Rf {} \;
find -type f -name '*.pyc' -delete

.PHONY: default install reset test coverage docs publish clean
76 changes: 76 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
#
# documentation build configuration file for the 'rotate-backups' package. This
# file is execfile()d with the current directory set to its containing dir.

import os
import sys

# Add the 'rotate-backups' source distribution's root directory to the module path.
sys.path.insert(0, os.path.abspath('..'))

# -- General configuration -----------------------------------------------------

# Sphinx extension module names.
extensions = ['sphinx.ext.doctest', 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx']

# Paths that contain templates, relative to this directory.
templates_path = ['templates']

# The suffix of source filenames.
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'rotate-backups'
copyright = u'2015, Peter Odding'

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

# Find the package version and make it the release.
from rotate_backups import __version__ as rotate_backups_version

# The short X.Y version.
version = '.'.join(rotate_backups_version.split('.')[:2])

# The full version, including alpha/beta/rc tags.
release = rotate_backups_version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['build']

# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True

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

# Refer to the Python standard library.
# From: http://twistedmatrix.com/trac/ticket/4582.
intersphinx_mapping = {
'python': ('http://docs.python.org', None),
}

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

# Output file base name for HTML help builder.
htmlhelp_basename = 'rotatebackupsdoc'


def setup(app):
# Based on http://stackoverflow.com/a/5599712/788200.
app.connect('autodoc-skip-member', (lambda app, what, name, obj, skip, options:
False if name == '__init__' and obj.__doc__ else skip))
16 changes: 16 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. include:: ../README.rst

API documentation
=================

This documentation is based on the source code of version |release| of the
`rotate-backups` package. The following modules are available:

.. contents::
:local:

:mod:`rotate_backups`
---------------------

.. automodule:: rotate_backups
:members:
46 changes: 25 additions & 21 deletions rotate_backups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
# Last Change: July 19, 2015
# URL: https://github.com/xolox/python-rotate-backups

"""
Usage: rotate-backups [OPTIONS] DIRECTORY..
Supported options:
-H, --hourly=NUM how many hourly backups to preserve
-d, --daily=NUM how many daily backups to preserve
-w, --weekly=NUM how many weekly backups to preserve
-m, --monthly=NUM how many monthly backups to preserve
-y, --yearly=NUM how many yearly backups to preserve
-i, --ionice=CLASS use ionice to set the I/O scheduling class
-n, --dry-run don't make any changes, just print what would be done
-v, --verbose make more noise
-h, --help show this message and exit
"""

# Semi-standard module versioning.
__version__ = '0.1.2'

Expand Down Expand Up @@ -69,11 +53,24 @@ def rotate_backups(directory, rotation_scheme, dry_run=False, io_scheduling_clas
:param directory: The directory containing the backups (a string).
:param rotation_scheme: A dictionary with one or more of the keys 'hourly',
'daily', 'weekly', 'monthly', 'yearly' and integer
values.
'daily', 'weekly', 'monthly', 'yearly'. Each key is
expected to have one of the following values:
- An integer gives the number of backups in the
corresponding category to preserve, starting from
the most recent backup and counting back in
time.
- The string 'always' means all backups in the
corresponding category are preserved (useful for
the biggest time unit in the rotation scheme).
By default no backups are preserved for categories
(keys) not present in the dictionary.
:param dry_run: If this is ``True`` then no changes will be made, which
provides a 'preview' of the effect of the rotation scheme
(the default is ``False``).
(the default is ``False``). Right now this is only useful
in the command line interface because there's no return
value.
:param io_scheduling_class: Use ``ionice`` to set the I/O scheduling class
(expected to be one of the strings 'idle',
'best-effort' or 'realtime').
Expand Down Expand Up @@ -152,15 +149,22 @@ def rotate_backups(directory, rotation_scheme, dry_run=False, io_scheduling_clas
@functools.total_ordering
class Backup(object):

""":py:class:`Backup` objects represent a rotation subject."""
"""
:py:class:`Backup` objects represent a rotation subject.
In addition to the :attr:`type` and :attr:`week` properties :class:`Backup`
objects support all of the attributes of :py:class:`~datetime.datetime`
objects by deferring attribute access for unknown attributes to the
:py:class:`~datetime.datetime` object given to the constructor.
"""

def __init__(self, pathname, datetime):
"""
Initialize a :py:class:`Backup` object.
:param pathname: The filename of the backup (a string).
:param datetime: The date/time when the backup was created (a
:py:class:`datetime.datetime` object).
:py:class:`~datetime.datetime` object).
"""
self.pathname = pathname
self.datetime = datetime
Expand Down

0 comments on commit f44d759

Please sign in to comment.