Commits

Stefan Scherfke committed dcb9dae

Flake8-ification.

Comments (0)

Files changed (9)

+# flake8: noqa
 # -*- coding: utf-8 -*-
 #
 # django-sphinxdoc documentation build configuration file, created by

sphinxdoc/admin.py

 Admin interface for the sphinxdoc app.
 
 """
-
 from django.contrib import admin
 
 from sphinxdoc.models import Project, Document
     """Admin interface for :class:`~sphinxdoc.models.Project`."""
     list_display = ('name', 'path',)
     prepopulated_fields = {'slug': ('name',)}
-    
+
 
 class DocumentAdmin(admin.ModelAdmin):
     """
     Admin interface for :class:`~sphinxdoc.models.Document`.
-    
+
     Normally, you shouldn’t need this, since you create new documents via
     the management command.
-    
+
     """
     pass
-    
+
 
 admin.site.register(Project, ProjectAdmin)
 admin.site.register(Document, DocumentAdmin)

sphinxdoc/forms.py

 Forms for the sphinxdoc app.
 
 """
-
 from haystack.forms import SearchForm
 from haystack.query import SearchQuerySet
 
 class ProjectSearchForm(SearchForm):
     """
     Custom search form for Haystack.
-    
-    It narrows the search query set to instances of 
+
+    It narrows the search query set to instances of
     :class:`~sphinxdoc.models.Document` that belong to the current
     :class:`~sphinxdoc.models.Project`.
-    
+
     """
     def __init__(self, *args, **kwargs):
         slug = kwargs.pop('slug')
         project = Project.objects.get(slug=slug)
         kwargs['searchqueryset'] = SearchQuerySet().models(Document).filter(
                 project=project.id)
-        
+
         SearchForm.__init__(self, *args, **kwargs)

sphinxdoc/management/commands/updatedoc.py

 Management command for updading the documentation of one or more projects.
 
 """
-
 import json
 import optparse
 import os
     """
     Update (and optionally build) the *Sphinx* documentation for one ore more
     projects.
-    
+
     You need to pass the slug of at least one project. If you pass the optional
     parameter ``-b``, the command ``sphinx-build`` will be run for each project
     before their files are read. If your project(s) are located in a different
     *virtualenv* than your django site, you can provide a path to its
-    interpreter with ``--virtualenv path/to/env/bin/`` 
-    
+    interpreter with ``--virtualenv path/to/env/bin/``
+
     """
     args = '[-b [--virtualenv <path/to/bin/>]] <project_slug project_slug ...>'
     help = ('Updates the documentation and the search index for the specified '
-            'projects.')    
+            'projects.')
     option_list = BaseCommand.option_list + (
         optparse.make_option('-b', '--build',
             action='store_true',
         optparse.make_option('--virtualenv',
             dest='virtualenv',
             default='',
-            help='Use this virtualenv to build project docs.'
+            help='Use this virtualenv to build project docs.',
         )
     )
 
-
     def handle(self, *args, **options):
         """
         Updates (and optionally builds) the documenation for all projects in
         ``args``.
-        
+
         """
         build = options['build']
         virtualenv = options['virtualenv']
-        
+
         for slug in args:
             try:
                 project = Project.objects.get(slug=slug)
             except Project.DoesNotExist:
                 raise CommandError('Project "%s" does not exist' % slug)
-            
+
             if build:
                 print 'Running "sphinx--build" for "%s" ...' % slug
                 self.build(project, virtualenv)
 
             print 'Importing JSON files for "%s" ...' % slug
             self.import_files(project)
-            
+
             print 'Updating search index for "%s" ...' % slug
             self.update_haystack()
-            
+
             print 'Done'
-            
+
     def build(self, project, virtualenv=''):
         """
-        Runs ``sphinx-build`` for ``project``. You can also specify a path to 
+        Runs ``sphinx-build`` for ``project``. You can also specify a path to
         the bin-directory of a ``virtualenv``, if your project requires it.
-        
+
         """
         cmd = 'sphinx-build'
         if virtualenv:
         ]
         print 'Executing %s' % ' '.join(cmd)
         subprocess.call(cmd)
-        
+
     def delete_documents(self, project):
         """Deletes all documents for ``project``."""
         Document.objects.filter(project=project).delete()
-        
+
     def import_files(self, project):
         """
         Creates a :class:`~sphinxdoc.models.Document` instance for each JSON
             for name in filter(lambda x: x.endswith(EXTENSION), filenames):
                 # Full path to the json file
                 filepath = os.path.join(dirpath, name)
-                
+
                 # Get path relative to the build dir w/o file extension
                 relpath = os.path.relpath(filepath, path)[:-len(EXTENSION)]
-                
+
                 # Some files have no title or body attribute
                 doc = json.load(open(filepath, 'rb'))
                 if 'title' not in doc:
                     doc['title'] = SPECIAL_TITLES[page_name]
                 if 'body' not in doc:
                     doc['body'] = ''
-                
+
                 # Finally create the Document
                 d = Document(
                     project=project,
                     path=relpath,
                     content=json.dumps(doc),
                     title=doc['title'],
-                    body=doc['body']
+                    body=doc['body'],
                 )
                 d.full_clean()
                 d.save()
-                
+
     def update_haystack(self):
         """Updates Haystack’s search index."""
         appname = __name__.split('.')[0]

sphinxdoc/models.py

 Models for django-sphinxdoc.
 
 """
-
 from django.db import models
 
 from sphinxdoc.validators import validate_isdir
     Represents a Sphinx project. Each ``Project`` has a name, a slug and a path
     to the root directory of a Sphinx project (where Sphinx’ ``conf.py``) is
     located).
-    
+
     """
     name = models.CharField(max_length=100)
     slug = models.SlugField(unique=True,
             help_text=u'Used in the URL for the project. Must be unique.')
     path = models.CharField(max_length=255, validators=[validate_isdir],
             help_text=u'Directory that contains Sphinx’ <tt>conf.py</tt>.')
