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

Skip to content

Commit b49e6b2

Browse files
committed
Replace Autosummary.warn() calls with logger.warning() for Sphinx 4 compatibility
1 parent 769ea19 commit b49e6b2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

sphinx_automodapi/automodsumm.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class members that are inherited from a base class. This value can be
9898

9999
__all__ = ['Automoddiagram', 'Automodsumm', 'automodsumm_to_autosummary_lines',
100100
'generate_automodsumm_docs', 'process_automodsumm_generation']
101+
logger = logging.getLogger(__name__)
101102

102103

103104
def _str_list_converter(argument):
@@ -134,7 +135,7 @@ def run(self):
134135
try:
135136
localnames, fqns, objs = find_mod_objs(modname)
136137
except ImportError:
137-
self.warn("Couldn't import module " + modname)
138+
logger.warning("Couldn't import module " + modname)
138139
return []
139140

140141
try:
@@ -144,8 +145,8 @@ def run(self):
144145
clsonly = 'classes-only' in self.options
145146
varonly = 'variables-only' in self.options
146147
if [clsonly, funconly, varonly].count(True) > 1:
147-
self.warn('more than one of "functions-only", "classes-only", '
148-
'or "variables-only" defined. Ignoring.')
148+
logger.warning('more than one of "functions-only", "classes-only", '
149+
'or "variables-only" defined. Ignoring.')
149150
clsonly = funconly = varonly = False
150151

151152
skipnames = []
@@ -156,9 +157,9 @@ def run(self):
156157
option_skipnames.remove(lnm)
157158
skipnames.append(lnm)
158159
if len(option_skipnames) > 0:
159-
self.warn('Tried to skip objects {objs} in module {mod}, '
160-
'but they were not present. Ignoring.'
161-
.format(objs=option_skipnames, mod=modname))
160+
logger.warning('Tried to skip objects {objs} in module {mod}, '
161+
'but they were not present. Ignoring.'
162+
.format(objs=option_skipnames, mod=modname))
162163

163164
if funconly:
164165
cont = []
@@ -217,7 +218,7 @@ def run(self):
217218

218219
nms, objs = find_mod_objs(self.arguments[0], onlylocals=ols)[1:]
219220
except ImportError:
220-
self.warn("Couldn't import module " + self.arguments[0])
221+
logger.warning("Couldn't import module " + self.arguments[0])
221222
return []
222223

223224
# Check if some classes should be skipped
@@ -309,8 +310,6 @@ def automodsumm_to_autosummary_lines(fn, app):
309310
310311
"""
311312

312-
logger = logging.getLogger(__name__)
313-
314313
fullfn = os.path.join(app.builder.env.srcdir, fn)
315314

316315
with io.open(fullfn, encoding='utf8') as fr:
@@ -425,8 +424,6 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
425424

426425
from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
427426

428-
logger = logging.getLogger(__name__)
429-
430427
# Create our own templating environment - here we use Astropy's
431428
# templates rather than the default autosummary templates, in order to
432429
# allow docstrings to be shown for methods.

0 commit comments

Comments
 (0)