Repository: mgaitan/sphinxcontrib-mermaid

Issue:
some APIs are removed in Sphinx 4.0 version
such as ``sphinx.util.osutil.ENOENT``:

https://github.com/mgaitan/sphinxcontrib-mermaid/blob/07f9d4316f76d249f89d9b6fd289b8918b426344/sphinxcontrib/mermaid.py#L27

It was removed now and we can use `errno.ENOENT` instead of it. 

refs : https://github.com/sphinx-doc/sphinx/blob/master/doc/extdev/deprecated.rst

Discussion:

Patch:
diff --git a/sphinxcontrib/mermaid.py b/sphinxcontrib/mermaid.py
index f941c21..d7eb959 100644
--- a/sphinxcontrib/mermaid.py
+++ b/sphinxcontrib/mermaid.py
@@ -24,7 +24,7 @@ from docutils.statemachine import ViewList
 import sphinx
 from sphinx.locale import _
 from sphinx.util.i18n import search_image_for_language
-from sphinx.util.osutil import ensuredir, ENOENT
+from sphinx.util.osutil import ensuredir
 from sphinx.util import logging
 from .exceptions import MermaidError
 from .autoclassdiag import class_diagram
@@ -173,9 +173,7 @@ def render_mm(self, code, options, _fmt, prefix='mermaid'):
 
     try:
         p = Popen(mm_args, shell=mermaid_cmd_shell, stdout=PIPE, stdin=PIPE, stderr=PIPE)
-    except OSError as err:
-        if err.errno != ENOENT:   # No such file or directory
-            raise
+    except FileNotFoundError:
         logger.warning('command %r cannot be run (needed for mermaid '
                        'output), check the mermaid_cmd setting' % mermaid_cmd)
         return None, None


Test patch:
diff --git a/tests/test_html.py b/tests/test_html.py
index 7e4df7b..6dcb151 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -7,13 +7,14 @@ def build_all(app):
 
 @pytest.fixture
 def index(app, build_all):
-    return (app.outdir / 'index.html').read_text()
+    # normalize script tag for compat to Sphinx<4
+    return (app.outdir / 'index.html').read_text().replace("<script >", "<script>")
 
 
 @pytest.mark.sphinx('html', testroot="basic")
 def test_html_raw(index):
     assert '<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>' in index
-    assert "<script >mermaid.initialize({startOnLoad:true});</script>" in index
+    assert "<script>mermaid.initialize({startOnLoad:true});</script>" in index
     assert """<div class="mermaid">
             sequenceDiagram
    participant Alice
@@ -36,14 +37,14 @@ def test_conf_mermaid_no_version(app, index):
 
 @pytest.mark.sphinx('html', testroot="basic", confoverrides={'mermaid_init_js': "custom script;"})
 def test_mermaid_init_js(index):
-    assert "<script >mermaid.initialize({startOnLoad:true});</script>" not in index
-    assert '<script >custom script;</script>' in index
+    assert "<script>mermaid.initialize({startOnLoad:true});</script>" not in index
+    assert '<script>custom script;</script>' in index
 
 
 @pytest.mark.sphinx('html', testroot="markdown")
 def test_html_raw_from_markdown(index):
     assert '<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>' in index
-    assert "<script >mermaid.initialize({startOnLoad:true});</script>" in index
+    assert "<script>mermaid.initialize({startOnLoad:true});</script>" in index
     assert """
 <div class="mermaid">
             sequenceDiagram