From 3f94c77df727059ed7a3039c62157a2936df82d1 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 13 Feb 2023 13:01:38 -0800 Subject: [PATCH 1/3] Add support for typedoc v0.22 --- sphinx_js/typedoc.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index 4ef2dd81..c19ae269 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -1,11 +1,14 @@ """Converter from TypeDoc output to IR format""" +import re import subprocess from collections.abc import Sequence from errno import ENOENT +from functools import cache from inspect import isclass from json import load -from os.path import basename, join, normpath, relpath, sep, splitext +from os.path import basename, relpath, sep, splitext +from pathlib import Path from tempfile import NamedTemporaryFile from typing import Annotated, Any, Literal, TypedDict @@ -20,6 +23,21 @@ __all__ = ["Analyzer"] +@cache +def typedoc_version_info() -> tuple[tuple[int, ...], tuple[int, ...]]: + result = subprocess.run( + ["typedoc", "--version"], capture_output=True, encoding="utf8" + ) + lines = result.stdout.strip().splitlines() + m = re.search(r"TypeDoc ([0-9]+\.[0-9]+\.[0-9]+)", lines[0]) + assert m + typedoc_version = tuple(int(x) for x in m.group(1).split(".")) + m = re.search(r"TypeScript ([0-9]+\.[0-9]+\.[0-9]+)", lines[1]) + assert m + typescript_version = tuple(int(x) for x in m.group(1).split(".")) + return typedoc_version, typescript_version + + def typedoc_output( abs_source_paths: list[str], sphinx_conf_dir: str, config_path: str ) -> "Project": @@ -27,12 +45,16 @@ def typedoc_output( paths.""" command = Command("typedoc") if config_path: - command.add("--tsconfig", normpath(join(sphinx_conf_dir, config_path))) + tsconfig_path = str((Path(sphinx_conf_dir) / config_path).absolute()) + command.add("--tsconfig", tsconfig_path) + typedoc_version, _ = typedoc_version_info() + if typedoc_version >= (0, 22, 0): + command.add("--entryPointStrategy", "expand") with NamedTemporaryFile(mode="w+b") as temp: command.add("--json", temp.name, *abs_source_paths) try: - subprocess.call(command.make()) + subprocess.run(command.make()) except OSError as exc: if exc.errno == ENOENT: raise SphinxError( From d53fb97f846ee247766827fa4510ec4117cca016 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 26 Aug 2023 14:34:16 +0200 Subject: [PATCH 2/3] Test against 0.22 --- .github/workflows/ci.yml | 2 +- noxfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db804c14..9dfdc81a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: fail-fast: false matrix: python-version: ['3.10', '3.11'] - typedoc-version: ['0.20', '0.21'] + typedoc-version: ['0.20', '0.21', '0.22'] experimental: [false] name: Python ${{ matrix.python-version}} + typedoc ${{ matrix.typedoc-version }} diff --git a/noxfile.py b/noxfile.py index 1610804c..498aaa72 100644 --- a/noxfile.py +++ b/noxfile.py @@ -10,7 +10,7 @@ def tests(session: Session) -> None: @nox.session(python=["3.10", "3.11"]) -@nox.parametrize("typedoc", ["0.20", "0.21"]) +@nox.parametrize("typedoc", ["0.20", "0.21", "0.22"]) def test_typedoc(session: Session, typedoc: str) -> None: session.install("-r", "requirements_dev.txt") session.run( From 388ed902cfad21b2c3bf5d1bcc50c4bba1b570a2 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 26 Aug 2023 14:36:49 +0200 Subject: [PATCH 3/3] Fix version check --- sphinx_js/typedoc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index 273e8fb1..cb15985f 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -25,9 +25,9 @@ @cache -def typedoc_version_info() -> tuple[tuple[int, ...], tuple[int, ...]]: +def typedoc_version_info(typedoc: str) -> tuple[tuple[int, ...], tuple[int, ...]]: result = subprocess.run( - ["typedoc", "--version"], capture_output=True, encoding="utf8" + [typedoc, "--version"], capture_output=True, encoding="utf8" ) lines = result.stdout.strip().splitlines() m = re.search(r"TypeDoc ([0-9]+\.[0-9]+\.[0-9]+)", lines[0]) @@ -50,7 +50,7 @@ def typedoc_output( if config_path: tsconfig_path = str((Path(sphinx_conf_dir) / config_path).absolute()) command.add("--tsconfig", tsconfig_path) - typedoc_version, _ = typedoc_version_info() + typedoc_version, _ = typedoc_version_info(typedoc) if typedoc_version >= (0, 22, 0): command.add("--entryPointStrategy", "expand")