Skip to content

Commit 6b97b48

Browse files
committed
Added docstrings to most of the important modules, and included a few more modules in the api .rst files
1 parent 8066970 commit 6b97b48

File tree

15 files changed

+98
-6
lines changed

15 files changed

+98
-6
lines changed

bookmarks/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Django admin interface for `~bookmarks.models.Bookmark`.
2+
"""
3+
14
from django.contrib import admin
25
from bookmarks.models import Bookmark
36

bookmarks/views.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,34 @@ def bookmark_list(request, queryset=Bookmark.objects.all()):
1717

1818
@login_required
1919
def user_bookmark_list(request):
20+
"""Show a list of the current user's bookmarks.
21+
"""
2022
queryset = Bookmark.objects.all()
2123
queryset = queryset.filter(user=request.user)
2224
return bookmark_list(request, queryset=queryset)
2325

2426
@login_required
2527
def bookmark_add(request, url):
28+
"""Add a new bookmark for the current user to ``url``.
29+
"""
2630
bookmark, _ = Bookmark.objects.get_or_create(user=request.user, url=url)
27-
31+
2832
payload = simplejson.dumps({'added': True})
29-
33+
3034
return HttpResponse(payload, mimetype='text/javascript')
3135

3236
@login_required
3337
def bookmark_remove(request, url):
38+
"""Remove the current user's bookmark to ``url``.
39+
"""
3440
try:
3541
bookmark = Bookmark.objects.get(user=request.user, url=url)
3642
except Bookmark.DoesNotExist:
3743
pass
3844
else:
3945
bookmark.delete()
40-
46+
4147
payload = simplejson.dumps({'removed': True})
42-
48+
4349
return HttpResponse(payload, mimetype='text/javascript')
50+

builds/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Django admin interface for `~builds.models.Build` and related models.
2+
"""
3+
14
from django.contrib import admin
25
from builds.models import Build
36

builds/views.py

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from taggit.models import Tag
1010

1111
def build_list(request, username=None, project_slug=None, tag=None):
12+
"""Show a list of builds.
13+
"""
1214
queryset = Build.objects.all()
1315
if username:
1416
user = get_object_or_404(User, username=username)
@@ -35,7 +37,10 @@ def build_list(request, username=None, project_slug=None, tag=None):
3537
template_object_name='build',
3638
)
3739

40+
3841
def build_detail(request, username, project_slug, pk):
42+
"""Show the details of a particular build.
43+
"""
3944
user = get_object_or_404(User, username=username)
4045
queryset = Build.objects.all()
4146

@@ -52,3 +57,4 @@ def build_detail(request, username, project_slug, pk):
5257
extra_context={'user': user, 'project': project },
5358
template_object_name='build',
5459
)
60+

core/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Django admin interface for core models.
2+
"""
3+
14
from django.contrib import admin
25

36
from core.models import UserProfile

core/management/commands/update_repos.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from projects.models import Project
44

55
class Command(BaseCommand):
6-
6+
"""Custom management command to rebuild documentation for all projects on
7+
the site. Invoked via ``./manage.py update_repos``.
8+
"""
79
def handle(self, *args, **kwargs):
810
if not len(args):
911
tasks.update_docs_pull()

core/views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Core views, including the main homepage, post-commit build hook,
2+
documentation and header rendering, and server errors.
3+
"""
4+
15
from django.conf import settings
26
from django.db.models import F, Max
37
from django.http import HttpResponse, HttpResponseRedirect
@@ -58,7 +62,7 @@ def serve_docs(request, username, project_slug, filename):
5862
The way that we're serving the documentation.
5963
6064
This is coming out of Django so that we can do simple page counting, and
61-
because later we can use Django auth to protect views.
65+
because later we can use Django auth to protect views.
6266
6367
This could probably be refactored to serve out of nginx if we have more
6468
time.

docs/api/core.rst

+11
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@
3131
.. automodule:: core.views
3232
:members:
3333

34+
35+
:mod:`core.management.commands`
36+
----------------------------------
37+
This is where custom ``manage.py`` commands are defined.
38+
39+
.. automodule:: core.management.commands.build_files
40+
:members:
41+
42+
.. automodule:: core.management.commands.update_repos
43+
:members:
44+

docs/api/index.rst

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
API
22
===
33

