Skip to content

Commit 51d0ca0

Browse files
committed
docs: Document single file usage
1 parent 0a40747 commit 51d0ca0

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

docs/lsp/howto.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ This section contains a number of guides to help you get the most out of Esbonio
1010

1111
Configure the Sphinx Build Command <howto/configure-the-sphinx-build-cmd>
1212
Configure the Sphinx Build Environment <howto/configure-the-sphinx-build-env>
13+
Use Esbonio Without a Sphinx Project <howto/use-esbonio-without-sphinx-project>
1314
Migrate to v1 <howto/migrate-to-v1>

docs/lsp/howto/configure-the-sphinx-build-env.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,49 @@ Then you should set :esbonio:conf:`esbonio.sphinx.pythonCommand` to
9090
[tool.esbonio.sphinx]
9191
pythonCommand = ["poetry", "run", "python"]
9292
93+
uv
94+
---
95+
96+
If you use `uv <https://docs.astral.sh/uv/>`__ and a ``pyproject.toml`` file to manage your dependencies
97+
98+
.. code-block:: toml
99+
100+
[project]
101+
dependencies = [
102+
"attrs>=24.3.0",
103+
"cattrs>=23.1.2",
104+
"lsprotocol==2025.0.0",
105+
]
106+
107+
[dependency-groups]
108+
docs = [
109+
"furo>=2024.8.6",
110+
"myst-parser>=2.0",
111+
"sphinx>=7.1.2",
112+
"sphinx-design>=0.5.0",
113+
]
114+
115+
Then you should set :esbonio:conf:`esbonio.sphinx.pythonCommand` to
116+
117+
.. code-block:: toml
118+
119+
[tool.esbonio.sphinx]
120+
pythonCommand = ["uv", "run", "--group", "docs", "python"]
121+
122+
Alternatively, you can specify the dependencies direct in the ``uv run`` command
123+
124+
.. code-block:: toml
125+
126+
[tool.esbonio.sphinx]
127+
pythonCommand = [
128+
"uv", "run", "--no-project",
129+
"--with", "sphinx",
130+
"--with", "myst-parser",
131+
"python"
132+
]
133+
134+
Just don't forget the ``--no-project`` flag, otherwise ``uv`` will attempt to include dependencies from the ``pyproject.toml`` file also!
135+
93136
venv / virtualenv
94137
-----------------
95138

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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!

lib/esbonio/changes/997.doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add guide on using the `-C` flag to `sphinx-build` to allow the use of esbonio with files that aren't in a Sphinx project.

0 commit comments

Comments
 (0)