Skip to content

Expose help and docs from device factory functions. #780

Closed

Description

@DiamondJoseph

After #597 but also relevant for the current state:

Device classes have docstrings about their capabilities/use/expected behaviour. Specific device factory functions may also have docstrings about their expected behaviour, other usage information. Some combination of these should be presented to the user when they use the python builtin help function on the device_factory_function.

Acceptance Criteria

  • After importing ixx.device, help(device) gives useful information about using the device, which may include
  • a description of any parameters that are added by our decorator and either their default or how to find their default
  • (if provided) docstring of any parameters that may be passed into the decorated function
  • (if provided) docstring of the device class that is being returned
  • (if provided) docstring of the device instance

Activity

  1. added
    documentation
    enhancement
    python
    on Sep 9, 2024
  2. DiamondJoseph commented on Sep 9, 2024

    @DiamondJoseph
    ContributorAuthor

    Note that the help method uses the docstrings generated via pydoc, which may require that we are using numpydoc style docstrings. @coretl has opinions about the verbosity.

  3. coretl commented on Sep 9, 2024

    @coretl
    Collaborator

    Note that the help method uses the docstrings generated via pydoc, which may require that we are using numpydoc style docstrings. @coretl has opinions about the verbosity.

    Really? That SO post seems to be about Spyder. help seems to just print what you wrote:

    class A:
        def google_meth(self, a: int):
            """A google style doc method.
            
            Args:
                a: The parameter
            """
        def numpy_meth(self, b: str):
            """A numpy style doc method
    
            Parameters
            ----------
            b
                The parameter
            """
    help(A)
    class A(builtins.object)
     |  Methods defined here:
     |  
     |  google_meth(self, a: int)
     |      A google style doc method.
     |      
     |      Args:
     |          a: The parameter
     |  
     |  numpy_meth(self, b: str)
     |      A numpy style doc method
     |      
     |      Parameters
     |      ----------
     |      b
     |          The parameter
    
  4. added
    Docsathon
    on Aug 26, 2025
  5. oliwenmandiamond commented on Jan 20, 2026

    @oliwenmandiamond
    Contributor

    This is what the output currently looks like when calling help on a device at the moment, e.g ipin from i03 using DeviceManager:

    Help on DeviceFactory in module dodal.beamlines.i03 object:

    ipin = class DeviceFactory(typing.Generic)
     |  ipin(factory: collections.abc.Callable[~Args, ~V2], use_factory_name: bool, timeout: float, mock: bool, skip: bool | collections.abc.Callable
    [[], bool], manager: 'DeviceManager')
     |
     |  Wrapper around a device factory (any function returning a device) that holds
     |  a reference to a device manager that can provide dependencies, along with
     |  default connection information for how the created device should be
     |  connected.
     |
     |  Method resolution order:
     |      DeviceFactory
     |      typing.Generic
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __call__(self, *args: Args.args, **kwargs: Args.kwargs) -> ~V2
     |      Call self as a function.
     |
     |  __init__(self, factory: collections.abc.Callable[~Args, ~V2], use_factory_name: bool, timeout: float, mock: bool, skip: bool | collections.ab
    c.Callable[[], bool], manager: 'DeviceManager')
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  __repr__(self) -> str
     |      Return repr(self).
     |
     |  build(self, mock: bool = False, connect_immediately: bool = False, name: str | None = None, timeout: float | None = None, **fixtures) -> ~V2
     |      Build this device, building any dependencies first
     |
     |  create(self, *args: Args.args, **kwargs: Args.kwargs) -> ~V2
     
     ...
    
    I would assume we would want something like this?
    

    help(ipin)

    """Doc string from factory function

    Simple device to get the ipin reading"""
    
  6. oliwenmandiamond commented on Jan 20, 2026

    @oliwenmandiamond
    Contributor

    After some experimenting, if I provide a doc string for my factory, it does use it

    >>> help(energy_source)
    Help on DeviceFactory in module dodal.beamlines.p60:
    
    energy_source = <energy_source: DeviceFactory() -> dodal.devices...on_analyser.base.energy_sources.DualEnergySource>
        My factory doc string
    

    So we need it to use the device doc string if not provided. If provided, add it to the bottom of the factory doc string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Docsathondocumentationenhancementpython

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions