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 Currently Implemented
--------------------- ---------------------
* Python * Python (2 only -- Epydoc doesn't support Python 3)
* .Net * .Net
* Go * Go
* Javascript * Javascript

View File

@ -235,7 +235,7 @@ class SphinxMapperBase(object):
detail_dir = os.path.join(root, *filename.split('.')) detail_dir = os.path.join(root, *filename.split('.'))
ensuredir(detail_dir) ensuredir(detail_dir)
path = os.path.join(detail_dir, '%s%s' % ('index', source_suffix)) 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')) detail_file.write(rst.encode('utf-8'))
# Render Top Index # Render Top Index

View File

@ -30,7 +30,10 @@ class DotNetSphinxMapper(SphinxMapperBase):
''' '''
raise_error = kwargs.get('raise_error', True) 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: if all_files:
try: try:
command = ['docfx', 'metadata', '--raw', '--force'] command = ['docfx', 'metadata', '--raw', '--force']
@ -155,7 +158,7 @@ class DotNetSphinxMapper(SphinxMapperBase):
_recurse_ns(obj) _recurse_ns(obj)
# Clean out dead namespaces # 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: if len(ns.children) == 0:
del self.top_namespaces[key] del self.top_namespaces[key]
@ -181,14 +184,14 @@ class DotNetSphinxMapper(SphinxMapperBase):
detail_dir = os.path.join(root, *filename.split('.')) detail_dir = os.path.join(root, *filename.split('.'))
ensuredir(detail_dir) ensuredir(detail_dir)
path = os.path.join(detail_dir, '%s%s' % ('index', source_suffix)) 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')) detail_file.write(rst.encode('utf-8'))
# Render Top Index # Render Top Index
top_level_index = os.path.join(root, 'index.rst') 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') 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 @staticmethod
def build_finished(app, exception): def build_finished(app, exception):

View File

@ -1,9 +1,16 @@
from collections import defaultdict from collections import defaultdict
import sys
from epyparse import parsed
from .base import PythonMapperBase, SphinxMapperBase 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): class PythonSphinxMapper(SphinxMapperBase):
@ -19,8 +26,6 @@ class PythonSphinxMapper(SphinxMapperBase):
:param path: Path of file to read :param path: Path of file to read
''' '''
# TODO support JSON here
# TODO sphinx way of reporting errors in logs?
try: try:
parsed_data = parsed(path) 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 Currently this is setup to build the Indentity repo from ASP.Net
We don't have the checkout in the repo, You should simply be able to run ``make html`` in this directory.
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.

View File

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

View File

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

View File

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