Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __pycache__

# Other generated files
MANIFEST
sphinx_automodapi/version.py

# Sphinx
_build
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ requires = ["setuptools>=30.3.0",
"setuptools_scm",
"wheel"]
build-backend = 'setuptools.build_meta'


[tool.setuptools_scm]
write_to = "sphinx_automodapi/version.py"
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

import os
from setuptools import setup

setup(use_scm_version={'write_to': os.path.join('sphinx_automodapi', 'version.py')})
setup()
2 changes: 1 addition & 1 deletion sphinx_automodapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.14.dev0'
from .version import version as __version__ # noqa
16 changes: 5 additions & 11 deletions sphinx_automodapi/automodapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class are included in the generated documentation. Defaults to ``False``.
# actually built.

import inspect
import io
import os
import re
import sys
Expand All @@ -112,11 +111,6 @@ class are included in the generated documentation. Defaults to ``False``.

__all__ = []

if sys.version_info[0] == 3:
text_type = str
else:
text_type = unicode # noqa

automod_templ_modheader = """
{modname} {pkgormod}
{modhds}{pkgormodhds}
Expand Down Expand Up @@ -377,14 +371,14 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
if app.config.automodapi_writereprocessed:
# sometimes they are unicode, sometimes not, depending on how
# sphinx has processed things
if isinstance(newsourcestr, text_type):
if isinstance(newsourcestr, str):
ustr = newsourcestr
else:
ustr = newsourcestr.decode(app.config.source_encoding)

if docname is None:
with io.open(os.path.join(app.srcdir, 'unknown.automodapi'),
'a', encoding='utf8') as f:
with open(os.path.join(app.srcdir, 'unknown.automodapi'),
'a', encoding='utf8') as f:
f.write(u'\n**NEW DOC**\n\n')
f.write(ustr)
else:
Expand All @@ -394,8 +388,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
filename = docname + os.path.splitext(env.doc2path(docname))[1]
filename += '.automodapi'

with io.open(os.path.join(app.srcdir, filename), 'w',
encoding='utf8') as f:
with open(os.path.join(app.srcdir, filename), 'w',
encoding='utf8') as f:
f.write(ustr)

return newsourcestr
Expand Down
3 changes: 1 addition & 2 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class members that are inherited from a base class. This value can be
import inspect
import os
import re
import io

from sphinx.util import logging
from sphinx.ext.autosummary import Autosummary
Expand Down Expand Up @@ -312,7 +311,7 @@ def automodsumm_to_autosummary_lines(fn, app):

fullfn = os.path.join(app.builder.env.srcdir, fn)

with io.open(fullfn, encoding='utf8') as fr:
with open(fullfn, encoding='utf8') as fr:
# Note: we use __name__ here instead of just writing the module name in
# case this extension is bundled into another package
from . import automodapi
Expand Down
5 changes: 2 additions & 3 deletions sphinx_automodapi/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import os
import sys
from copy import deepcopy

from sphinx.cmd.build import build_main
Expand All @@ -13,8 +12,8 @@


intersphinx_mapping = {
'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None)
}
'python': ('https://docs.python.org/3/', None)
}

DEFAULT_CONF = {'source_suffix': '.rst',
'master_doc': 'index',
Expand Down
24 changes: 5 additions & 19 deletions sphinx_automodapi/tests/test_autodoc_enhancements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

from textwrap import dedent

import pytest
Expand All @@ -15,23 +13,11 @@ def foo(cls):
return 'foo'


if sys.version_info[0] < 3:
exec(dedent("""
class MyClass(object):
__metaclass__ = Meta
@property
def foo(self):
\"\"\"Docstring for MyClass.foo property.\"\"\"
return 'myfoo'
"""))
else:
exec(dedent("""
class MyClass(metaclass=Meta):
@property
def foo(self):
\"\"\"Docstring for MyClass.foo property.\"\"\"
return 'myfoo'
"""))
class MyClass(metaclass=Meta):
@property
def foo(self):
"""Docstring for MyClass.foo property."""
return 'myfoo'


def test_type_attrgetter():
Expand Down
8 changes: 1 addition & 7 deletions sphinx_automodapi/tests/test_automodapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import sys
from copy import copy

import pytest
Expand All @@ -10,11 +9,6 @@
from . import cython_testpackage # noqa
from .helpers import run_sphinx_in_tmpdir

if sys.version_info[0] == 2:
from io import open as io_open
else:
io_open = open


def setup_function(func):
# This can be replaced with the docutils_namespace context manager once
Expand Down Expand Up @@ -104,7 +98,7 @@ def test_am_replacer_writereprocessed(tmpdir, writereprocessed):
Tests the automodapi_writereprocessed option
"""

with io_open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f:
with open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f:
f.write(am_replacer_repr_str.format(options=''))

run_sphinx_in_tmpdir(tmpdir, additional_conf={'automodapi_writereprocessed': writereprocessed})
Expand Down
10 changes: 4 additions & 6 deletions sphinx_automodapi/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# We store different cases in the cases sub-directory of the tests directory

import os
import io
import sys
import glob
import shutil
from itertools import product
Expand All @@ -26,8 +24,8 @@


intersphinx_mapping = {
'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None)
}
'python': ('https://docs.python.org/3/', None)
}

DEFAULT_CONF = {'source_suffix': '.rst',
'master_doc': 'index',
Expand Down Expand Up @@ -112,8 +110,8 @@ def test_run_full_case(tmpdir, case_dir, parallel):
path_relative = os.path.relpath(path_reference, output_dir)
path_actual = os.path.join(docs_dir, path_relative)
assert os.path.exists(path_actual)
with io.open(path_actual, encoding='utf8') as f:
with open(path_actual, encoding='utf8') as f:
actual = f.read()
with io.open(path_reference, encoding='utf8') as f:
with open(path_reference, encoding='utf8') as f:
reference = f.read()
assert actual.strip() == reference.strip()
7 changes: 0 additions & 7 deletions sphinx_automodapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
__all__ = ['cleanup_whitespace',
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']

if sys.version_info[0] >= 3:
def iteritems(dictionary):
return dictionary.items()
else:
def iteritems(dictionary):
return dictionary.iteritems()

# We use \n instead of os.linesep because even on Windows, the generated files
# use \n as the newline character.
SPACE_NEWLINE = ' \n'
Expand Down