Skip to content

Commit

Permalink
Fail elegantly when no source files are found
Browse files Browse the repository at this point in the history
Fixes #324
  • Loading branch information
AWhetter committed Feb 9, 2022
1 parent 685d1d3 commit 6028cb1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions autoapi/mappers/python/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

import sphinx.environment
from sphinx.errors import ExtensionError
import sphinx.util
from sphinx.util.console import bold
import sphinx.util.docstrings
Expand Down Expand Up @@ -286,6 +287,9 @@ def load(self, patterns, dirs, ignore=None):
shortened, relative path the package/module
"""
dir_root_files = list(self._find_files(patterns, dirs, ignore))
if not dir_root_files:
raise ExtensionError(f"No source files found in: {','.join(dirs)}")

if not self._need_to_load(dir_root_files):
LOGGER.debug(
"[AutoAPI] Skipping read stage because source files have not changed."
Expand Down
29 changes: 29 additions & 0 deletions tests/python/pyemptyexample/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"
project = "pyexample"
copyright = "2015, readthedocs"
author = "readthedocs"
version = "0.1"
release = "0.1"
language = None
exclude_patterns = ["_build"]
pygments_style = "sphinx"
todo_include_todos = False
html_theme = "alabaster"
htmlhelp_basename = "pyexampledoc"
extensions = ["sphinx.ext.autodoc", "autoapi.extension"]
autoapi_type = "python"
autoapi_dirs = ["example"]
autoapi_python_class_content = "both"
autoapi_options = [
"members",
"undoc-members", # this is temporary until we add docstrings across the codebase
"show-inheritance",
"show-module-summary",
"special-members",
"imported-members",
"inherited-members",
]
25 changes: 25 additions & 0 deletions tests/python/pyemptyexample/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. pyexample documentation master file, created by
sphinx-quickstart on Fri May 29 13:34:37 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to pyexample's documentation!
=====================================

.. toctree::

autoapi/index

Contents:

.. toctree::
:maxdepth: 2


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

9 changes: 9 additions & 0 deletions tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import sphinx
from sphinx.application import Sphinx
from sphinx.errors import ExtensionError
import sphinx.util.logging

from autoapi.mappers.python import (
Expand Down Expand Up @@ -912,3 +913,11 @@ def test_renders_typehint_in_second_module(self):
example2_file = example2_handle.read()

assert "(*int*)" in example2_file


def test_no_files_found(builder):
"""Test that building does not fail when no sources files are found."""
with pytest.raises(ExtensionError) as exc_info:
builder("pyemptyexample")

assert os.path.dirname(__file__) in str(exc_info.value)

0 comments on commit 6028cb1

Please sign in to comment.