Skip to content

Commit 17ffa2d

Browse files
committed
Fixed failure to build out of source conf.py files
Closes #293
1 parent 08e61b9 commit 17ffa2d

File tree

10 files changed

+43
-23
lines changed

10 files changed

+43
-23
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Bug Fixes
115115
Fixed an unnecessary deprecation warning being raised when running
116116
sphinx-build from the same directory as conf.py.
117117
* Fixed properties documented by Autodoc directives geting documented as methods.
118+
* `#293 <https://github.com/readthedocs/sphinx-autoapi/issues/293>`:
119+
Fixed failure to build out of source conf.py files.
120+
Configuration values using relative values are now relative to the source directory
121+
instead of relative to the conf.py file.
118122

119123

120124
V1.5.1 (2020-10-01)

autoapi/extension.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class RemovedInAutoAPI2Warning(DeprecationWarning):
5555
warnings.filterwarnings("default", category=RemovedInAutoAPI2Warning)
5656

5757

58-
def _normalise_autoapi_dirs(autoapi_dirs, confdir):
58+
def _normalise_autoapi_dirs(autoapi_dirs, srcdir):
5959
normalised_dirs = []
6060

6161
if isinstance(autoapi_dirs, str):
@@ -64,7 +64,7 @@ def _normalise_autoapi_dirs(autoapi_dirs, confdir):
6464
if os.path.isabs(path):
6565
normalised_dirs.append(path)
6666
else:
67-
normalised_dirs.append(os.path.normpath(os.path.join(confdir, path)))
67+
normalised_dirs.append(os.path.normpath(os.path.join(srcdir, path)))
6868

6969
return normalised_dirs
7070

@@ -96,7 +96,7 @@ def run_autoapi(app): # pylint: disable=too-many-branches
9696
app.config.autoapi_options.append("show-module-summary")
9797

