diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7177eed..07a81dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: # set -e # pip install --upgrade pip # pip install sphinx_rust --find-links dist --force-reinstall - # pip install pytest pytest-param-files + # pip install pytest # pytest # - name: pytest # if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }} @@ -68,7 +68,7 @@ jobs: # install: | # apt-get update # apt-get install -y --no-install-recommends python3-dev python3-pip build-essential - # pip3 install -U pip pytest pytest-param-files + # pip3 install -U pip pytest # run: | # set -e # pip3 install sphinx_rust --find-links dist --force-reinstall @@ -104,7 +104,7 @@ jobs: # set -e # pip install --upgrade pip # pip install sphinx_rust --find-links dist --force-reinstall - # pip install pytest pytest-param-files + # pip install pytest # pytest macos: @@ -136,7 +136,7 @@ jobs: # set -e # pip install --upgrade pip # pip install sphinx_rust --find-links dist --force-reinstall - # pip install pytest pytest-param-files + # pip install pytest # pytest sdist: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 537d28c..3ad4e84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -74,11 +74,11 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - run: pip install -e .[testing] + - run: pip install -e .[test] env: RUST_BACKTRACE: 1 - run: pip freeze - # - run: pytest + - run: pytest check: if: always() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 39fe3ed..4fb96fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,6 +38,12 @@ To run the analysis CLI tool: tox -e dev -- python -m sphinx_rust.cli crates/py_binding --overwrite ``` +To run the pytest tests: + +```bash +tox -e test-py39 +``` + To build the documentation: ```bash diff --git a/pyproject.toml b/pyproject.toml index 5398e16..f7c81a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dynamic = ["version"] description = "Sphinx plugin for documentation of Rust projects." authors = [{ name = "Chris Sewell", email = "chrisj_sewell@hotmail.com" }] readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" license = { file = "LICENSE" } keywords = [ "sphinx", @@ -26,7 +26,6 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -47,9 +46,12 @@ Documentation = "http://sphinx-rust.readthedocs.io" [project.optional-dependencies] dev = [ - "pytest", "ipython" ] +test = [ + "pytest", + "defusedxml", +] docs = [ "furo", "myst-parser", @@ -111,6 +113,16 @@ allowlist_externals = bash commands_pre = bash -c "unset CONDA_PREFIX; maturin develop" commands = {posargs:ipython} +[testenv:test-{py39,py310,py311,py312}] +extras = test +passenv = TERM +; ensure that the compilation is up-to-date +; There is an issue with mixing maturin with tox-conda, raising: +; Both VIRTUAL_ENV and CONDA_PREFIX are set. Please unset one of them +allowlist_externals = bash +commands_pre = bash -c "unset CONDA_PREFIX; maturin develop" +commands = pytest {posargs} + [testenv:docs] extras = docs passenv = TERM diff --git a/python/sphinx_rust/domain.py b/python/sphinx_rust/domain.py index 27c3430..4943a05 100644 --- a/python/sphinx_rust/domain.py +++ b/python/sphinx_rust/domain.py @@ -104,6 +104,7 @@ def on_builder_inited(app: Sphinx) -> None: LOGGER.warning( f"Error analyzing crate: {e!s}", type="rust", subtype="analyze" ) + return create_pages(srcdir, result) @property diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..0d98ab3 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +pytest_plugins = ["sphinx.testing.fixtures"] diff --git a/tests/test_sphinx_build.py b/tests/test_sphinx_build.py new file mode 100644 index 0000000..e93b5bb --- /dev/null +++ b/tests/test_sphinx_build.py @@ -0,0 +1,42 @@ +"""Simple test to build sphinx documentation.""" + +from __future__ import annotations + +from pathlib import Path +from textwrap import dedent + +from sphinx.testing.util import SphinxTestApp +from sphinx.util.console import strip_colors + + +def test_basic(make_app: type[SphinxTestApp], tmp_path: Path) -> None: + """Basic sphinx build test.""" + tmp_path.joinpath("Cargo.toml").write_text( + dedent("""\ + [package] + name = "test" + version = "0.1.0" + [lib] + """) + ) + tmp_path.joinpath("conf.py").write_text( + dedent("""\ + extensions = ['sphinx_rust'] + rust_crates = ['.'] + """) + ) + tmp_path.joinpath("index.rst").write_text( + dedent("""\ + Test + ==== + .. toctree:: api/crates/test/index + """) + ) + + app = make_app("html", srcdir=tmp_path) + app.build() + assert strip_colors(app.warning.getvalue()) == "" # noqa: PLC1901 + + assert ( + Path(str(app.outdir)).joinpath("api", "crates", "test", "index.html").exists() + )