Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Add slicer.parameterNodeWrapper autodocs #6876

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

allemangD
Copy link
Contributor

Add slicer.parameterNodeWrapper automodule to the Slicer Python API documentation.


Currently this fails because sphinx does not have access to the extension types in the Slicer namespace. See #6875 for more details.

@jcfr
Copy link
Member

jcfr commented Mar 13, 2023

The following error is reported on readthedocs:

WARNING: autodoc: failed to import module 'parameterNodeWrapper' from module 'slicer'; the following exception was raised:
cannot import name 'Annotated' from 'typing' (/home/docs/.pyenv/versions/3.7.9/lib/python3.7/typing.py)

This happens because the Annotated type was introduced1 in Python 3.9 and readthedocs currently uses Python 3.7.

Footnotes

  1. https://docs.python.org/3/library/typing.html#typing.Annotated

@jcfr
Copy link
Member

jcfr commented Mar 13, 2023

The generation is currently failing with the following error:

WARNING: autodoc: failed to import module 'parameterNodeWrapper' from module 'slicer'; the following exception was raised:
Traceback (most recent call last):
  [...]
  File "/home/jcfr/Projects/Slicer/Base/Python/slicer/parameterNodeWrapper/__init__.py", line 5, in <module>
    from .guiConnectors import *
  File "/home/jcfr/Projects/Slicer/Base/Python/slicer/parameterNodeWrapper/guiConnectors.py", line 16, in <module>
    from . import parameterPack as pack
  File "/home/jcfr/Projects/Slicer/Base/Python/slicer/parameterNodeWrapper/parameterPack.py", line 10, in <module>
    from .serializers import (
  File "/home/jcfr/Projects/Slicer/Base/Python/slicer/parameterNodeWrapper/serializers.py", line 402, in <module>
    class NodeSerializer(Serializer):
  File "/home/jcfr/Projects/Slicer/Base/Python/slicer/parameterNodeWrapper/serializers.py", line 424, in NodeSerializer
    def write(self, parameterNode, name: str, value: slicer.vtkMRMLNode) -> None:
AttributeError: module 'slicer' has no attribute 'vtkMRMLNode'

@jcfr jcfr force-pushed the parameter-node-wrapper-autodoc branch 2 times, most recently from 3c4066f to f4195e3 Compare March 15, 2023 07:06
@jcfr jcfr added the Type: Documentation Issues regarding documentation label Aug 17, 2023
@jcfr jcfr force-pushed the parameter-node-wrapper-autodoc branch from f4195e3 to 1beee3f Compare November 2, 2023 03:24
@jcfr jcfr added the Status: Draft This pull-request is not yet ready for integration label Nov 11, 2023
allemangD and others added 6 commits December 5, 2023 11:38
This commit allows to successfully import the package from a standalone
python console (e.g PythonSlicer).

Supporting this is helpful in the context of documentation generation and
IDE integration.
…ment

This commit fixes the error reported below by ensuring the path to the
"slicer" package available in the source tree is prepended only if
not already available from the Slicer Python environment where modules
like MRMLCorePython have been successfully imported.

Note that since "slicer.kits" is only available in the Slicer Python environment,
its presence usually indicates that (1) the slicer module is available and
(2) the kits (mrml, vtkAddon, vtkSegmentationCore, ..) have been imported.

Error:

WARNING: autodoc: failed to import module 'parameterNodeWrapper' from module 'slicer'; the following exception was raised:
Traceback (most recent call last):
  [...]
  File "/path/to/Slicer/Base/Python/slicer/parameterNodeWrapper/__init__.py", line 5, in <module>
    from .guiConnectors import *
  File "/path/to/Slicer/Base/Python/slicer/parameterNodeWrapper/guiConnectors.py", line 16, in <module>
    from . import parameterPack as pack
  File "/path/to/Slicer/Base/Python/slicer/parameterNodeWrapper/parameterPack.py", line 10, in <module>
    from .serializers import (
  File "/path/to/Slicer/Base/Python/slicer/parameterNodeWrapper/serializers.py", line 402, in <module>
    class NodeSerializer(Serializer):
  File "/path/to/Slicer/Base/Python/slicer/parameterNodeWrapper/serializers.py", line 424, in NodeSerializer
    def write(self, parameterNode, name: str, value: slicer.vtkMRMLNode) -> None:
AttributeError: module 'slicer' has no attribute 'vtkMRMLNode'
Since mrml and vtkAddon classes are associated with the slicer package,
they should be documented accordingly.
@jcfr jcfr force-pushed the parameter-node-wrapper-autodoc branch from 1beee3f to 46ef80c Compare December 5, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Draft This pull-request is not yet ready for integration Type: Documentation Issues regarding documentation
Development

Successfully merging this pull request may close these issues.

None yet

2 participants