Skip to content

Commit a8e6cdb

Browse files
authored
polish loggers (#54)
1 parent f3fadce commit a8e6cdb

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

sphinx_runpython/blocdefs/sphinx_blocref_extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from ..language import TITLES
2020
from ..ext_helper import info_blocref
2121

22+
logger = logging.getLogger("blocref")
23+
2224

2325
class blocref_node(nodes.admonition):
2426
"""
@@ -471,15 +473,13 @@ def process_blocref_nodes_generic(
471473
try:
472474
targ = blocref_info["target"]
473475
except KeyError as e:
474-
logger = logging.getLogger("blocref")
475476
logger.warning(
476477
"Unable to find key 'target' in %r (e=%r)", blocref_info, e
477478
)
478479
continue
479480
try:
480481
targ_refid = blocref_info["target"]["refid"]
481482
except KeyError as e:
482-
logger = logging.getLogger("blocref")
483483
logger.warning("Unable to find key 'refid' in %r (e=%r)", targ, e)
484484
continue
485485
int_ids = [f"index{targ_refid}-{env.new_serialno(targ_refid)}"]

sphinx_runpython/collapse/sphinx_collapse_extension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from sphinx.util.nodes import nested_parse_with_titles
77
from ..language import TITLES, sphinx_lang
88

9+
logger = logging.getLogger("sphinx")
10+
911

1012
class collapse_node(nodes.admonition):
1113
"""
@@ -61,7 +63,6 @@ def run(self):
6163
if "legend" in self.options:
6264
legend = self.options["legend"]
6365
if "/" not in legend:
64-
logger = logging.getLogger("sphinx")
6566
logger.warning(
6667
"[CollapseDirective] unable to interpret parameter legend %r.",
6768
legend,

sphinx_runpython/docassert/sphinx_docassert_extension.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from sphinx.util.docfields import DocFieldTransformer, _is_single_paragraph
77
from ..import_object_helper import import_any_object, import_object
88

9+
logger = logging.getLogger("docassert")
10+
911

1012
class Parameter:
1113
"Definition of a parameter."
@@ -121,7 +123,6 @@ def kg(p):
121123
return p if isinstance(p, str) else p.name
122124

123125
check_params = {kg(p): 0 for p in parameters}
124-
logger = logging.getLogger("docassert")
125126

126127
def check_item(fieldarg, content, logger):
127128
"local function"
@@ -339,7 +340,6 @@ def override_transform(self, other_self, node):
339340
reasons = "\n".join(f" {e}" for e in excs)
340341
else:
341342
reasons = "unknown"
342-
logger = logging.getLogger("docassert")
343343
logger.warning(
344344
"[docassert] unable to import object %r, reasons: %s", docs, reasons
345345
)
@@ -353,7 +353,6 @@ def override_transform(self, other_self, node):
353353
parameters = signature.parameters
354354
except (TypeError, ValueError):
355355
# built-in function
356-
logger = logging.getLogger("docassert")
357356
if myfunc.__text_signature__:
358357
logger.warning(
359358
"[docassert] unable to get signature (1) of %r: %s",
@@ -393,15 +392,13 @@ def override_transform(self, other_self, node):
393392
try:
394393
env = other_self.directive.state.document.settings.env
395394
except AttributeError as e:
396-
logger = logging.getLogger("docassert")
397395
logger.warning("[docassert] %s", e)
398396
env = None
399397

400398
docname = fieldbody.parent.source.split("docstring of")[-1].strip()
401399

402400
for entry in entries:
403401
if isinstance(entry, nodes.field):
404-
logger = logging.getLogger("docassert")
405402
logger.warning("[docassert] unable to check [nodes.field] %s", entry)
406403
else:
407404
fieldtype, content = entry

sphinx_runpython/gdot/sphinx_gdot_extension.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from ..ext_io_helper import download_requirejs, get_url_content_timeout
1818
from ..runpython.sphinx_runpython_extension import run_python_script
1919

20+
logger = logging.getLogger("gdot")
21+
2022

2123
class gdot_node(nodes.admonition):
2224
"""
@@ -130,7 +132,6 @@ def run(self):
130132
if url == "local":
131133
if docname is None or "HERE" not in info:
132134
url = GDotDirective._default_url
133-
logger = logging.getLogger("gdot")
134135
logger.warning("[gdot] docname is none, falling back to %r.", url)
135136
else:
136137
spl = docname.split("/")
@@ -196,13 +197,11 @@ def run(self):
196197
)
197198

198199
if stderr:
199-
logger = logging.getLogger("gdot")
200200
logger.warning("[gdot] a dot graph cannot be draw due to %s", stderr)
201201
content = stdout
202202
if script:
203203
spl = content.split(script)
204204
if len(spl) > 2:
205-
logger = logging.getLogger("gdot")
206205
logger.warning("[gdot] too many output lines %s", content)
207206
content = spl[-1]
208207

@@ -274,7 +273,6 @@ def render_dot_html(
274273
_emit_dummy_output(self, format=format)
275274

276275
if format not in {"png", "svg"}:
277-
logger = logging.getLogger(__name__)
278276
logger.warning(__("format must be either 'png' or 'svg', but is %r"), format)
279277
try:
280278
fname, outfn = render_dot(self, code, options, format, prefix, filename)
@@ -428,7 +426,6 @@ def depart_gdot_node_html(self, node):
428426

429427

430428
def copy_js_files(app):
431-
logger = logging.getLogger("gdot")
432429
dest = app.config.html_static_path
433430
if isinstance(dest, list) and len(dest) > 0:
434431
dest = dest[0]

sphinx_runpython/runpython/sphinx_runpython_extension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from .run_cmd import run_cmd
1515
from ..collapse.sphinx_collapse_extension import collapse_node
1616

17+
logger = logging.getLogger("runpython")
18+
1719

1820
def remove_extra_spaces_and_black(
1921
filename: str, apply_black=True, is_string=None
@@ -757,7 +759,6 @@ def run(self):
757759
try:
758760
script_disp = remove_extra_spaces_and_black(script_disp, is_string=True)
759761
except Exception as e:
760-
logger = logging.getLogger("runpython")
761762
if "." in docname:
762763
comment = f' File "{docname}", line {lineno}'
763764
else:

0 commit comments

Comments
 (0)