From 44a1a39f55afb678aa2d7e02770ea79f3095b50d Mon Sep 17 00:00:00 2001 From: tristanlatr <19967168+tristanlatr@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:53:17 -0400 Subject: [PATCH] Fix CI (#730) * Require Sphinx<7.0.0 for the tests. * Twisted does not support python 3.7 anymore * Fix introspection code for cython3 generated functions * Remove deprecated key in readthedocs.yml config file --- .github/workflows/unit.yaml | 2 +- README.rst | 1 + pydoctor/model.py | 7 +++++-- pydoctor/sphinx_ext/build_apidocs.py | 4 ++-- pydoctor/templatewriter/__init__.py | 5 ++--- pydoctor/test/test_sphinx.py | 2 +- readthedocs.yml | 7 +++++-- setup.cfg | 4 ++-- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml index 751e089e1..eb1fc3c87 100644 --- a/.github/workflows/unit.yaml +++ b/.github/workflows/unit.yaml @@ -46,7 +46,7 @@ jobs: tox -e test - name: Run unit tests with latest Twisted version - if: matrix.python-version != '3.6' && matrix.python-version != 'pypy-3.6' + if: matrix.python-version != '3.7' && matrix.python-version != '3.6' && matrix.python-version != 'pypy-3.6' run: | tox -e test-latest-twisted diff --git a/README.rst b/README.rst index acf43a21a..48a8df2ce 100644 --- a/README.rst +++ b/README.rst @@ -88,6 +88,7 @@ in development * Improve the class hierarchy such that it links top level names with intersphinx when possible. * Add highlighting when clicking on "View In Hierarchy" link from class page. * Recognize variadic generics type variables (PEP 646). +* Fix support for introspection of cython3 generated modules. pydoctor 23.4.1 ^^^^^^^^^^^^^^^ diff --git a/pydoctor/model.py b/pydoctor/model.py index 8d0d6c2ba..310529fe0 100644 --- a/pydoctor/model.py +++ b/pydoctor/model.py @@ -1257,8 +1257,11 @@ def _introspectThing(self, thing: object, parent: CanContainImportsDocumentable, for k, v in thing.__dict__.items(): if (isinstance(v, func_types) # In PyPy 7.3.1, functions from extensions are not - # instances of the abstract types in func_types - or (hasattr(v, "__class__") and v.__class__.__name__ == 'builtin_function_or_method')): + # instances of the abstract types in func_types, it will have the type 'builtin_function_or_method'. + # Additionnaly cython3 produces function of type 'cython_function_or_method', + # so se use a heuristic on the class name as a fall back detection. + or (hasattr(v, "__class__") and + v.__class__.__name__.endswith('function_or_method'))): f = self.Function(self, k, parent) f.parentMod = parentMod f.docstring = v.__doc__ diff --git a/pydoctor/sphinx_ext/build_apidocs.py b/pydoctor/sphinx_ext/build_apidocs.py index a5b828885..74b1b501b 100644 --- a/pydoctor/sphinx_ext/build_apidocs.py +++ b/pydoctor/sphinx_ext/build_apidocs.py @@ -49,7 +49,7 @@ def on_build_finished(app: Sphinx, exception: Exception) -> None: runs = app.config.pydoctor_args placeholders = { - 'outdir': app.outdir, + 'outdir': str(app.outdir), } if not isinstance(runs, Mapping): @@ -86,7 +86,7 @@ def on_builder_inited(app: Sphinx) -> None: raise ConfigError("Missing 'pydoctor_args'.") placeholders = { - 'outdir': app.outdir, + 'outdir': str(app.outdir), } runs = config.pydoctor_args diff --git a/pydoctor/templatewriter/__init__.py b/pydoctor/templatewriter/__init__.py index ffaff07a1..7a158a57d 100644 --- a/pydoctor/templatewriter/__init__.py +++ b/pydoctor/templatewriter/__init__.py @@ -1,5 +1,5 @@ """Render pydoctor data as HTML.""" -from typing import Any, Iterable, Iterator, Optional, Union, cast, TYPE_CHECKING +from typing import Any, Iterable, Iterator, Optional, Union, TYPE_CHECKING if TYPE_CHECKING: from typing_extensions import Protocol, runtime_checkable else: @@ -38,8 +38,7 @@ def parse_xml(text: str) -> minidom.Document: Create a L{minidom} representaton of the XML string. """ try: - # TODO: submit a PR to typeshed to add a return type for parseString() - return cast(minidom.Document, minidom.parseString(text)) + return minidom.parseString(text) except Exception as e: raise ValueError(f"Failed to parse template as XML: {e}") from e diff --git a/pydoctor/test/test_sphinx.py b/pydoctor/test/test_sphinx.py index d05274c04..d71e0caf5 100644 --- a/pydoctor/test/test_sphinx.py +++ b/pydoctor/test/test_sphinx.py @@ -110,7 +110,7 @@ def test_generate_empty_functional() -> None: @contextmanager def openFileForWriting(path: str) -> Iterator[io.BytesIO]: yield output - inv_writer._openFileForWriting = openFileForWriting # type: ignore[assignment] + inv_writer._openFileForWriting = openFileForWriting # type: ignore inv_writer.generate(subjects=[], basepath='base-path') diff --git a/readthedocs.yml b/readthedocs.yml index 6802034a9..1a1beb95b 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -4,9 +4,12 @@ version: 2 sphinx: fail_on_warning: false +build: + os: ubuntu-22.04 + tools: + python: "3.11" + python: - version: 3.8 - system_packages: false install: - method: pip path: . diff --git a/setup.cfg b/setup.cfg index 8b10c2cb5..1f00cc431 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,9 +66,9 @@ test = coverage pytest hypothesis - cython-test-exception-raiser==1.0.0 + cython-test-exception-raiser bs4 - Sphinx>=3.5 + Sphinx<7.0.0 pytest-subtests [options.entry_points]