From dbd1e9dfe6ac834097539c8566d8191e6fad1d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fritze?= Date: Thu, 1 Apr 2021 14:22:47 +0200 Subject: [PATCH] Adds a subtype to all `logger.warning` calls --- autoapi/mappers/dotnet.py | 23 ++++++++++++++++++----- autoapi/mappers/go.py | 16 +++++++++++++--- autoapi/mappers/javascript.py | 16 +++++++++++++--- autoapi/mappers/python/mapper.py | 20 ++++++++++++++------ autoapi/toctree.py | 7 ++++++- 5 files changed, 64 insertions(+), 18 deletions(-) diff --git a/autoapi/mappers/dotnet.py b/autoapi/mappers/dotnet.py index 609d2ae..a767f44 100644 --- a/autoapi/mappers/dotnet.py +++ b/autoapi/mappers/dotnet.py @@ -104,10 +104,13 @@ class DotNetSphinxMapper(SphinxMapperBase): ) _, error_output = proc.communicate() if error_output: - LOGGER.warning(error_output, type="autoapi") + LOGGER.warning(error_output, type="autoapi", subtype="not_readable") except (OSError, subprocess.CalledProcessError): LOGGER.warning( - "Error generating metadata", exc_info=True, type="autoapi" + "Error generating metadata", + exc_info=True, + type="autoapi", + subtype="metadata_generation", ) if raise_error: raise ExtensionError( @@ -133,9 +136,17 @@ class DotNetSphinxMapper(SphinxMapperBase): parsed_data = yaml.safe_load(handle) return parsed_data except IOError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) except TypeError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) return None # Subclassed to iterate over items @@ -174,7 +185,9 @@ class DotNetSphinxMapper(SphinxMapperBase): try: cls = obj_map[data["type"].lower()] except KeyError: - LOGGER.warning("Unknown type: %s" % data, type="autoapi") + LOGGER.warning( + "Unknown type: %s" % data, type="autoapi", subtype="create_class" + ) else: obj = cls( data, jinja_env=self.jinja_env, app=self.app, options=options, **kwargs diff --git a/autoapi/mappers/go.py b/autoapi/mappers/go.py index 8b7c113..b96ea44 100644 --- a/autoapi/mappers/go.py +++ b/autoapi/mappers/go.py @@ -54,9 +54,17 @@ class GoSphinxMapper(SphinxMapperBase): parsed_data = json.loads(subprocess.check_output(parser_command)) return parsed_data except IOError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) except TypeError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) return None def create_class(self, data, options=None, **kwargs): @@ -83,7 +91,9 @@ class GoSphinxMapper(SphinxMapperBase): else: cls = obj_map[data["type"]] except KeyError: - LOGGER.warning("Unknown Type: %s" % data, type="autoapi") + LOGGER.warning( + "Unknown Type: %s" % data, type="autoapi", subtype="create_class" + ) else: if cls.inverted_names and "names" in data: # Handle types that have reversed names parameter diff --git a/autoapi/mappers/javascript.py b/autoapi/mappers/javascript.py index 465f1b2..ab0de4f 100644 --- a/autoapi/mappers/javascript.py +++ b/autoapi/mappers/javascript.py @@ -34,9 +34,17 @@ class JavaScriptSphinxMapper(SphinxMapperBase): parsed_data = json.loads(subprocess.check_output([subcmd, "-X", path])) return parsed_data except IOError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) except TypeError: - LOGGER.warning("Error reading file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Error reading file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) return None # Subclassed to iterate over items @@ -71,7 +79,9 @@ class JavaScriptSphinxMapper(SphinxMapperBase): try: cls = obj_map[data["kind"]] except (KeyError, TypeError): - LOGGER.warning("Unknown Type: %s" % data, type="autoapi") + LOGGER.warning( + "Unknown Type: %s" % data, type="autoapi", subtype="create_class" + ) else: # Recurse for children obj = cls(data, jinja_env=self.jinja_env, app=self.app) diff --git a/autoapi/mappers/python/mapper.py b/autoapi/mappers/python/mapper.py index e1c4016..733f5bd 100644 --- a/autoapi/mappers/python/mapper.py +++ b/autoapi/mappers/python/mapper.py @@ -52,7 +52,7 @@ def _expand_wildcard_placeholder(original_module, originals_map, placeholder): msg = "Invalid __all__ entry {0} in {1}".format( name, original_module["name"] ) - LOGGER.warning(msg, type="autoapi") + LOGGER.warning(msg, type="autoapi", subtype="python_import_resolution") continue originals.append(originals_map[name]) @@ -107,7 +107,7 @@ def _resolve_module_placeholders(modules, module_name, visit_path, resolved): msg = "Cannot resolve cyclic import: {0}, {1}".format( ", ".join(visit_path), imported_from ) - LOGGER.warning(msg, type="autoapi") + LOGGER.warning(msg, type="autoapi", subtype="python_import_resolution") module["children"].remove(child) children.pop(child["name"]) continue @@ -116,7 +116,7 @@ def _resolve_module_placeholders(modules, module_name, visit_path, resolved): msg = "Cannot resolve import of unknown module {0} in {1}".format( imported_from, module_name ) - LOGGER.warning(msg, type="autoapi") + LOGGER.warning(msg, type="autoapi", subtype="python_import_resolution") module["children"].remove(child) children.pop(child["name"]) continue @@ -144,7 +144,7 @@ def _resolve_module_placeholders(modules, module_name, visit_path, resolved): msg = "Cannot resolve import of {0} in {1}".format( child["original_path"], module_name ) - LOGGER.warning(msg, type="autoapi") + LOGGER.warning(msg, type="autoapi", subtype="python_import_resolution") module["children"].remove(child) children.pop(child["name"]) continue @@ -319,7 +319,11 @@ class PythonSphinxMapper(SphinxMapperBase): return parsed_data except (IOError, TypeError, ImportError): LOGGER.debug("Reason:", exc_info=True) - LOGGER.warning("Unable to read file: {0}".format(path), type="autoapi") + LOGGER.warning( + "Unable to read file: {0}".format(path), + type="autoapi", + subtype="not_readable", + ) return None def _resolve_placeholders(self): @@ -359,7 +363,11 @@ class PythonSphinxMapper(SphinxMapperBase): try: cls = self._OBJ_MAP[data["type"]] except KeyError: - LOGGER.warning("Unknown type: %s" % data["type"], type="autoapi") + LOGGER.warning( + "Unknown type: %s" % data["type"], + type="autoapi", + subtype="create_class", + ) else: obj = cls( data, diff --git a/autoapi/toctree.py b/autoapi/toctree.py index 70f159b..9c9e059 100644 --- a/autoapi/toctree.py +++ b/autoapi/toctree.py @@ -91,7 +91,12 @@ def _get_toc_reference(node, toc, docname): ref_id = node.children[0].attributes["ids"][0] toc_reference = _find_toc_node(toc, ref_id, addnodes.desc) except (KeyError, IndexError): - LOGGER.warning("Invalid desc node", exc_info=True, type="autoapi") + LOGGER.warning( + "Invalid desc node", + exc_info=True, + type="autoapi", + subtype="toc_reference", + ) toc_reference = None return toc_reference