Skip to content
This repository

sphinxext returns empty apidocs #52

Closed
WouterVH opened this Issue · 2 comments

2 participants

Wouter Vanden Hove Alexis Metaireau
Wouter Vanden Hove

I've tried various ways the get the sphinx-extension working, but nothing seems working.
In the following I can reproduce all the steps I've taken:

  • install cornice in a 2.7-virtualenv,
  • generate sphinx-docs with the sphinx-quickstarter,
  • add the cornice-directive in conf.py and
  • use this directive in a document.

the result is an empty block where I expect the autogenerated API

wouter@midgard: /opt/dev/sandbox-cornice > bin/sphinx-quickstart
Welcome to the Sphinx 1.1.3 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Enter the root path for documentation.

Root path for the documentation [.]: docs

You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.

Separate source and build directories (y/N) [n]: n

Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.

Name prefix for templates and static dir [_]:

The project name will occur in several places in the built documentation.

Project name: Demo
Author name(s): Wouter

Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1. If you don't need this dual structure,
just set both to the same value.

Project version: 0.1
Project release [0.1]: 0.1

The file name suffix for source files. Commonly, this is either ".txt"
or ".rst". Only files with this suffix are considered documents.

Source file suffix [.rst]:

One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.

Name of your master document (without suffix) [index]:

Sphinx can also add configuration for epub output:

Do you want to use the epub builder (y/N) [n]:

Please indicate if you want to use one of the following Sphinx extensions:

autodoc: automatically insert docstrings from modules (y/N) [n]:
doctest: automatically test code snippets in doctest blocks (y/N) [n]:
intersphinx: link between Sphinx documentation of different projects (y/N) [n]:
todo: write "todo" entries that can be shown or hidden on build (y/N) [n]:
coverage: checks for documentation coverage (y/N) [n]:
pngmath: include math, rendered as PNG images (y/N) [n]:
mathjax: include math, rendered in the browser by MathJax (y/N) [n]:
ifconfig: conditional inclusion of content based on config values (y/N) [n]:
viewcode: include links to the source code of documented Python objects (y/N) [n]:

A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.

Create Makefile? (Y/n) [y]:
Create Windows command file? (Y/n) [y]: n

Creating file docs/conf.py.
Creating file docs/index.rst.
Creating file docs/Makefile.

Finished: An initial directory structure has been created.

You should now populate your master file docs/index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.

wouter@midgard: /opt/dev/sandbox-cornice >

vi Makefile # so we don"t have to activate thevirtual environment
SPHINXBUILD = /opt/dev/sandbox-cornice/bin/sphinx-build

vi conf.py

>>> import cornice
>>> sys.path.insert(0, os.path.abspath(cornice.__file__))
>>> extensions = ['cornice.sphinxext']

vi index.rst

.. services::
:package: cornice.tests.validationapp

make html

the results:

cornice is found, includeme is run, add_apidoc is indeed called,
but apidocs in _get_services is returning an empty dict

def _get_services(self, package, ignore):
    from pyramid.config import Configurator
    conf = Configurator()
    conf.include('cornice')
    conf.scan(package, ignore=ignore)
    by_service = defaultdict(dict)
    apidocs = conf.registry.settings.get('apidocs', {})   <-- this is always an empty dict

I don't see what I'm missing here.

However creating an application and getting the apidoc from the request does not have this problem:

cd /opt/dev/sandbox-cornice
bin/paster create --t cornice demo
Enter appname (Application name) ['']: Demo
Enter description (One-line description of the project) ['']: Demo
Enter author (Author name) ['']: Wouter

cd demo
/opt/dev/sandbox-cornice/bin/python setup.py develop
/opt/dev/sandbox-cornice/bin/paster serve demo.ini
--> no problems running the application

vi demo/views.py
9 @hello.get()
10 def get_info(request):
11 """Returns Hello in JSON."""
12 print 'APIDOC: ', request.registry.settings.get('apidocs')
13 return {'Hello': 'World'}
~

/opt/dev/sandbox-cornice/bin/paster serve demo.ini

APIDOC:
{('/', 'GET'): {'filters': [], 'service': , 'request_method': 'GET', 'renderer': 'simplejson', 'func': , 'validators': []}}

Wouter Vanden Hove

It seems the directive is broken too on RTD.
http://cornice.readthedocs.org/en/latest/exampledoc.html
However, I did see this functioning there.

Alexis Metaireau
Owner

I fixed this in the latest release. Feel free to open if it's not working for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.