mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use pathlib in `sys.path` manipulation examples
This commit is contained in:
@@ -313,10 +313,10 @@ For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(os.path.abspath("./_ext"))
|
||||
sys.path.append(str(Path('_ext').resolve()))
|
||||
|
||||
extensions = ['todo']
|
||||
|
||||
|
||||
@@ -169,10 +169,10 @@ For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(os.path.abspath("./_ext"))
|
||||
sys.path.append(str(Path('_ext').resolve()))
|
||||
|
||||
extensions = ['helloworld']
|
||||
|
||||
|
||||
@@ -223,11 +223,14 @@ General configuration
|
||||
|
||||
Ensure that absolute paths are used when modifying :data:`sys.path`.
|
||||
If your custom extensions live in a directory that is relative to the
|
||||
:term:`configuration directory`, use :func:`os.path.abspath` like so:
|
||||
:term:`configuration directory`, use :meth:`pathlib.Path.resolve` like so:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import os, sys; sys.path.append(os.path.abspath('sphinxext'))
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(str(Path('sphinxext').resolve()))
|
||||
|
||||
extensions = [
|
||||
...
|
||||
|
||||
@@ -69,11 +69,14 @@ Where to put your own extensions?
|
||||
Extensions local to a project should be put within the project's directory
|
||||
structure. Set Python's module search path, ``sys.path``, accordingly so that
|
||||
Sphinx can find them. For example, if your extension ``foo.py`` lies in the
|
||||
``exts`` subdirectory of the project root, put into :file:`conf.py`::
|
||||
``exts`` subdirectory of the project root, put into :file:`conf.py`:
|
||||
|
||||
import sys, os
|
||||
.. code-block:: python
|
||||
|
||||
sys.path.append(os.path.abspath('exts'))
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(str(Path('exts').resolve()))
|
||||
|
||||
extensions = ['foo']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user