|
| 1 | +.. _lsp-use-without-sphinx-project: |
| 2 | + |
| 3 | +How To Use Esbonio without a Sphinx Project |
| 4 | +=========================================== |
| 5 | + |
| 6 | +Esbonio (currently) requires a background Sphinx process in order to be useful. |
| 7 | +However, this does not mean Esbonio can only be used with a "proper" Sphinx project. |
| 8 | + |
| 9 | +This guide provides some examples on how you might configure Esbonio for "lightweight" or single file projects. |
| 10 | + |
| 11 | +Minimal Example |
| 12 | +--------------- |
| 13 | + |
| 14 | +Say you have a folder containing a single file ``notes.rst``. |
| 15 | +To enable Esbonio's features in this file you would create a ``pyproject.toml`` file in the same folder containing something like the following. |
| 16 | + |
| 17 | +.. code-block:: toml |
| 18 | +
|
| 19 | + [tool.esbonio.sphinx] |
| 20 | + pythonCommand = ["uv", "run", "--no-project", "--with", "sphinx", "python"] |
| 21 | + buildCommand = ["sphinx-build", "-C", "-b", "html", ".", "${defaultBuildDir}"] |
| 22 | +
|
| 23 | + [tool.esbonio.sphinx.configOverrides] |
| 24 | + root_doc = "notes" |
| 25 | +
|
| 26 | +
|
| 27 | +The ``pythonCommand`` setting instructs Esbonio how to launch the background process with the correct version of Python. |
| 28 | +As you can see, tools like `uv <https://docs.astral.sh/uv/>`__ can be very useful in situations like this, but this can be any command that launches a Python interpreter, see :ref:`this guide <lsp-configure-sphinx-build-env>` for more examples. |
| 29 | + |
| 30 | +.. tip:: |
| 31 | + |
| 32 | + If you use the VSCode extension, (or any client that sets the ``esbonio.sphinx.fallbackEnv``) option, then you can omit the ``pythonCommand`` setting and have ``esbonio`` use the default environment provided by your editor. |
| 33 | + |
| 34 | +The ``buildCommand`` setting instructs Esbonio how to invoke Sphinx. |
| 35 | +**The most important option here is** ``-C`` as this prevents Sphinx from looking for the ``conf.py`` file you see in a typical project. |
| 36 | +See :ref:`this guide <lsp-configure-sphinx-build-cmd>` for more examples. |
| 37 | + |
| 38 | +Finally, by default, Sphinx looks for a file called ``index.rst``. |
| 39 | +Using the ``tool.esbonio.sphinx.configOverrides`` section we can override the ``root_doc`` setting to point it ``notes.rst`` instead. |
| 40 | + |
| 41 | +Markdown Example |
| 42 | +---------------- |
| 43 | + |
| 44 | +If you prefer, you can use Esbonio with your markdown files - assuming you have the necessary dependencies available. |
| 45 | + |
| 46 | +.. code-block:: toml |
| 47 | +
|
| 48 | + [tool.esbonio.sphinx] |
| 49 | + buildCommand = ["sphinx-build", "-C", "-b", "html", ".", "${defaultBuildDir}"] |
| 50 | + pythonCommand = [ |
| 51 | + "uv", "run", "--no-project", |
| 52 | + "--with", "sphinx", |
| 53 | + "--with", "myst-parser", |
| 54 | + "python" |
| 55 | + ] |
| 56 | +
|
| 57 | + [tool.esbonio.sphinx.configOverrides] |
| 58 | + extensions = [ "myst_parser" ] |
| 59 | + root_doc = "notes" |
| 60 | +
|
| 61 | +Third-Party Extensions, Themes and Options |
| 62 | +------------------------------------------ |
| 63 | + |
| 64 | +As you might be able to guess from the previous two examples, you can provide many of the settings you would find in a ``conf.py`` file direct in your ``pyproject.toml`` file! |
| 65 | + |
| 66 | +.. code-block:: toml |
| 67 | +
|
| 68 | + [tool.esbonio.sphinx] |
| 69 | + buildCommand = ["sphinx-build", "-C", "-b", "html", ".", "${defaultBuildDir}"] |
| 70 | + pythonCommand = [ |
| 71 | + "uv", "run", "--no-project", |
| 72 | + "--with", "sphinx", |
| 73 | + "--with", "myst-parser", |
| 74 | + "--with", "sphinx-design", |
| 75 | + "--with", "furo", |
| 76 | + "python" |
| 77 | + ] |
| 78 | +
|
| 79 | +
|
| 80 | + [tool.esbonio.sphinx.configOverrides] |
| 81 | + extensions = [ |
| 82 | + "myst_parser", |
| 83 | + "sphinx.ext.intersphinx", |
| 84 | + "sphinx_design", |
| 85 | + ] |
| 86 | + project = "My Notes" |
| 87 | + root_doc = "notes" |
| 88 | +
|
| 89 | + html_theme = "furo" |
| 90 | + html_title = "Notes" |
| 91 | +
|
| 92 | + intersphinx_mapping.python = [ |
| 93 | + "https://docs.python.org/3/", |
| 94 | + # Need to explicitly provide the objects.inv URL here as TOML does not |
| 95 | + # have an equivalent for `None` |
| 96 | + "https://docs.python.org/3/objects.inv" |
| 97 | + ] |
| 98 | +
|
| 99 | +Obviously beyond a certain point, you are better off just creating a ``conf.py`` file but this might be useful for providing reproducable examples when submitting bug reports! |
0 commit comments