Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3acbb6e

Browse files
authored
Merge pull request astropy#88 from eteq/add-version-policy
Update sphinx req to 1.7 and add version "policy"
2 parents 9f0b05c + 961fa48 commit 3acbb6e

File tree

10 files changed

+45
-131
lines changed

10 files changed

+45
-131
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changes in sphinx-automodapi
55
-----------------
66

77
- Fixed compatibility with Sphinx 2.0 and later. [#86]
8+
- The minimum sphinx version is now 1.7. [#88]
89

910

1011
0.11 (2019-05-29)

docs/index.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ standalone package that can be used for any project.
99
Installation
1010
------------
1111

12-
This extension requires Sphinx 1.3 or later, and can be installed with::
12+
This extension requires Sphinx 1.7 or later, and can be installed with::
1313

1414
pip install sphinx-automodapi
1515

1616
The extension is also available through conda package management system. It can be installed with::
1717

1818
conda install -c astropy sphinx-automodapi
1919

20+
21+
2022
.. _quickstart:
2123

2224
Quick start
@@ -69,3 +71,11 @@ User guide
6971

7072
automodapi.rst
7173
automodsumm.rst
74+
75+
Dependency Version Guidelines
76+
-----------------------------
77+
78+
As a general guideline, automodapi dependencies (at the time of writing, just
79+
Sphinx) aim to maintain compatibility with versions <= 2 years old. Dependencies
80+
may be newer, however, if specific features become important to help automodapi
81+
work better or be more maintainable.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ classifiers =
2020
zip_safe = False
2121
packages = find:
2222
install_requires =
23-
sphinx>=1.3
23+
sphinx>=1.7
2424

2525
[options.extras_require]
2626
test =

sphinx_automodapi/autodoc_enhancements.py

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from sphinx.ext.autodoc import AttributeDocumenter, ModuleDocumenter
1010
from sphinx.util.inspect import isdescriptor
1111

12-
from .utils import SPHINX_LT_15
13-
1412
__all__ = []
1513

1614
if sys.version_info[0] == 3:
@@ -73,66 +71,19 @@ def type_object_attrgetter(obj, attr, *defargs):
7371
return getattr(obj, attr, *defargs)
7472

7573

76-
if SPHINX_LT_15:
77-
# Provided to work around a bug in Sphinx
78-
# See https://github.com/sphinx-doc/sphinx/pull/1843
79-
class AttributeDocumenter(AttributeDocumenter):
80-
@classmethod
81-
def can_document_member(cls, member, membername, isattr, parent):
82-
non_attr_types = cls.method_types + class_types + \
83-
(MethodDescriptorType,)
84-
isdatadesc = isdescriptor(member) and not \
85-
isinstance(member, non_attr_types) and not \
86-
type(member).__name__ == "instancemethod"
87-
# That last condition addresses an obscure case of C-defined
88-
# methods using a deprecated type in Python 3, that is not
89-
# otherwise exported anywhere by Python
90-
return isdatadesc or (not isinstance(parent, ModuleDocumenter) and
91-
not inspect.isroutine(member) and
92-
not isinstance(member, class_types))
93-
94-
9574
def setup(app):
9675
# Must have the autodoc extension set up first so we can override it
9776
app.setup_extension('sphinx.ext.autodoc')
98-
# Need to import this too since it re-registers all the documenter types
99-
# =_=
100-
import sphinx.ext.autosummary.generate
10177

10278
app.add_autodoc_attrgetter(type, type_object_attrgetter)
10379

104-
if sphinx.version_info < (1, 4, 2):
105-
# this is a really ugly hack to supress a warning that sphinx 1.4
106-
# generates when overriding an existing directive (which is *desired*
107-
# behavior here). As of sphinx v1.4.2, this has been fixed:
108-
# https://github.com/sphinx-doc/sphinx/issues/2451
109-
# But we leave it in for 1.4.0/1.4.1 . But if the "needs_sphinx" is
110-
# eventually updated to >= 1.4.2, this should be removed entirely (in
111-
# favor of the line in the "else" clause)
112-
_oldwarn = app._warning
113-
_oldwarncount = app._warncount
114-
try:
115-
try:
116-
# *this* is in a try/finally because we don't want to force six as
117-
# a real dependency. In sphinx 1.4, six is a prerequisite, so
118-
# there's no issue. But in older sphinxes this may not be true...
119-
# but the inderlying warning is absent anyway so we let it slide.
120-
from six import StringIO
121-
app._warning = StringIO()
122-
except ImportError:
123-
pass
124-
app.add_autodocumenter(AttributeDocumenter)
125-
finally:
126-
app._warning = _oldwarn
127-
app._warncount = _oldwarncount
128-
else:
129-
suppress_warnigns_orig = app.config.suppress_warnings[:]
130-
if 'app.add_directive' not in app.config.suppress_warnings:
131-
app.config.suppress_warnings.append('app.add_directive')
132-
try:
133-
app.add_autodocumenter(AttributeDocumenter)
134-
finally:
135-
app.config.suppress_warnings = suppress_warnigns_orig
80+
suppress_warnings_orig = app.config.suppress_warnings[:]
81+
if 'app.add_directive' not in app.config.suppress_warnings:
82+
app.config.suppress_warnings.append('app.add_directive')
83+
try:
84+
app.add_autodocumenter(AttributeDocumenter)
85+
finally:
86+
app.config.suppress_warnings = suppress_warnings_orig
13687

13788
return {'parallel_read_safe': True,
13889
'parallel_write_safe': True}

sphinx_automodapi/automodapi.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ class are included in the generated documentation. Defaults to ``False``.
100100
import re
101101
import sys
102102

103-
from .utils import SPHINX_LT_16, find_mod_objs
103+
from sphinx.util import logging
104+
105+
from .utils import find_mod_objs
104106

105107
__all__ = []
106108

@@ -199,12 +201,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
199201
sphinx markup.
200202
"""
201203

202-
if SPHINX_LT_16:
203-
warn = app.warn
204-
else:
205-
from sphinx.util import logging
206-
logger = logging.getLogger(__name__)
207-
warn = logger.warning
204+
logger = logging.getLogger(__name__)
208205

209206
spl = _automodapirex.split(sourcestr)
210207
if len(spl) > 1: # automodsumm is in this document
@@ -282,7 +279,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
282279
if len(hds) < 2:
283280
msg = 'Not enough headings (got {0}, need 2), using default -^'
284281
if warnings:
285-
warn(msg.format(len(hds)), location)
282+
logger.warning(msg.format(len(hds)), location)
286283
hds = '-^'
287284
h1, h2 = hds[:2]
288285

@@ -291,7 +288,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
291288
opsstrs = ','.join(unknownops)
292289
msg = 'Found additional options ' + opsstrs + ' in automodapi.'
293290
if warnings:
294-
warn(msg, location)
291+
logger.warning(msg, location)
295292

296293
ispkg, hascls, hasfuncs, hasother = _mod_info(
297294
modnm, toskip, onlylocals=onlylocals)

sphinx_automodapi/automodsumm.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class members that are inherited from a base class. This value can be
8989
import re
9090
import io
9191

92+
from sphinx.util import logging
9293
from sphinx.ext.autosummary import Autosummary
9394
from sphinx.ext.inheritance_diagram import InheritanceDiagram
9495
from docutils.parsers.rst.directives import flag
9596

96-
from .utils import (SPHINX_LT_16, SPHINX_LT_17, find_mod_objs,
97-
cleanup_whitespace)
97+
from .utils import find_mod_objs, cleanup_whitespace
9898

9999
__all__ = ['Automoddiagram', 'Automodsumm', 'automodsumm_to_autosummary_lines',
100100
'generate_automodsumm_docs', 'process_automodsumm_generation']
@@ -144,8 +144,8 @@ def run(self):
144144
clsonly = 'classes-only' in self.options
145145
varonly = 'variables-only' in self.options
146146
if [clsonly, funconly, varonly].count(True) > 1:
147-
self.warning('more than one of functions-only, classes-only, '
148-
'or variables-only defined. Ignoring.')
147+
self.warn('more than one of "functions-only", "classes-only", '
148+
'or "variables-only" defined. Ignoring.')
149149
clsonly = funconly = varonly = False
150150

151151
skipnames = []
@@ -310,12 +310,7 @@ def automodsumm_to_autosummary_lines(fn, app):
310310
311311
"""
312312

313-
if SPHINX_LT_16:
314-
warn = app.warn
315-
else:
316-
from sphinx.util import logging
317-
logger = logging.getLogger(__name__)
318-
warn = logger.warning
313+
logger = logging.getLogger(__name__)
319314

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

@@ -380,7 +375,7 @@ def automodsumm_to_autosummary_lines(fn, app):
380375
msg = ('Defined more than one of functions-only, classes-only, '
381376
'and variables-only. Skipping this directive.')
382377
lnnum = sum([spl[j].count('\n') for j in range(i * 5 + 1)])
383-
warn('[automodsumm] ' + msg, (fn, lnnum))
378+
logger.warning('[automodsumm] ' + msg, (fn, lnnum))
384379
continue
385380

386381
# Use the currentmodule directive so we can just put the local names
@@ -431,14 +426,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
431426

432427
from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
433428

434-
if SPHINX_LT_16:
435-
info = app.info
436-
warn = app.warn
437-
else:
438-
from sphinx.util import logging
439-
logger = logging.getLogger(__name__)
440-
info = logger.info
441-
warn = logger.warning
429+
logger = logging.getLogger(__name__)
442430

443431
# Create our own templating environment - here we use Astropy's
444432
# templates rather than the default autosummary templates, in order to
@@ -460,12 +448,12 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
460448
items = find_autosummary_in_lines(lines, filename=srcfn)
461449
if len(items) > 0:
462450
msg = '[automodsumm] {1}: found {0} automodsumm entries to generate'
463-
info(msg.format(len(items), srcfn))
451+
logger.info(msg.format(len(items), srcfn))
464452

465453
# gennms = [item[0] for item in items]
466454
# if len(gennms) > 20:
467455
# gennms = gennms[:10] + ['...'] + gennms[-10:]
468-
# info('[automodsumm] generating autosummary for: ' + ', '.join(gennms))
456+
# logger.info('[automodsumm] generating autosummary for: ' + ', '.join(gennms))
469457

470458
# remove possible duplicates
471459
items = list(set(items))
@@ -487,7 +475,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
487475
try:
488476
import_by_name_values = import_by_name(name)
489477
except ImportError as e:
490-
warn('[automodsumm] failed to import %r: %s' % (name, e))
478+
logger.warning('[automodsumm] failed to import %r: %s' % (name, e))
491479
continue
492480

493481
# if block to accommodate Sphinx's v1.2.2 and v1.2.3 respectively
@@ -508,10 +496,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
508496

509497
try:
510498

511-
if SPHINX_LT_17:
512-
doc = get_documenter(obj, parent)
513-
else:
514-
doc = get_documenter(app, obj, parent)
499+
doc = get_documenter(app, obj, parent)
515500

516501
if template_name is not None:
517502
template = template_env.get_template(template_name)
@@ -529,10 +514,7 @@ def get_members_mod(obj, typ, include_public=[]):
529514
items = []
530515
for name in dir(obj):
531516
try:
532-
if SPHINX_LT_17:
533-
documenter = get_documenter(safe_getattr(obj, name), obj)
534-
else:
535-
documenter = get_documenter(app, safe_getattr(obj, name), obj)
517+
documenter = get_documenter(app, safe_getattr(obj, name), obj)
536518
except AttributeError:
537519
continue
538520
if typ is None or documenter.objtype == typ:
@@ -572,10 +554,7 @@ def get_members_class(obj, typ, include_public=[],
572554

573555
for name in names:
574556
try:
575-
if SPHINX_LT_17:
576-
documenter = get_documenter(safe_getattr(obj, name), obj)
577-
else:
578-
documenter = get_documenter(app, safe_getattr(obj, name), obj)
557+
documenter = get_documenter(app, safe_getattr(obj, name), obj)
579558
except AttributeError:
580559
continue
581560
if typ is None or documenter.objtype == typ:

sphinx_automodapi/tests/helpers.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
import sys
66
from copy import deepcopy
77

8-
from ..utils import SPHINX_LT_17
8+
from sphinx.cmd.build import build_main
9+
910
from . import cython_testpackage # noqa
1011

11-
__all__ = ['build_main', 'write_conf', 'run_sphinx_in_tmpdir']
12+
__all__ = ['write_conf', 'run_sphinx_in_tmpdir']
1213

13-
if SPHINX_LT_17:
14-
from sphinx import build_main
15-
else:
16-
from sphinx.cmd.build import build_main
1714

1815
intersphinx_mapping = {
1916
'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None)
@@ -47,9 +44,6 @@ def run_sphinx_in_tmpdir(tmpdir, additional_conf={}, expect_error=False):
4744
write_conf(tmpdir.join('conf.py').strpath, conf)
4845

4946
argv = ['-W', '-b', 'html', '.', '_build/html']
50-
if SPHINX_LT_17:
51-
# As of Sphinx 1.7, the first argument is now no longer ignored
52-
argv.insert(0, 'sphinx-build')
5347

5448
try:
5549
os.chdir(tmpdir.strpath)

sphinx_automodapi/tests/test_cases.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
from sphinx.util.osutil import ensuredir
1717
from docutils.parsers.rst import directives, roles
1818

19-
from ..utils import SPHINX_LT_16, SPHINX_LT_17
2019
from .helpers import build_main, write_conf
2120

2221
CASES_ROOT = os.path.join(os.path.dirname(__file__), 'cases')
2322

2423
CASES_DIRS = glob.glob(os.path.join(CASES_ROOT, '*'))
2524

26-
if SPHINX_LT_16 or os.environ.get('TRAVIS_OS_NAME', None) == 'osx':
27-
PARALLEL = {False}
28-
else:
29-
PARALLEL = {False, True}
25+
PARALLEL = {False, True}
3026

3127

3228
intersphinx_mapping = {
@@ -99,9 +95,6 @@ def test_run_full_case(tmpdir, case_dir, parallel):
9995
argv = ['-W', '-b', 'html', src_dir, '_build/html']
10096
if parallel:
10197
argv.insert(0, '-j 4')
102-
if SPHINX_LT_17:
103-
# As of Sphinx 1.7, the first argument is now no longer ignored
104-
argv.insert(0, 'sphinx-build')
10598

10699
try:
107100
os.chdir(docs_dir)

sphinx_automodapi/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
from sphinx import __version__
99
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring
1010

11-
__all__ = ['SPHINX_LT_16', 'SPHINX_LT_17', 'cleanup_whitespace',
11+
__all__ = ['cleanup_whitespace',
1212
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']
1313

14-
SPHINX_LT_15 = LooseVersion(__version__) < LooseVersion('1.5')
15-
SPHINX_LT_16 = LooseVersion(__version__) < LooseVersion('1.6')
16-
SPHINX_LT_17 = LooseVersion(__version__) < LooseVersion('1.7')
17-
1814
if sys.version_info[0] >= 3:
1915
def iteritems(dictionary):
2016
return dictionary.items()

tox.ini

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ envlist =
44
py37-test
55
py27-test-clocale
66
py37-test-clocale
7-
py27-test-sphinx13
8-
py35-test-sphinx14
9-
py35-test-sphinx15
10-
py36-test-sphinx16
7+
py27-test-sphinx17
118
py36-test-sphinx17
129
py37-test-sphinx18
1310
py37-test-sphinx20
@@ -18,10 +15,6 @@ requires = pip >= 18.0
1815
[testenv]
1916
changedir = .tmp/{envname}
2017
deps =
21-
sphinx13: sphinx==1.3.6
22-
sphinx14: sphinx==1.4.9
23-
sphinx15: sphinx==1.5.6
24-
sphinx16: sphinx==1.6.7
2518
sphinx17: sphinx==1.7.9
2619
sphinx18: sphinx==1.8.5
2720
sphinx20: sphinx==2.0.1

0 commit comments

Comments
 (0)