Refactored dotnet error to raise an exception properly

This commit is contained in:
Ashley Whetter 2021-04-12 20:00:35 -07:00
parent 099e6e89c1
commit 86a6d1059c
3 changed files with 25 additions and 40 deletions

View File

@ -61,7 +61,7 @@ class DotNetSphinxMapper(SphinxMapperBase):
DOCFX_OUTPUT_PATH = "_api"
# pylint: disable=arguments-differ
def load(self, patterns, dirs, ignore=None, **kwargs):
def load(self, patterns, dirs, ignore=None):
"""Load objects from the filesystem into the ``paths`` dictionary.
If the setting ``autoapi_patterns`` was not specified, look for a
@ -70,7 +70,6 @@ class DotNetSphinxMapper(SphinxMapperBase):
pattern matches if no ``docfx.json`` files are found.
"""
LOGGER.info(bold("[AutoAPI] ") + darkgreen("Loading Data"))
raise_error = kwargs.get("raise_error", True)
all_files = set()
if not self.app.config.autoapi_file_patterns:
all_files = set(
@ -82,40 +81,28 @@ class DotNetSphinxMapper(SphinxMapperBase):
)
if all_files:
try:
command = ["docfx", "metadata", "--raw", "--force"]
command.extend(all_files)
proc = subprocess.Popen(
" ".join(command),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
env=dict(
(key, os.environ[key])
for key in [
"PATH",
"HOME",
"SYSTEMROOT",
"USERPROFILE",
"WINDIR",
]
if key in os.environ
),
)
_, error_output = proc.communicate()
if error_output:
LOGGER.warning(error_output, type="autoapi", subtype="not_readable")
except (OSError, subprocess.CalledProcessError):
LOGGER.warning(
"Error generating metadata",
exc_info=True,
type="autoapi",
subtype="metadata_generation",
)
if raise_error:
raise ExtensionError(
"Failure in docfx while generating AutoAPI output."
)
command = ["docfx", "metadata", "--raw", "--force"]
command.extend(all_files)
proc = subprocess.Popen(
" ".join(command),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
env=dict(
(key, os.environ[key])
for key in [
"PATH",
"HOME",
"SYSTEMROOT",
"USERPROFILE",
"WINDIR",
]
if key in os.environ
),
)
_, error_output = proc.communicate()
if error_output:
LOGGER.warning(error_output, type="autoapi", subtype="not_readable")
# We now have yaml files
for xdoc_path in self.find_files(
patterns=["*.yml"], dirs=[self.DOCFX_OUTPUT_PATH], ignore=ignore

View File

@ -299,8 +299,6 @@ Suppressing Warnings
* python_import_resolution
Used if resolving references to objects in an imported module failed. Potential reasons
include cyclical imports and missing (parent) modules.
* metadata_generation
(Dotnet only) Generating metadata for input files via docfx failed.
* not_readable
Emitted if processing (opening, parsing, ...) an input file failed.
* toc_reference
@ -311,4 +309,4 @@ Suppressing Warnings
.. code-block:: python
suppress_warnings = ["autoapi.python_import_resolution", "autoapi.not_readable"]
suppress_warnings = ["autoapi.python_import_resolution", "autoapi.not_readable"]

View File

@ -93,7 +93,7 @@ class TestDotNetSphinxMapper:
"autoapi.mappers.dotnet.DotNetSphinxMapper.read_file", _mock_read
):
dom = dotnet.DotNetSphinxMapper(MockApplication())
dom.load("", "", "", raise_error=False)
dom.load("", "", "")
dom.map()
objs = dom.objects
assert len(objs) == 2