Skip to content

Conversation

@oliwenmandiamond
Copy link
Contributor

@oliwenmandiamond oliwenmandiamond commented Jan 20, 2026

Fixes #780

Examples

Device without documentation

>>> help(beamsize)
Help on DeviceFactory in module dodal.beamlines.i03:

beamsize = <beamsize: DeviceFactory(aperture_scatterguard: ...terguard) -> dodal.devices.i03.beamsize.Beamsize>
    Beamsize:
    
    No documentation available.

>>> 

Device with documentation

>>> help(robot)
Help on DeviceFactory in module dodal.beamlines.i03:

robot = <robot: DeviceFactory() -> dodal.devices.robot.BartRobot>
    BartRobot:
    
    The sample changing robot.

>>> 

Device with factory documentation and device documentation

>>> help(panda_fast_grid_scan)
Help on DeviceFactory in module dodal.beamlines.i03:

panda_fast_grid_scan = <panda_fast_grid_scan: DeviceFactory() -> dodal.devices.fast_grid_scan.PandAFastGridScan>
    This is used instead of the zebra_fast_grid_scan device when using the PandA.
    
    PandAFastGridScan:
    
    Device for panda constant-motion scan.
    
        In this scan, the goniometer's velocity
        is constant through each row. It doesn't slow down when going through trigger points.

>>> 

Instructions to reviewer on how to test:

  1. Check new tests make sense
  2. Check tests pass

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

@oliwenmandiamond oliwenmandiamond requested a review from a team as a code owner January 20, 2026 13:49
@oliwenmandiamond oliwenmandiamond changed the title Device manager adds device doc string to factory method DeviceManager adds device doc string to factory method Jan 20, 2026
@DominicOram
Copy link
Contributor

I was literally just thinking of doing this

@oliwenmandiamond
Copy link
Contributor Author

I was literally just thinking of doing this

Saved you the work 😄

Copy link
Collaborator

@dan-fernandes dan-fernandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good once the failing tests are sorted

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.05%. Comparing base (d8e8aab) to head (6ada650).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1829      +/-   ##
==========================================
- Coverage   99.06%   99.05%   -0.01%     
==========================================
  Files         290      290              
  Lines       11092    11107      +15     
==========================================
+ Hits        10988    11002      +14     
- Misses        104      105       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


assert OphydV2Device.__doc__ is not None
assert (
foo.__doc__ == f"{OphydV2Device.__name__}:\n\n{cleandoc(OphydV2Device.__doc__)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(here and below)
Replicating the implementation using f-strings here doesn't really test anything. It would be better if the expected values were normal literals.

To avoid depending on the docs of Device, it might be useful to have a DocsDevice to go with the NoDocsDevice with docs that won't change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reused the _type_docs function in the tests which I think makes it much cleaner now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still defeats the point of the test though. They're now effectively assert make_docs(func) == make_docs(func)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, it still checks to make sure the formatting of the docs is still called through this function.

Would me adding another test specifically for _type_docs works as expected be suitable enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help, but raises the question of whether private functions should be tested directly or only via the things that call them. I still think it would be useful for the tests to include an example of what the full docs should look like but I'll leave it up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the additional tests. I personally think it is sufficient but let me know what you think

oliwenmandiamond and others added 3 commits January 21, 2026 13:48
Co-authored-by: Peter Holloway <peter.holloway@diamond.ac.uk>
Co-authored-by: Peter Holloway <peter.holloway@diamond.ac.uk>
return _type_docs(return_type)


def _type_docs(target: type[V1 | V2], extra_docs: str = "") -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By making this take extra_docs the type_docs name is no longer correct and it re-introduces another string comparison. Is there a benefit to moving the concatenation out of the format method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes the function much more reusable with the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the other comment about testing private functions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose help and docs from device factory functions.

5 participants