mkdocstrings / typescript

A TypeScript handler for mkdocstrings. Available to sponsors only.
https://mkdocstrings.github.io/typescript
ISC License
1 stars 0 forks source link

TypeError: Project.__init__() got an unexpected keyword argument 'files' #2

Closed adaxi closed 1 week ago

adaxi commented 1 week ago

When I attempt to build my documentation I get the following error:

INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /home/gbo/Workspaces/reproducer/docs/site
[info] Loaded plugin typedoc-material-theme
[info] Documentation generated at ./site/typedoc
INFO    -  griffe_typedoc: JSON written to /tmp/tmp7i_xda5m
ERROR   -  Error reading page 'index.md': Project.__init__() got an unexpected keyword argument 'files'
Traceback (most recent call last):
  File "/home/gbo/Workspaces/reproducer/docs/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.render(config, files)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/structure/pages.py", line 285, in render
    self.content = md.convert(self.markdown)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 128, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 216, in _process_block
    data: CollectorItem = handler.collect(identifier, options)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings_handlers/typescript/handler.py", line 124, in collect
    data = load_typedoc(["typedoc"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/loader.py", line 59, in load
    return json.load(tmpfile, cls=TypedocDecoder)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 293, in load
    return loads(fp.read(),
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 538, in _object_hook
    return _loader_map[kind](obj_dict, self._symbol_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 69, in wrapper
    obj = func(obj_dict)
          ^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 86, in _load_project
    return Project(**obj_dict)
           ^^^^^^^^^^^^^^^^^^^
TypeError: Project.__init__() got an unexpected keyword argument 'files'

Attached you can find a reproducer: reproducer.tar.gz

To reproduce:

tar -zxf reproducer.tar.gz
cd reproducer/docs
python -m venv .venv
.venv/bin/pip install -r requirements.txt
npm install
.venv/bin/mkdocs build

The reproducer includes all the plugins I am currently using. Note that I am also also includes the typedoc plugin which generates typedoc documentation on the side, though this one does not seem to be interfering with mkdocstrings-typescript.

pawamoy commented 1 week ago

Thanks a lot for the report and reproduction!

Strangely, I get a different error from you:

TypeError: Project.init() missing 1 required keyword-only argument: 'readme'

I believe I can simply make the readme parameter optional, and add an optional files parameter too, to resolve both issues.

pawamoy commented 1 week ago

Could you somehow give me more information about this files argument that seems to be passed to Project :thinking:? You can probably either run a Python debugger, or generate the JSON output with typedoc by running it manually, and checking the resulting JSON to see what these files are (list of paths?).

pawamoy commented 1 week ago

Ah, I now get the same error as you (fixed my setup, had typedoc installed globally).

pawamoy commented 1 week ago
{'entries': {'1': '../sdk/src/index.ts'}, 'reflections': {'1': 0}}

https://typedoc.org/api/interfaces/JSONOutput.FileRegistry.html#entries

pawamoy commented 1 week ago

OK I've pushed new commits (and tags) for both griffe-typedoc and mkdocstrings-typescript (insiders versions). This shouldn't crash anymore.

adaxi commented 1 week ago

Thank you for the quick reaction time, has solved this issue :)