Remove calls to `builtins.print()`

This commit is contained in:
Adam Turner 2023-08-15 16:58:57 +01:00
parent 53a930f8c7
commit ffb14f59bc
6 changed files with 112 additions and 89 deletions

View File

@ -299,18 +299,38 @@ select = [
[tool.ruff.per-file-ignores] [tool.ruff.per-file-ignores]
"doc/conf.py" = ["INP001"] "doc/conf.py" = ["INP001"]
"doc/development/tutorials/examples/*" = ["INP001"] "doc/development/tutorials/examples/*" = ["INP001"]
# allow print() in the tutorial
"doc/development/tutorials/examples/recipe.py" = ["T201"]
# whitelist ``print`` for stdout messages
"sphinx/cmd/build.py" = ["T201"]
"sphinx/cmd/make_mode.py" = ["T201"]
"sphinx/cmd/quickstart.py" = ["T201"]
"sphinx/environment/collectors/toctree.py" = ["B026"] "sphinx/environment/collectors/toctree.py" = ["B026"]
"sphinx/environment/adapters/toctree.py" = ["B026"] "sphinx/environment/adapters/toctree.py" = ["B026"]
# whitelist ``print`` for stdout messages
"sphinx/ext/intersphinx.py" = ["T201"]
# whitelist ``print`` for stdout messages
"sphinx/testing/fixtures.py" = ["T201"]
# Ruff bug: https://github.com/astral-sh/ruff/issues/6540 # Ruff bug: https://github.com/astral-sh/ruff/issues/6540
"sphinx/transforms/i18n.py" = ["PGH004"] "sphinx/transforms/i18n.py" = ["PGH004"]
"tests/*" = ["E501"] "tests/*" = [
"E501",
"T201" # whitelist ``print`` for tests
]
# these tests need old ``typing`` generic aliases # these tests need old ``typing`` generic aliases
"tests/test_util_typing.py" = ["UP006", "UP035"] "tests/test_util_typing.py" = ["UP006", "UP035"]
"tests/typing_test_data.py" = ["UP006", "UP035"] "tests/typing_test_data.py" = ["UP006", "UP035"]
# whitelist ``print`` for stdout messages
"utils/*" = ["T201"]
[tool.ruff.flake8-quotes] [tool.ruff.flake8-quotes]
inline-quotes = "single" inline-quotes = "single"

View File

@ -1555,8 +1555,8 @@ class Symbol:
@staticmethod @staticmethod
def debug_print(*args: Any) -> None: def debug_print(*args: Any) -> None:
print(Symbol.debug_indent_string * Symbol.debug_indent, end="") logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end="")
print(*args) logger.debug(*args)
def _assert_invariants(self) -> None: def _assert_invariants(self) -> None:
if not self.parent: if not self.parent:
@ -1733,7 +1733,7 @@ class Symbol:
Symbol.debug_print("_find_named_symbols:") Symbol.debug_print("_find_named_symbols:")
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("self:") Symbol.debug_print("self:")
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_print("ident: ", ident) Symbol.debug_print("ident: ", ident)
Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("matchSelf: ", matchSelf)
Symbol.debug_print("recurseInAnon: ", recurseInAnon) Symbol.debug_print("recurseInAnon: ", recurseInAnon)
@ -1743,7 +1743,7 @@ class Symbol:
s = self s = self
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in self:") Symbol.debug_print("searching in self:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
while True: while True:
if matchSelf: if matchSelf:
yield s yield s
@ -1757,12 +1757,12 @@ class Symbol:
s = s.siblingAbove s = s.siblingAbove
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in sibling:") Symbol.debug_print("searching in sibling:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
for s in candidates(): for s in candidates():
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("candidate:") Symbol.debug_print("candidate:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
if s.ident == ident: if s.ident == ident:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 1 Symbol.debug_indent += 1
@ -1790,7 +1790,7 @@ class Symbol:
Symbol.debug_print("_symbol_lookup:") Symbol.debug_print("_symbol_lookup:")
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("self:") Symbol.debug_print("self:")
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_print("nestedName: ", nestedName) Symbol.debug_print("nestedName: ", nestedName)
Symbol.debug_print("ancestorLookupType:", ancestorLookupType) Symbol.debug_print("ancestorLookupType:", ancestorLookupType)
Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("matchSelf: ", matchSelf)
@ -1817,7 +1817,7 @@ class Symbol:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("starting point:") Symbol.debug_print("starting point:")
print(parentSymbol.to_string(Symbol.debug_indent + 1), end="") logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
# and now the actual lookup # and now the actual lookup
for ident in names[:-1]: for ident in names[:-1]:
@ -1837,7 +1837,7 @@ class Symbol:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("handle last name from:") Symbol.debug_print("handle last name from:")
print(parentSymbol.to_string(Symbol.debug_indent + 1), end="") logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
# handle the last name # handle the last name
ident = names[-1] ident = names[-1]
@ -2088,14 +2088,14 @@ class Symbol:
Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("matchSelf: ", matchSelf)
Symbol.debug_print("recurseInAnon: ", recurseInAnon) Symbol.debug_print("recurseInAnon: ", recurseInAnon)
Symbol.debug_print("searchInSiblings:", searchInSiblings) Symbol.debug_print("searchInSiblings:", searchInSiblings)
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_indent -= 2 Symbol.debug_indent -= 2
current = self current = self
while current is not None: while current is not None:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 2 Symbol.debug_indent += 2
Symbol.debug_print("trying:") Symbol.debug_print("trying:")
print(current.to_string(Symbol.debug_indent + 1), end="") logger.debug(current.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_indent -= 2 Symbol.debug_indent -= 2
if matchSelf and current.ident == ident: if matchSelf and current.ident == ident:
return current return current
@ -2125,7 +2125,7 @@ class Symbol:
Symbol.debug_print("name: ", name) Symbol.debug_print("name: ", name)
Symbol.debug_print("id: ", id_) Symbol.debug_print("id: ", id_)
if s is not None: if s is not None:
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
else: else:
Symbol.debug_print("not found") Symbol.debug_print("not found")
if s is None: if s is None:
@ -3587,9 +3587,9 @@ class AliasTransform(SphinxTransform):
rootSymbol: Symbol = self.env.domains['c'].data['root_symbol'] rootSymbol: Symbol = self.env.domains['c'].data['root_symbol']
parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey) parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey)
if not parentSymbol: if not parentSymbol:
print("Target: ", sig) logger.debug("Target: ", sig)
print("ParentKey: ", parentKey) logger.debug("ParentKey: ", parentKey)
print(rootSymbol.dump(1)) logger.debug(rootSymbol.dump(1))
assert parentSymbol # should be there assert parentSymbol # should be there
s = parentSymbol.find_declaration( s = parentSymbol.find_declaration(
@ -3778,40 +3778,40 @@ class CDomain(Domain):
def clear_doc(self, docname: str) -> None: def clear_doc(self, docname: str) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("clear_doc:", docname) logger.debug("clear_doc:", docname)
print("\tbefore:") logger.debug("\tbefore:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tbefore end") logger.debug("\tbefore end")
rootSymbol = self.data['root_symbol'] rootSymbol = self.data['root_symbol']
rootSymbol.clear_doc(docname) rootSymbol.clear_doc(docname)
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("\tafter:") logger.debug("\tafter:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tafter end") logger.debug("\tafter end")
print("clear_doc end:", docname) logger.debug("clear_doc end:", docname)
def process_doc(self, env: BuildEnvironment, docname: str, def process_doc(self, env: BuildEnvironment, docname: str,
document: nodes.document) -> None: document: nodes.document) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("process_doc:", docname) logger.debug("process_doc:", docname)
print(self.data['root_symbol'].dump(0)) logger.debug(self.data['root_symbol'].dump(0))
print("process_doc end:", docname) logger.debug("process_doc end:", docname)
def process_field_xref(self, pnode: pending_xref) -> None: def process_field_xref(self, pnode: pending_xref) -> None:
pnode.attributes.update(self.env.ref_context) pnode.attributes.update(self.env.ref_context)
def merge_domaindata(self, docnames: list[str], otherdata: dict) -> None: def merge_domaindata(self, docnames: list[str], otherdata: dict) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("merge_domaindata:") logger.debug("merge_domaindata:")
print("\tself:") logger.debug("\tself:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tself end") logger.debug("\tself end")
print("\tother:") logger.debug("\tother:")
print(otherdata['root_symbol'].dump(1)) logger.debug(otherdata['root_symbol'].dump(1))
print("\tother end") logger.debug("\tother end")
print("merge_domaindata end") logger.debug("merge_domaindata end")
self.data['root_symbol'].merge_with(otherdata['root_symbol'], self.data['root_symbol'].merge_with(otherdata['root_symbol'],
docnames, self.env) docnames, self.env)
@ -3837,9 +3837,9 @@ class CDomain(Domain):
if parentKey: if parentKey:
parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey) parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey)
if not parentSymbol: if not parentSymbol:
print("Target: ", target) logger.debug("Target: ", target)
print("ParentKey: ", parentKey) logger.debug("ParentKey: ", parentKey)
print(rootSymbol.dump(1)) logger.debug(rootSymbol.dump(1))
assert parentSymbol # should be there assert parentSymbol # should be there
else: else:
parentSymbol = rootSymbol parentSymbol = rootSymbol

