Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Use docstring & doctest #108

Open
wants to merge 2 commits into
base: week06
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions week06/average-squares-example/average_squares/squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def average_of_squares(list_of_numbers, list_of_weights=None):
for number, weight
in zip(list_of_numbers, effective_weights)
]
return sum(squares)
return sum(squares)/len(list_of_numbers)


def convert_numbers(list_of_strings):
Expand All @@ -38,7 +38,7 @@ def convert_numbers(list_of_strings):
Example:
--------
>>> convert_numbers(["4", " 8 ", "15 16", " 23 42 "])
[4, 8, 15, 16]
[4.0, 8.0, 15.0, 16.0, 23.0, 42.0]

"""
all_numbers = []
Expand Down
20 changes: 20 additions & 0 deletions week06/average-squares-example/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, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Average Squares Documentation
=============================

.. automodule:: squares
:members:
55 changes: 55 additions & 0 deletions week06/average-squares-example/docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- 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 = 'squares'
copyright = '2020, Danqing'
author = 'Danqing'

# The full version, including alpha/beta/rc tags
release = '0.1'


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

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

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# 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 = []


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

# 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']
24 changes: 24 additions & 0 deletions week06/average-squares-example/docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. squares documentation master file, created by
sphinx-quickstart on Tue Nov 17 02:39:10 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to squares's documentation!
===================================

This project is designed to calculate the weighted average of squares.

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

Average Squares Documentation <average-squares-docs.rst>


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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`