9898
# Make sure the paths are full
99-
normalised_dirs = _normalise_autoapi_dirs(app.config.autoapi_dirs, app.confdir)
99+
normalised_dirs = _normalise_autoapi_dirs(app.config.autoapi_dirs, app.srcdir)
100100
for _dir in normalised_dirs:
101101
if not os.path.exists(_dir):
102102
raise ExtensionError(
@@ -133,11 +133,11 @@ def run_autoapi(app): # pylint: disable=too-many-branches
133133
template_dir = app.config.autoapi_template_dir
134134
if template_dir and not os.path.isabs(template_dir):
135135
if not os.path.isdir(template_dir):
136-
template_dir = os.path.join(app.confdir, app.config.autoapi_template_dir)
137-
elif app.confdir != os.getcwd():
136+
template_dir = os.path.join(app.srcdir, app.config.autoapi_template_dir)
137+
elif app.srcdir != os.getcwd():
138138
warnings.warn(
139139
"autoapi_template_dir will be expected to be "
140-
" relative to conf.py instead of "
140+
"relative to the Sphinx source directory instead of "
141141
"relative to where sphinx-build is run\n",
142142
RemovedInAutoAPI2Warning,
143143
)
@@ -173,7 +173,7 @@ def run_autoapi(app): # pylint: disable=too-many-branches
173173
def build_finished(app, exception):
174174
if not app.config.autoapi_keep_files and app.config.autoapi_generate_api_docs:
175175
normalized_root = os.path.normpath(
176-
os.path.join(app.confdir, app.config.autoapi_root)
176+
os.path.join(app.srcdir, app.config.autoapi_root)
177177
)
178178
if app.verbosity > 1:
179179
LOGGER.info(bold("[AutoAPI] ") + darkgreen("Cleaning generated .rst files"))

docs/how_to.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Simply copy whichever templates you want to customise to a local directory
1313
and edit them.
1414
To get AutoAPI to use these templates,
1515
point the :confval:`autoapi_template_dir` configuration option to your directory.
16-
It can be absolute, or relative to the root of the documentation directory
17-
(ie the directory with the ``conf.py`` file).
16+
It can be absolute, or relative to the root of the documentation source directory
17+
(ie the directory passed to ``sphinx-build``).
1818

1919
.. code-block:: python
2020
@@ -67,7 +67,7 @@ How to Configure Where Documentation Appears in the TOC Tree
6767

6868
The :confval:`autoapi_root` configuration option defines where generated documentation is output.
6969
To change where documentation is output,
70-
simply change this option to another directory relative to the ``conf.py`` file:
70+
simply change this option to another directory relative to the documentation source directory:
7171

7272
.. code-block:: python
7373

docs/reference/config.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Configuration Options
77

88
Paths (relative or absolute) to the source code that you wish to generate your API documentation from.
99
The paths are searched recursively for files matching :confval:`autoapi_file_patterns`.
10-
Relative paths should be relative to the root of the documentation directory
11-
(ie the directory with the ``conf.py`` file).
10+
Relative paths should be relative to the source directory of your documentation.
1211

1312
For Python, if a package directory is specified,
1413
the package directory itself will be included in the relative path of the children.
@@ -37,8 +36,7 @@ Configuration Options
3736

3837
A directory that has user-defined templates to override our default templates.
3938
The path can either be absolute,
40-
or relative to the root of the documentation directory
41-
(ie the directory with the ``conf.py`` file).
39+
or relative to the source directory of your documentation files.
4240
An path relative to where `sphinx-build` is run
4341
is allowed for backwards compatibility only
4442
and will be removed in a future version.
@@ -137,8 +135,7 @@ Customisation Options
137135

138136
Path to output the generated AutoAPI files into,
139137
including the generated index page.
140-
This path must be relative to the root of the documentation directory
141-
(ie the directory with the ``conf.py`` file).
138+
This path must be relative to the source directory of your documentation files.
142139
This can be used to place the generated documentation
143140
anywhere in your documentation hierarchy.
144141

docs/tutorials.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ we need to add it to the list of extensions in Sphinx's ``conf.py`` file::
3939
For Python, there is only one required configuration option that we need to set.
4040
:confval:`autoapi_dirs` tells AutoAPI which directories contain
4141
the source code to document.
42-
This can either be absolute, or relative to Sphinx's conf.py file.
42+
These can either be absolute, or relative to the source directory of
43+
your documentation files.
4344
For example, say we have a package and we have used ``sphinx-quickstart``
4445
to create a Sphinx project in a ``docs/`` folder.
4546
The directory structure might look like this:
@@ -131,7 +132,8 @@ For Go, this is::
131132

132133
The second configuration option is :confval:`autoapi_dirs`,
133134
which tells AutoAPI which directories contain the source code to document.
134-
These can either be absolute, or relative to Sphinx's `conf.py` file.
135+
These can either be absolute, or relative to the source directory of
136+
your documentation files.
135137
So if your documentation was inside a ``docs/`` directory
136138
and your source code is in an ``example`` directory one level up,
137139
you would configure :confval:`autoapi_dirs` to be::
@@ -167,7 +169,8 @@ For Javascript, this is::
167169

168170
The second configuration option is :confval:`autoapi_dirs`,
169171
which tells AutoAPI which directories contain the source code to document.
170-
These can either be absolute, or relative to Sphinx's `conf.py` file.
172+
These can either be absolute, or relative to the source directory of
173+
your documentation files.
171174
So if your documentation was inside a ``docs/`` directory
172175
and your source code is in an ``example`` directory one level up,
173176
you would configure :confval:`autoapi_dirs` to be::
@@ -196,7 +199,7 @@ By default, ``docfx`` will output metadata files into the ``_api`` path.
196199
You can configure which path to output files into by setting the path in your
197200
`docfx configuration file <https://dotnet.github.io/docfx/tutorial/docfx.exe_user_manual.html#3-docfx-json-format>`_
198201
in your project repository.
199-
For example, if your ``conf.py`` file is located inside a ``docs/`` directory:
202+
For example, if your documentation source files are located inside a ``docs/`` directory:
200203

201204
.. code:: json
202205
@@ -223,7 +226,8 @@ For .NET, this is::
223226

224227
The second configuration option is :confval:`autoapi_dirs`,
225228
which tells AutoAPI which directories contain the source code to document.
226-
These can either be absolute, or relative to Sphinx's `conf.py` file.
229+
These can either be absolute, or relative to the source directory of
230+
your documentation files.
227231
So if your documentation was inside a ``docs/`` directory
228232
and your source code is in an ``example`` directory one level up,
229233
you would configure :confval:`autoapi_dirs` to be::
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../pyexample/conf.py

tests/python/pymovedconfpy/example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../pyexample/example

tests/python/pymovedconfpy/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../pyexample/index.rst
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../pyexample/manualapi.rst

tests/python/test_pyintegration.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
)
2020

2121

22-
def rebuild(confoverrides=None, **kwargs):
22+
def rebuild(confoverrides=None, confdir=".", **kwargs):
2323
app = Sphinx(
2424
srcdir=".",
25-
confdir=".",
25+
confdir=confdir,
2626
outdir="_build/text",
2727
doctreedir="_build/.doctrees",
2828
buildername="text",
@@ -121,6 +121,17 @@ def test_show_inheritance(self, builder):
121121
assert "Bases:" in example_file
122122

123123

124+
class TestMovedConfPy(TestSimpleModule):
125+
@pytest.fixture(autouse=True, scope="class")
126+
def built(self, builder):
127+
builder(
128+
"pymovedconfpy",
129+
confdir="confpy",
130+
warningiserror=True,
131+
confoverrides={"suppress_warnings": ["app"]},
132+
)
133+
134+
124135
class TestSimpleStubModule:
125136
@pytest.fixture(autouse=True, scope="class")
126137
def built(self, builder):

0 commit comments

Comments
 (0)