Skip to content

Commit 1266c42

Browse files
committed
Use pathlib in sys.path manipulation examples
1 parent fbb2307 commit 1266c42

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

doc/development/tutorials/extending_build.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ For example:
313313

314314
.. code-block:: python
315315
316-
import os
317316
import sys
317+
from pathlib import Path
318318
319-
sys.path.append(os.path.abspath("./_ext"))
319+
sys.path.append(str(Path('_ext').resolve()))
320320
321321
extensions = ['todo']
322322

doc/development/tutorials/extending_syntax.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ For example:
169169

170170
.. code-block:: python
171171
172-
import os
173172
import sys
173+
from pathlib import Path
174174
175-
sys.path.append(os.path.abspath("./_ext"))
175+
sys.path.append(str(Path('_ext').resolve()))
176176
177177
extensions = ['helloworld']
178178

doc/usage/configuration.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,14 @@ General configuration
223223

224224
Ensure that absolute paths are used when modifying :data:`sys.path`.
225225
If your custom extensions live in a directory that is relative to the
226-
:term:`configuration directory`, use :func:`os.path.abspath` like so:
226+
:term:`configuration directory`, use :meth:`pathlib.Path.resolve` like so:
227227

228228
.. code-block:: python
229229
230-
import os, sys; sys.path.append(os.path.abspath('sphinxext'))
230+
import sys
231+
from pathlib import Path
232+
233+
sys.path.append(str(Path('sphinxext').resolve()))
231234
232235
extensions = [
233236
...

doc/usage/extensions/index.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ Where to put your own extensions?
6969
Extensions local to a project should be put within the project's directory
7070
structure. Set Python's module search path, ``sys.path``, accordingly so that
7171
Sphinx can find them. For example, if your extension ``foo.py`` lies in the
72-
``exts`` subdirectory of the project root, put into :file:`conf.py`::
72+
``exts`` subdirectory of the project root, put into :file:`conf.py`:
7373

74-
import sys, os
74+
.. code-block:: python
7575
76-
sys.path.append(os.path.abspath('exts'))
76+
import sys
77+
from pathlib import Path
78+
79+
sys.path.append(str(Path('exts').resolve()))
7780
7881
extensions = ['foo']
7982

0 commit comments

Comments
 (0)