Skip to content

Commit

Permalink
Tentatively fix #728
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr committed Oct 26, 2023
1 parent 922f81e commit 854636d
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ jobs:
- name: Run docs and check extensions
run: |
tox -e testdocs
- name: Run sphinx extension tests
run: |
tox -e test-sphinx-ext
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ _trial_temp/
apidocs/
*.egg-info
.eggs
.hypothesis
__pycache__
10 changes: 7 additions & 3 deletions pydoctor/sphinx_ext/build_apidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def on_builder_inited(app: Sphinx) -> None:

# Build the API docs in temporary path.
shutil.rmtree(temp_path, ignore_errors=True)
_run_pydoctor(key, arguments)
_run_pydoctor(key, arguments, app.warningiserror)
output_path.rename(temp_path)


def _run_pydoctor(name: str, arguments: Sequence[str]) -> None:
def _run_pydoctor(name: str, arguments: Sequence[str], warningiserror:bool) -> None:
"""
Call pydoctor with arguments.
Expand All @@ -135,8 +135,12 @@ def _run_pydoctor(name: str, arguments: Sequence[str]) -> None:
with redirect_stdout(stream):
main(args=arguments)

has_warnings = False
for line in stream.getvalue().splitlines():
logger.warning(line)
has_warnings = True
logger.info(line)
if has_warnings and warningiserror:
logger.warning('Pydocor build is not clean and sphinx option -W (turn warnings into errors) is enabled.')


def _get_arguments(arguments: Sequence[str], placeholders: Mapping[str, str]) -> Sequence[str]:
Expand Down
10 changes: 10 additions & 0 deletions pydoctor/test/testpackages/epytext_syntax_error/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

"""
Title
~~~~~
Hello
~~~~~
"""
pass
2 changes: 2 additions & 0 deletions pydoctor/test/testsphinxextension/source/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
API ref
=======
43 changes: 43 additions & 0 deletions pydoctor/test/testsphinxextension/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'test-sphinx-ext'
copyright = '2023, Contributors'
author = 'Contributors'
release = '0.0.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []
templates_path = []
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = []

# ----------------------------------------------------------------------------
# Test configuration for pydoctor.sphinx_ext.build_apidocs

from pathlib import Path
extensions.append("pydoctor.sphinx_ext.build_apidocs")

_testpackages = Path(__file__).parent.parent.parent.joinpath('testpackages')

pydoctor_args = [
'--project-name=test-sphinx-ext-api',
f'--project-version={release}',
'--docformat=epytext',
'--intersphinx=https://docs.python.org/3/objects.inv',
'--html-output={outdir}/api',
f'{_testpackages / "report_trigger"}',
f'{_testpackages / "epytext_syntax_error"}',
]
21 changes: 21 additions & 0 deletions pydoctor/test/testsphinxextension/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. test-sphinx-ext documentation master file, created by
sphinx-quickstart on Thu Oct 26 13:13:53 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to test-sphinx-ext's documentation!
===========================================

.. toctree::
:maxdepth: 2
:caption: Contents:

api/index


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Empty file.
19 changes: 19 additions & 0 deletions pydoctor/test/testsphinxextension/tests/test_build_apidocs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import pathlib
from typing import List
import xml.etree.ElementTree as ET
import json

from pydoctor import __version__

BASE_DIR = pathlib.Path(os.environ.get('TOX_INI_DIR', os.getcwd())) / 'build' / 'test-sphinx-ext'

def test_rtd_pydoctor_call():
"""
With the pydoctor Sphinx extension, the pydoctor API HTML files are
generated.
"""
# The pydoctor index is generated and overwrites the Sphinx files.
with open(BASE_DIR / 'api' / 'index.html', 'r') as stream:
page = stream.read()
assert 'moduleIndex.html' in page, page
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,17 @@ commands =
echo "::endgroup::"

pytest -vv docs/tests/test.py

[testenv:test-sphinx-ext]
description = Run integration tests for the sphinx extension

extras = docs
deps = pytest

setenv =
TOX_INI_DIR = {toxinidir}

commands =

sphinx-build {posargs:} -aE -b html {toxinidir}/pydoctor/test/testsphinxextension/source {toxinidir}/build/test-sphinx-ext
pytest -vv {toxinidir}/pydoctor/test/testsphinxextension/tests/test_build_apidocs.py

0 comments on commit 854636d

Please sign in to comment.