Skip to content

Commit

Permalink
Add typedoc 0.26 to CI (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Dec 21, 2024
1 parent 1428f15 commit 98493c2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.12"]
typedoc-version: ["0.25"]
typedoc-version: ["0.25", "0.26"]

name: Python ${{ matrix.python-version}} + typedoc ${{ matrix.typedoc-version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: "3.11"
python: "3.12"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
Expand Down
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def tests(session: Session) -> None:


@nox.session(python=["3.12"])
@nox.parametrize("typedoc", ["0.25"])
@nox.parametrize("typedoc", ["0.25", "0.26"])
def test_typedoc(session: Session, typedoc: str) -> None:
session.install("-r", "requirements_dev.txt")
venvroot = Path(session.bin).parent
Expand All @@ -32,6 +32,8 @@ def test_typedoc(session: Session, typedoc: str) -> None:
session.run(
"npm", "i", "--no-save", "[email protected]", f"typedoc@{typedoc}", external=True
)
session.run("npx", "tsc", "--version", external=True)
session.run("npx", "typedoc", "--version", external=True)
session.run("pytest", "--junitxml=test-results.xml", "-k", "not js")


Expand Down
3 changes: 2 additions & 1 deletion sphinx_js/js/convertType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ class TypeConverter implements TypeVisitor<Type> {
return this.convertSignature(lit.signatures[0]);
}
const result: Type = ["{ "];
const index_sig = lit.indexSignature;
// lit.indexSignature for 0.25.x, lit.indexSignatures for 0.26.0 and later.
const index_sig = lit.indexSignature ?? lit.indexSignatures?.[0];
if (index_sig) {
if (index_sig.parameters?.length !== 1) {
throw new Error("oops");
Expand Down
11 changes: 9 additions & 2 deletions sphinx_js/js/redirectPrivateAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ export function redirectPrivateTypes(app: Application): ReadonlySymbolToType {
const referencedSymbols = new Map<Reflection, Set<ts.Symbol>>();
const knownPrograms = new Map<Reflection, ts.Program>();
const symbolToType: SymbolToType = new Map<`${string}:${number}`, SomeType>();

app.converter.on(
Converter.EVENT_CREATE_DECLARATION,
(context: Context, refl: Reflection) => {
// TypeDoc 0.26 doesn't fire EVENT_CREATE_DECLARATION for project
// We need to ensure the project has a program attached to it, so
// do that when the first declaration is created.
if (knownPrograms.size === 0) {
knownPrograms.set(refl.project, context.program);
}
if (refl.kindOf(ModuleLike)) {
knownPrograms.set(refl, context.program);
}
Expand Down Expand Up @@ -136,7 +141,9 @@ export function redirectPrivateTypes(app: Application): ReadonlySymbolToType {
if (ts.isTypeAliasDeclaration(decl)) {
const sf = decl.getSourceFile();
const fileName = sf.fileName;
const pos = decl.pos;
const pos = Application.VERSION.startsWith("0.25")
? decl.pos
: decl.getStart();
const converted = context.converter.convertType(context, decl.type);
// Depending on whether we have a symbolId or a reflection in
// renderType we'll use different keys to look this up.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function exampleFunction() {}
export async function asyncFunction() {}

export class Iterable {
*[Symbol.iterator](): Iterator<number> {
*[Symbol.iterator](): Iterator<number, any, undefined> {
yield 1;
yield 2;
yield 3;
Expand Down
29 changes: 12 additions & 17 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from textwrap import dedent

from bs4 import BeautifulSoup, Tag
from conftest import TYPEDOC_VERSION

from tests.testing import SphinxBuildTestCase

Expand Down Expand Up @@ -45,17 +44,15 @@ def test_abstract_extends_and_implements(self):
These are all TypeScript-specific features.
"""
CLASS_COMMENT = (
" A definition of a class\n\n" if TYPEDOC_VERSION >= (0, 23, 0) else ""
)

# The quotes around ClassDefinition must be some weird decision in
# Sphinx's text output. I don't care if they go away in a future
# version of Sphinx. It doesn't affect the HTML output.
self._file_contents_eq(
"autoclass_class_with_interface_and_supers",
"class ClassWithSupersAndInterfacesAndAbstract()\n"
"\n" + CLASS_COMMENT + " *abstract*\n"
"\n"
" A definition of a class\n\n"
" *abstract*\n"
"\n"
' *exported from* "class"\n'
"\n"
Expand Down Expand Up @@ -156,21 +153,19 @@ def test_async(self):
)

def test_symbol(self):
self._file_contents_eq(
"symbol",
dedent(
"""\
class Iterable()
expected = dedent(
"""\
class Iterable()
*exported from* "class"
*exported from* "class"
Iterable.[Symbol․iterator]()
Iterable.[Symbol․iterator]()
Returns:
Iterator<number, any, undefined>
"""
),
Returns:
Iterator<number, any, undefined>
"""
)
self._file_contents_eq("symbol", expected)

def test_predicate(self):
self._file_contents_eq(
Expand Down
7 changes: 5 additions & 2 deletions tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest
from conftest import TYPEDOC_VERSION
from sphinx.errors import SphinxError

from sphinx_js.analyzer_utils import search_node_modules
Expand Down Expand Up @@ -89,12 +90,14 @@ def test_err():
search_node_modules("my_program", my_prog_path, "/a/b/c")


@pytest.mark.xfail(reason="Isn't working right now. Not sure why.")
def test_global_install(tmp_path_factory, monkeypatch):
tmpdir = tmp_path_factory.mktemp("global_root")
tmpdir2 = tmp_path_factory.mktemp("blah")
monkeypatch.setenv("npm_config_prefix", str(tmpdir))
monkeypatch.setenv("PATH", str(tmpdir / "bin"), prepend=":")
subprocess.run(["npm", "i", "-g", "[email protected]", "typescript", "[email protected]"])
version = ".".join(str(x) for x in TYPEDOC_VERSION)
subprocess.run(["npm", "i", "-g", f"typedoc@{version}", "typescript"])
typedoc = search_node_modules("typedoc", "typedoc/bin/typedoc", str(tmpdir2))
monkeypatch.setenv("TYPEDOC_NODE_MODULES", str(Path(typedoc).parents[3]))
dir = Path(__file__).parents[1].resolve() / "sphinx_js/js"
Expand All @@ -114,4 +117,4 @@ def test_global_install(tmp_path_factory, monkeypatch):
print(res.stdout)
print(res.stderr)
res.check_returncode()
assert "TypeDoc 0.25" in res.stdout
assert f"TypeDoc {version}" in res.stdout
6 changes: 2 additions & 4 deletions tests/test_typedoc_analysis/test_typedoc_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ def test_properties(self):
m
for m in cls.members
if isinstance(m, Attribute)
and m.name
in ["someStatic", "someOptional", "somePrivate", "someNormal"]
and m.name in ["someStatic", "someOptional", "someNormal"]
]
)
== 4
== 3
)

# The unique things about properties (over and above Variables) are set
Expand All @@ -341,7 +340,6 @@ def get_prop(delim: str, val: str) -> Attribute:

assert get_prop(".", "someStatic").is_static
assert get_prop("#", "someOptional").is_optional
assert get_prop("#", "somePrivate").is_private
normal_property = get_prop("#", "someNormal")
assert (
not normal_property.is_optional
Expand Down

0 comments on commit 98493c2

Please sign in to comment.