View File

@ -4242,8 +4242,8 @@ class Symbol:
@staticmethod @staticmethod
def debug_print(*args: Any) -> None: def debug_print(*args: Any) -> None:
print(Symbol.debug_indent_string * Symbol.debug_indent, end="") logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end="")
print(*args) logger.debug(*args)
def _assert_invariants(self) -> None: def _assert_invariants(self) -> None:
if not self.parent: if not self.parent:
@ -4452,7 +4452,7 @@ class Symbol:
Symbol.debug_print("_find_named_symbols:") Symbol.debug_print("_find_named_symbols:")
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("self:") Symbol.debug_print("self:")
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_print("identOrOp: ", identOrOp) Symbol.debug_print("identOrOp: ", identOrOp)
Symbol.debug_print("templateParams: ", templateParams) Symbol.debug_print("templateParams: ", templateParams)
Symbol.debug_print("templateArgs: ", templateArgs) Symbol.debug_print("templateArgs: ", templateArgs)
@ -4496,7 +4496,7 @@ class Symbol:
s = self s = self
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in self:") Symbol.debug_print("searching in self:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
while True: while True:
if matchSelf: if matchSelf:
yield s yield s
@ -4510,12 +4510,12 @@ class Symbol:
s = s.siblingAbove s = s.siblingAbove
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in sibling:") Symbol.debug_print("searching in sibling:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
for s in candidates(): for s in candidates():
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("candidate:") Symbol.debug_print("candidate:")
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
if matches(s): if matches(s):
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 1 Symbol.debug_indent += 1
@ -4545,7 +4545,7 @@ class Symbol:
Symbol.debug_print("_symbol_lookup:") Symbol.debug_print("_symbol_lookup:")
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("self:") Symbol.debug_print("self:")
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_print("nestedName: ", nestedName) Symbol.debug_print("nestedName: ", nestedName)
Symbol.debug_print("templateDecls: ", ",".join(str(t) for t in templateDecls)) Symbol.debug_print("templateDecls: ", ",".join(str(t) for t in templateDecls))
Symbol.debug_print("strictTemplateParamArgLists:", strictTemplateParamArgLists) Symbol.debug_print("strictTemplateParamArgLists:", strictTemplateParamArgLists)
@ -4592,7 +4592,7 @@ class Symbol:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("starting point:") Symbol.debug_print("starting point:")
print(parentSymbol.to_string(Symbol.debug_indent + 1), end="") logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
# and now the actual lookup # and now the actual lookup
iTemplateDecl = 0 iTemplateDecl = 0
@ -4638,7 +4638,7 @@ class Symbol:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("handle last name from:") Symbol.debug_print("handle last name from:")
print(parentSymbol.to_string(Symbol.debug_indent + 1), end="") logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
# handle the last name # handle the last name
name = names[-1] name = names[-1]
@ -4997,14 +4997,14 @@ class Symbol:
Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("matchSelf: ", matchSelf)
Symbol.debug_print("recurseInAnon: ", recurseInAnon) Symbol.debug_print("recurseInAnon: ", recurseInAnon)
Symbol.debug_print("searchInSiblings:", searchInSiblings) Symbol.debug_print("searchInSiblings:", searchInSiblings)
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_indent -= 2 Symbol.debug_indent -= 2
current = self current = self
while current is not None: while current is not None:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 2 Symbol.debug_indent += 2
Symbol.debug_print("trying:") Symbol.debug_print("trying:")
print(current.to_string(Symbol.debug_indent + 1), end="") logger.debug(current.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_indent -= 2 Symbol.debug_indent -= 2
if matchSelf and current.identOrOp == identOrOp: if matchSelf and current.identOrOp == identOrOp:
return current return current
@ -5047,7 +5047,7 @@ class Symbol:
Symbol.debug_print("templateParams:", templateParams) Symbol.debug_print("templateParams:", templateParams)
Symbol.debug_print("id: ", id_) Symbol.debug_print("id: ", id_)
if s is not None: if s is not None:
print(s.to_string(Symbol.debug_indent + 1), end="") logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
else: else:
Symbol.debug_print("not found") Symbol.debug_print("not found")
if s is None: if s is None:
@ -5069,7 +5069,7 @@ class Symbol:
Symbol.debug_print("find_name:") Symbol.debug_print("find_name:")
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("self:") Symbol.debug_print("self:")
print(self.to_string(Symbol.debug_indent + 1), end="") logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
Symbol.debug_print("nestedName: ", nestedName) Symbol.debug_print("nestedName: ", nestedName)
Symbol.debug_print("templateDecls: ", templateDecls) Symbol.debug_print("templateDecls: ", templateDecls)
Symbol.debug_print("typ: ", typ) Symbol.debug_print("typ: ", typ)
@ -6916,7 +6916,7 @@ class DefinitionParser(BaseParser):
self.fail('Expected "," or ">".') self.fail('Expected "," or ">".')
except DefinitionError as e: except DefinitionError as e:
errs.append((e, "If no parameter")) errs.append((e, "If no parameter"))
print(errs) logger.debug(errs)
raise self._make_multi_error(errs, header) raise self._make_multi_error(errs, header)
def _parse_template_introduction(self) -> ASTTemplateIntroduction: def _parse_template_introduction(self) -> ASTTemplateIntroduction:
@ -7717,9 +7717,9 @@ class AliasTransform(SphinxTransform):
rootSymbol: Symbol = self.env.domains['cpp'].data['root_symbol'] rootSymbol: Symbol = self.env.domains['cpp'].data['root_symbol']
parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey) parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey)
if not parentSymbol: if not parentSymbol:
print("Target: ", sig) logger.debug("Target: ", sig)
print("ParentKey: ", parentKey) logger.debug("ParentKey: ", parentKey)
print(rootSymbol.dump(1)) logger.debug(rootSymbol.dump(1))
assert parentSymbol # should be there assert parentSymbol # should be there
symbols: list[Symbol] = [] symbols: list[Symbol] = []
@ -7960,19 +7960,19 @@ class CPPDomain(Domain):
def clear_doc(self, docname: str) -> None: def clear_doc(self, docname: str) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("clear_doc:", docname) logger.debug("clear_doc:", docname)
print("\tbefore:") logger.debug("\tbefore:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tbefore end") logger.debug("\tbefore end")
rootSymbol = self.data['root_symbol'] rootSymbol = self.data['root_symbol']
rootSymbol.clear_doc(docname) rootSymbol.clear_doc(docname)
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("\tafter:") logger.debug("\tafter:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tafter end") logger.debug("\tafter end")
print("clear_doc end:", docname) logger.debug("clear_doc end:", docname)
for name, nDocname in list(self.data['names'].items()): for name, nDocname in list(self.data['names'].items()):
if nDocname == docname: if nDocname == docname:
del self.data['names'][name] del self.data['names'][name]
@ -7980,22 +7980,22 @@ class CPPDomain(Domain):
def process_doc(self, env: BuildEnvironment, docname: str, def process_doc(self, env: BuildEnvironment, docname: str,
document: nodes.document) -> None: document: nodes.document) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("process_doc:", docname) logger.debug("process_doc:", docname)
print(self.data['root_symbol'].dump(0)) logger.debug(self.data['root_symbol'].dump(0))
print("process_doc end:", docname) logger.debug("process_doc end:", docname)
def process_field_xref(self, pnode: pending_xref) -> None: def process_field_xref(self, pnode: pending_xref) -> None:
pnode.attributes.update(self.env.ref_context) pnode.attributes.update(self.env.ref_context)
def merge_domaindata(self, docnames: list[str], otherdata: dict) -> None: def merge_domaindata(self, docnames: list[str], otherdata: dict) -> None:
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("merge_domaindata:") logger.debug("merge_domaindata:")
print("\tself:") logger.debug("\tself:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tself end") logger.debug("\tself end")
print("\tother:") logger.debug("\tother:")
print(otherdata['root_symbol'].dump(1)) logger.debug(otherdata['root_symbol'].dump(1))
print("\tother end") logger.debug("\tother end")
self.data['root_symbol'].merge_with(otherdata['root_symbol'], self.data['root_symbol'].merge_with(otherdata['root_symbol'],
docnames, self.env) docnames, self.env)
@ -8006,10 +8006,10 @@ class CPPDomain(Domain):
ourNames[name] = docname ourNames[name] = docname
# no need to warn on duplicates, the symbol merge already does that # no need to warn on duplicates, the symbol merge already does that
if Symbol.debug_show_tree: if Symbol.debug_show_tree:
print("\tresult:") logger.debug("\tresult:")
print(self.data['root_symbol'].dump(1)) logger.debug(self.data['root_symbol'].dump(1))
print("\tresult end") logger.debug("\tresult end")
print("merge_domaindata end") logger.debug("merge_domaindata end")
def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder: Builder, def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
typ: str, target: str, node: pending_xref, typ: str, target: str, node: pending_xref,
@ -8044,9 +8044,9 @@ class CPPDomain(Domain):
if parentKey: if parentKey:
parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey) parentSymbol: Symbol = rootSymbol.direct_lookup(parentKey)
if not parentSymbol: if not parentSymbol:
print("Target: ", target) logger.debug("Target: ", target)
print("ParentKey: ", parentKey.data) logger.debug("ParentKey: ", parentKey.data)
print(rootSymbol.dump(1)) logger.debug(rootSymbol.dump(1))
assert parentSymbol # should be there assert parentSymbol # should be there
else: else:
parentSymbol = rootSymbol parentSymbol = rootSymbol
@ -8099,7 +8099,7 @@ class CPPDomain(Domain):
objtypes = self.objtypes_for_role(typ) objtypes = self.objtypes_for_role(typ)
if objtypes: if objtypes:
return declTyp in objtypes return declTyp in objtypes
print(f"Type is {typ}, declaration type is {declTyp}") logger.debug(f"Type is {typ}, declaration type is {declTyp}")
raise AssertionError raise AssertionError
if not checkType(): if not checkType():
logger.warning("cpp:%s targets a %s (%s).", logger.warning("cpp:%s targets a %s (%s).",

View File

@ -27,12 +27,15 @@ import sphinx.locale
from sphinx import __display_version__, package_dir from sphinx import __display_version__, package_dir
from sphinx.cmd.quickstart import EXTENSIONS from sphinx.cmd.quickstart import EXTENSIONS
from sphinx.locale import __ from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.osutil import FileAvoidWrite, ensuredir from sphinx.util.osutil import FileAvoidWrite, ensuredir
from sphinx.util.template import ReSTRenderer from sphinx.util.template import ReSTRenderer
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Generator, Sequence from collections.abc import Generator, Sequence
logger = logging.getLogger(__name__)
# automodule options # automodule options
if 'SPHINX_APIDOC_OPTIONS' in os.environ: if 'SPHINX_APIDOC_OPTIONS' in os.environ:
OPTIONS = os.environ['SPHINX_APIDOC_OPTIONS'].split(',') OPTIONS = os.environ['SPHINX_APIDOC_OPTIONS'].split(',')
@ -80,14 +83,14 @@ def write_file(name: str, text: str, opts: Any) -> None:
fname = path.join(opts.destdir, f'{name}.{opts.suffix}') fname = path.join(opts.destdir, f'{name}.{opts.suffix}')
if opts.dryrun: if opts.dryrun:
if not quiet: if not quiet:
print(__('Would create file %s.') % fname) logger.info(__('Would create file %s.'), fname)
return return
if not opts.force and path.isfile(fname): if not opts.force and path.isfile(fname):
if not quiet: if not quiet:
print(__('File %s already exists, skipping.') % fname) logger.info(__('File %s already exists, skipping.'), fname)
else: else:
if not quiet: if not quiet:
print(__('Creating file %s.') % fname) logger.info(__('Creating file %s.'), fname)
with FileAvoidWrite(fname) as f: with FileAvoidWrite(fname) as f:
f.write(text) f.write(text)
@ -423,7 +426,7 @@ def main(argv: list[str] = sys.argv[1:]) -> int:
if args.suffix.startswith('.'): if args.suffix.startswith('.'):
args.suffix = args.suffix[1:] args.suffix = args.suffix[1:]
if not path.isdir(rootpath): if not path.isdir(rootpath):
print(__('%s is not a directory.') % rootpath, file=sys.stderr) logger.error(__('%s is not a directory.'), rootpath)
raise SystemExit(1) raise SystemExit(1)
if not args.dryrun: if not args.dryrun:
ensuredir(args.destdir) ensuredir(args.destdir)

View File

@ -580,10 +580,10 @@ def find_autosummary_in_docstring(
pass pass
except ImportExceptionGroup as exc: except ImportExceptionGroup as exc:
errors = '\n'.join({f"* {type(e).__name__}: {e}" for e in exc.exceptions}) errors = '\n'.join({f"* {type(e).__name__}: {e}" for e in exc.exceptions})
print(f'Failed to import {name}.\nPossible hints:\n{errors}') logger.warning(f'Failed to import {name}.\nPossible hints:\n{errors}') # NoQA: G004
except SystemExit: except SystemExit:
print("Failed to import '%s'; the module executes module level " logger.warning("Failed to import '%s'; the module executes module level "
"statement and it might call sys.exit()." % name) 'statement and it might call sys.exit().', name)
return [] return []

View File

@ -284,7 +284,7 @@ class BaseParser:
def status(self, msg: str) -> None: def status(self, msg: str) -> None:
# for debugging # for debugging
indicator = '-' * self.pos + '^' indicator = '-' * self.pos + '^'
print(f"{msg}\n{self.definition}\n{indicator}") logger.debug(f"{msg}\n{self.definition}\n{indicator}") # NoQA: G004
def fail(self, msg: str) -> None: def fail(self, msg: str) -> None:
errors = [] errors = []