4+
This is the Read The Docs API documentation, autogenerated from the source
5+
code.
6+
47
.. toctree::
58

69
bookmarks

docs/api/projects.rst

+13
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@
3636
.. automodule:: projects.utils
3737
:members:
3838

39+
:mod:`projects.views`
40+
----------------------------------
41+
42+
:mod:`projects.views.public`
43+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
.. automodule:: projects.views.public
45+
:members:
46+
47+
:mod:`projects.views.private`
48+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
.. automodule:: projects.views.private
50+
:members:
51+

projects/admin.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Django administration interface for `~projects.models.Project`
2+
and related models.
3+
"""
4+
15
from django.contrib import admin
26

37
from projects.models import Project, File, ImportedFile

projects/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Default values and other various configuration for projects,
2+
including available theme names and repository types.
3+
"""
4+
15
THEME_DEFAULT = 'default'
26
THEME_SPHINX = 'sphinxdoc'
37
THEME_SCROLLS = 'scrolls'

projects/tasks.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Tasks related to projects, including fetching repository code, cleaning
2+
``conf.py`` files, and rebuilding documentation.
3+
"""
4+
15
from celery.decorators import task
26
from celery.task.schedules import crontab
37
from celery.decorators import periodic_task
@@ -21,6 +25,7 @@ class ProjectImportError (Exception):
2125
"""Failure to import a project from a repository."""
2226
pass
2327

28+
2429
@task
2530
def update_docs(pk, record=True):
2631
"""
@@ -119,6 +124,9 @@ def update_imported_docs(project):
119124

120125

121126
def scrape_conf_file(project):
127+
"""Locate the given project's ``conf.py`` file and extract important
128+
settings, including copyright, theme, source suffix and version.
129+
"""
122130
try:
123131
conf_dir = project.find('conf.py')[0]
124132
except IndexError:
@@ -200,8 +208,11 @@ def fileify(project_slug):
200208
file, new = ImportedFile.objects.get_or_create(project=project,
201209
path=dirpath,
202210
name=filename)
211+
212+
203213
@periodic_task(run_every=crontab(hour="*", minute="10", day_of_week="*"))
204214
def update_docs_pull():
205215
for project in Project.objects.live():
206216
print "Building %s" % project
207217
update_docs(pk=project.pk, record=False)
218+

projects/utils.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Utility functions used by projects.
2+
"""
3+
14
import subprocess
25
import os
36
import fnmatch
@@ -8,13 +11,18 @@
811

912
from projects.libs.diff_match_patch import diff_match_patch
1013

14+
1115
def find_file(file):
16+
"""Find matching filenames in the current directory and its subdirectories,
17+
and return a list of matching filenames.
18+
"""
1219
matches = []
1320
for root, dirnames, filenames in os.walk('.'):
1421
for filename in fnmatch.filter(filenames, file):
1522
matches.append(os.path.join(root, filename))
1623
return matches
1724

25+
1826
def run(*commands):
1927
"""
2028
Run one or more commands, and return ``(status, out, err)``.
@@ -58,14 +66,20 @@ def diff(txt1, txt2):
5866
patch = dmp.patch_make(txt1, txt2)
5967
return dmp.patch_toText(patch)
6068

69+
6170
def safe_write(filename, contents):
71+
"""Write ``contents`` to the given ``filename``. If the filename's
72+
directory does not exist, it is created. Contents are written as UTF-8,
73+
ignoring any characters that cannot be encoded as UTF-8.
74+
"""
6275
dirname = os.path.dirname(filename)
6376
if not os.path.exists(dirname):
6477
os.makedirs(dirname)
6578
fh = open(filename, 'w')
6679
fh.write(contents.encode('utf-8', 'ignore'))
6780
fh.close()
6881

82+
6983
def sanitize_conf(conf_filename):
7084
"""Modify the given ``conf.py`` file from a whitelisted project. For now,
7185
this just adds the RTD template directory to ``templates_path``.
@@ -93,3 +107,4 @@ def sanitize_conf(conf_filename):
93107
outfile.write(line)
94108
outfile.close()
95109
return lines_matched
110+

watching/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Django admin interface for `~watching.models.PageView`.
2+
"""
3+
14
from watching.models import PageView
25
from django.contrib import admin
36

0 commit comments

Comments
 (0)