Repository: sphinx-contrib/matlabdomain

Issue:
Vague error when there is an empty @ClassFolder
Due to some kind of Git quirk, I sometimes end up with empty directories in my MATLAB file tree. They could be class directories, like `@Test`. It turns out that if this is the case, building the documentation fails with a very vague error which I had been scratching my head over for quite some time now:

```
Extension error (sphinxcontrib.matlab):
Handler <function analyze at 0x000002A1322DE340> for event 'builder-inited' threw an exception (exception: )
```

I usually build using `make html` but when running using `sphinx-build` the verbosity is better and I found out that this error is due to the assertion in `mat_types.py:254`:

```
Traceback (most recent call last):
  File "C:\...\.venv\Lib\site-packages\sphinx\events.py", line 97, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\sphinxcontrib\matlab.py", line 844, in analyze
    mat_types.analyze(app)
  File "C:\...\.venv\Lib\site-packages\sphinxcontrib\mat_types.py", line 254, in analyze
    assert len(class_entities) == 1
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\...\.venv\Lib\site-packages\sphinx\cmd\build.py", line 293, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\sphinx\application.py", line 272, in __init__
    self._init_builder()
  File "C:\...\.venv\Lib\site-packages\sphinx\application.py", line 343, in _init_builder
    self.events.emit('builder-inited')
  File "C:\...\.venv\Lib\site-packages\sphinx\events.py", line 108, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x000001FBDA819C60> for event 'builder-inited' threw an exception (exception: )
```

I can imagine that others might run into this issue, too, so is it perhaps an idea to handle this situation?

Comments:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 73861fa..23f5a6b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,11 @@
+sphinxcontrib-matlabdomain-0.X.Y (2023-MM-DD)
+==============================================
+
+* Fixed `Issue 225`. Empty ``@classfolder`` would throw an assertion error.
+
+.. _Issue 225: https://github.com/sphinx-contrib/matlabdomain/issues/225
+
+
 sphinxcontrib-matlabdomain-0.20.2 (2023-09-15)
 ==============================================
 
diff --git a/sphinxcontrib/mat_types.py b/sphinxcontrib/mat_types.py
index b4adfb4..4eb17db 100644
--- a/sphinxcontrib/mat_types.py
+++ b/sphinxcontrib/mat_types.py
@@ -251,6 +251,10 @@ def analyze(app):
         # Find the class entity class.
         class_entities = [e for e in cf_entity.entities if isinstance(e[1], MatClass)]
         func_entities = [e for e in cf_entity.entities if isinstance(e[1], MatFunction)]
+
+        empty_class_folder = not class_entities and not func_entities
+        if empty_class_folder:
+            continue
         assert len(class_entities) == 1
         cls = class_entities[0][1]
 


Test patch:
diff --git a/tests/helper.py b/tests/helper.py
index d1a345b..803d224 100644
--- a/tests/helper.py
+++ b/tests/helper.py
@@ -17,7 +17,7 @@ if sphinx_version_info[0] >= 7 and sphinx_version_info[1] >= 2:
     from pathlib import Path
 
     def rootdir(the_file):
-        return Path(os.path.dirname(__file__)).absolute()
+        return Path(os.path.dirname(__file__)).resolve().absolute()
 
 else:
     from sphinx.testing.path import path as sphinx_path
diff --git a/tests/test_data/@EmptyClassFolder/readme.txt b/tests/test_data/@EmptyClassFolder/readme.txt
new file mode 100644
index 0000000..0cc80f9
--- /dev/null
+++ b/tests/test_data/@EmptyClassFolder/readme.txt
@@ -0,0 +1,1 @@
+Intentionally empty folder. Tests https://github.com/sphinx-contrib/matlabdomain/issues/225
diff --git a/tests/test_matlabify.py b/tests/test_matlabify.py
index 6e14d68..5c0a3bb 100644
--- a/tests/test_matlabify.py
+++ b/tests/test_matlabify.py
@@ -52,6 +52,7 @@ def test_module(mod):
     expected_items = {
         "+package",
         "@ClassFolder",
+        "@EmptyClassFolder",
         "Application",
         "ClassAbstract",
         "ClassExample",