-    
+
     def __unicode__(self):
         return self.name
 
     @models.permalink
     def get_absolute_url(self):
         return ('doc-index', (), {'slug': self.slug})
-        
+
 
 class Document(models.Model):
     """
     Represents a JSON encoded Sphinx document. The attributes ``title`` and
     ``body`` dubicate the corresponding keys in ``content`` and are used for
     the Haystack search.
-    
+
     """
     project = models.ForeignKey(Project)
     path = models.CharField(max_length=255)
     content = models.TextField()
     title = models.CharField(max_length=255)
     body = models.TextField(blank=True)
-    
+
     def __unicode__(self):
         return self.path
-        
+
     @models.permalink
     def get_absolute_url(self):
         return ('doc-detail', (), {
-            'slug': self.project.slug, 
+            'slug': self.project.slug,
             'path': self.path + '/',
         })

sphinxdoc/search_indexes.py

 Search indexes for Haystack.
 
 """
-
 from haystack import indexes, site
 
 from sphinxdoc.models import Document
 class DocumentIndex(indexes.SearchIndex):
     """
     Index for :class:`~sphinxdoc.models.Document`.
-    
+
     """
     text = indexes.CharField(document=True, use_template=True)
     title = indexes.CharField(model_attr='title')
     project = indexes.IntegerField(model_attr='project_id')
-    
+
     def get_queryset(self):
         """Used when the entire index for model is updated."""
         return Document.objects.all()

sphinxdoc/urls.py

 URL conf for django-sphinxdoc.
 
 """
-
 from django.conf.urls.defaults import patterns, url
 from django.views.generic import list_detail
 

sphinxdoc/validators.py

 Custom form validators for this app.
 
 """
-
 import os.path
 
 from django.core.exceptions import ValidationError

sphinxdoc/views.py

 Views for django-shinxdoc.
 
 """
-
 import datetime
 import json
 import os.path
 def documentation(request, slug, path):
     """
     Displays the contents of a :class:`sphinxdoc.models.Document`.
-    
+
     ``slug`` specifies the project, the document belongs to, ``path`` is the
     path to the original JSON file relative to the builddir and without the
     file extension. ``path`` may also be a directory, so this view checks if
     ``path/index`` exists, before trying to load ``path`` directly.
-    
+
     """
     project = get_object_or_404(Project, slug=slug)
     path = path.rstrip('/')
-    
+
     try:
         index = 'index' if path == '' else '%s/index' % path
         doc = Document.objects.get(project=project, path=index)
         'sphinxdoc/%s.html' % os.path.basename(path),
         'sphinxdoc/documentation.html',
     )
-    
+
     data = {
         'project': project,
         'doc': json.loads(doc.content),
         'env': json.load(open(
-                os.path.join(project.path, BUILDDIR, 
+                os.path.join(project.path, BUILDDIR,
                 'globalcontext.json'), 'rb')),
         'update_date':  datetime.datetime.fromtimestamp(
                 os.path.getmtime(os.path.join(project.path, BUILDDIR,
                 'last_build'))),
-        'search': urlresolvers.reverse('doc-search', kwargs={'slug':slug}),
+        'search': urlresolvers.reverse('doc-search', kwargs={'slug': slug}),
     }
-        
+
     return render_to_response(templates, data,
             context_instance=RequestContext(request))
 
+
 @cache_page(60 * CACHE_MINUTES)
 def objects_inventory(request, slug):
     """
     Renders the ``objects.inv`` as plain text.
-    
+
     """
     project = get_object_or_404(Project, slug=slug)
     response = serve(
-        request, 
-        document_root = project.path,
-        path = "objects.inv",
+        request,
+        document_root=project.path,
+        path='objects.inv',
     )
-    response['Content-Type'] = "text/plain"
+    response['Content-Type'] = 'text/plain'
     return response
 
+
 @cache_page(60 * CACHE_MINUTES)
 def images(request, slug, path):
     """
     Shows the specified image.
-    
+
     """
     project = get_object_or_404(Project, slug=slug)
     return serve(
-        request, 
-        document_root = os.path.join(project.path, BUILDDIR, '_images'),
-        path = path,
+        request,
+        document_root=os.path.join(project.path, BUILDDIR, '_images'),
+        path=path,
     )
-    
+
+
 @cache_page(60 * CACHE_MINUTES)
 def source(request, slug, path):
     """
     Shows the ReST source of a document.
-    
+
     """
     project = get_object_or_404(Project, slug=slug)
     return serve(
         request,
-        document_root = os.path.join(project.path, BUILDDIR, '_sources'),
-        path = path,
+        document_root=os.path.join(project.path, BUILDDIR, '_sources'),
+        path=path,
     )
-    
+
 
 class ProjectSearchView(SearchView):
     """
     Inherits :class:`SearchView` and handles a search request and displays the
     results as a simple list.
-    
+
     """
     def __init__(self):
         SearchView.__init__(self, form_class=ProjectSearchForm,
                 template='sphinxdoc/search.html')
-        
+
     def __call__(self, request, slug):
         self.slug = slug
         return SearchView.__call__(self, request)
-    
+
     def build_form(self):
         """
         Instantiates the form that should be used to process the search query.
-        
-        """        
+
+        """
         return self.form_class(self.request.GET, slug=self.slug,
                 searchqueryset=self.searchqueryset, load_all=self.load_all)