Merge pull request #19 from rtfd/add-python3

Fix up python 3 support.
This commit is contained in:
Eric Holscher 2015-08-05 10:29:41 -07:00
commit f7621c9bac
8 changed files with 37 additions and 32 deletions

View File

@ -102,7 +102,7 @@ Read more about the deisgn in our :doc:`design`.
Currently Implemented
---------------------
* Python
* Python (2 only -- Epydoc doesn't support Python 3)
* .Net
* Go
* Javascript

View File

@ -235,7 +235,7 @@ class SphinxMapperBase(object):
detail_dir = os.path.join(root, *filename.split('.'))
ensuredir(detail_dir)
path = os.path.join(detail_dir, '%s%s' % ('index', source_suffix))
with open(path, 'w+') as detail_file:
with open(path, 'wb+') as detail_file:
detail_file.write(rst.encode('utf-8'))
# Render Top Index

View File

@ -30,7 +30,10 @@ class DotNetSphinxMapper(SphinxMapperBase):
'''
raise_error = kwargs.get('raise_error', True)
all_files = list(self.find_files(patterns=patterns, dir=dir, ignore=ignore))
all_files = set()
for _file in self.find_files(patterns=patterns, dir=dir, ignore=ignore):
# Iterating for Sphinx output clarify
all_files.add(_file)
if all_files:
try:
command = ['docfx', 'metadata', '--raw', '--force']
@ -155,7 +158,7 @@ class DotNetSphinxMapper(SphinxMapperBase):
_recurse_ns(obj)
# Clean out dead namespaces
for key, ns in self.top_namespaces.items():
for key, ns in self.top_namespaces.copy().items():
if len(ns.children) == 0:
del self.top_namespaces[key]
@ -181,14 +184,14 @@ class DotNetSphinxMapper(SphinxMapperBase):
detail_dir = os.path.join(root, *filename.split('.'))
ensuredir(detail_dir)
path = os.path.join(detail_dir, '%s%s' % ('index', source_suffix))
with open(path, 'w+') as detail_file:
with open(path, 'wb+') as detail_file:
detail_file.write(rst.encode('utf-8'))
# Render Top Index
top_level_index = os.path.join(root, 'index.rst')
with open(top_level_index, 'w+') as top_level_file:
with open(top_level_index, 'wb+') as top_level_file:
content = self.jinja_env.get_template('index.rst')
top_level_file.write(content.render(pages=self.namespaces.values()))
top_level_file.write(content.render(pages=self.namespaces.values()).encode('utf-8'))
@staticmethod
def build_finished(app, exception):

View File

@ -1,9 +1,16 @@
from collections import defaultdict
from epyparse import parsed
import sys
from .base import PythonMapperBase, SphinxMapperBase
if sys.version_info < (3,):
from epyparse import parsed
else:
# Don't raise exception on module level because it would
# break all backends on Python 3
def parsed(path):
raise Exception('Python 3 not supported')
class PythonSphinxMapper(SphinxMapperBase):
@ -19,8 +26,6 @@ class PythonSphinxMapper(SphinxMapperBase):
:param path: Path of file to read
'''
# TODO support JSON here
# TODO sphinx way of reporting errors in logs?
try:
parsed_data = parsed(path)

View File

@ -5,8 +5,4 @@ It also depends on the sphinxcontrib-dotnet domain: https://github.com/rtfd/sphi
Currently this is setup to build the Indentity repo from ASP.Net
We don't have the checkout in the repo,
but there's a ``clone.sh`` in the ``example`` directory which will clone it properly.
Then you should simply be able to run ``make html`` in this directory.
You should simply be able to run ``make html`` in this directory.

View File

@ -1,7 +1,6 @@
'''Test .NET autoapi domain'''
import unittest
from contextlib import nested
from mock import patch
@ -67,6 +66,7 @@ class DomainTests(unittest.TestCase):
self.assertIsInstance(cls, dotnet.DotNetClass)
self.assertDictEqual(cls.item_map, {})
@patch('subprocess.check_output', lambda foo: foo)
def test_get_objects(self):
'''Test basic get objects'''
objs = []
@ -79,11 +79,8 @@ class DomainTests(unittest.TestCase):
{'id': 'Foo.Bar2', 'name': 'Bar', 'type': 'property'}],
'id': 'Foo.Bar', 'type': 'Class', 'summary': path}
with nested(
patch('autoapi.mappers.dotnet.DotNetSphinxMapper.find_files', _mock_find),
patch('autoapi.mappers.dotnet.DotNetSphinxMapper.read_file', _mock_read),
patch('subprocess.check_output', lambda foo: foo),
):
with patch('autoapi.mappers.dotnet.DotNetSphinxMapper.find_files', _mock_find):
with patch('autoapi.mappers.dotnet.DotNetSphinxMapper.read_file', _mock_read):
dom = dotnet.DotNetSphinxMapper(self.application)
dom.load('', '', '', raise_error=False)
dom.map()

View File

@ -1,5 +1,6 @@
import json
import os
import sys
import shutil
import unittest
@ -59,6 +60,7 @@ class GoTests(LanguageIntegrationTests):
class PythonTests(LanguageIntegrationTests):
@unittest.skipIf(sys.version_info > (3, 0), 'Epydoc does not support Python 3')
def test_integration(self):
self._run_test(
'pyexample',
@ -94,6 +96,7 @@ class DotNetTests(LanguageIntegrationTests):
class IntegrationTests(LanguageIntegrationTests):
@unittest.skipIf(sys.version_info > (3, 0), 'Epydoc does not support Python 3')
def test_template_overrides(self):
self._run_test(
'templateexample',
@ -104,6 +107,7 @@ class IntegrationTests(LanguageIntegrationTests):
class TOCTreeTests(LanguageIntegrationTests):
@unittest.skipIf(sys.version_info > (3, 0), 'Epydoc does not support Python 3')
def test_toctree_overrides(self):
self._run_test(
'toctreeexample',

View File

@ -1,5 +1,5 @@
[tox]
envlist = py27,lint,docs
envlist = py27,py34,lint,docs
[testenv]
setenv =