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

Add long names #627

Merged
merged 8 commits into from
Feb 6, 2025
Merged

Add long names #627

merged 8 commits into from
Feb 6, 2025

Conversation

aberges-SLAC
Copy link
Contributor

Description

Made changes to SignalPanel class in display module to support long_names for device signals. This approach should be pretty close to compatible with bluesky/ophyd#1187, so if & when that comes through we should only need minimal changes.

Motivation and Context

Have you ever had a screen with 30+ signals and maybe multiple subcomponent devices with identical signal names? Maybe you wanted alternative signal labels for cleaner GUI that end users can play with?

Figured some of the work I did in pcdshub/pcdsdevices#1320 could be generalized in typhos and potentially trim the fat out of my screen scripts.

Long names lets you use an optional string to replace the label_text in a signal row object added to your grid of signals. When you use a long_name, it will add the signal's dotted_name to the tooltip so you can still hover and get hutch python context.

How Has This Been Tested?

I didn't have any unit tests to run, per se, but I did test this on a variety of devices for screens we've got out in prod (and some I'm cooking in a different PR).

I was able to open the entire CRIXS MODS screen without everything crashing and burning, so that's gotta amount to something, right?

test_typhos_long_name_crixs_mods.mp4

Where Has This Been Documented?

This PR! And in the code itself

Pre-merge checklist

  • Code works interactively
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Code has been checked for threading issues (no blocking tasks in GUI thread)
  • Test suite passes locally
  • Test suite passes on GitHub Actions
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

I like the way this is implemented. I think the docs inclusion is required before merge and the other suggestion is optional.

typhos/panel.py Outdated
Comment on lines 357 to 365
# Hacky workaround until Ophyd.Component.long_name PR comes through
long_name = None
try:
if hasattr(getattr(device, attr), 'long_name'):
long_name = getattr(device, attr).long_name
except AttributeError:
# Then maybe we have a nested component and can't touch the signal
if hasattr(getattr(device, dotted_name), 'long_name'):
long_name = getattr(device, dotted_name).long_name
Copy link
Member

Choose a reason for hiding this comment

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

If this bit is a hacky workaround, and we needed it twice, it should be pulled out into its own function. After pulling out into its own function this is a reasonable thing to write a short unit test for to make sure we've covered all the cases we expect.

I'm wondering if there's some way to revise this to make it more readable but I don't have any immediate suggestions. Some of the hasattr calls probably aren't needed I guess.

Copy link
Contributor Author

@aberges-SLAC aberges-SLAC Feb 6, 2025

Choose a reason for hiding this comment

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

Agreed, it's probably worth some:

def _get_long_name(self, device, attr, dotted_name) -> str:
"""
Check if the signal has implemented a long_name and return it. Will check both the device and the component signal for the long_name if it exists.
"""
    long_name = None
    try:
            if hasattr(getattr(device, attr), 'long_name'):
                long_name = getattr(device, attr).long_name
    except AttributeError:
            # Then maybe we have a nested component and can't touch the signal
            if hasattr(getattr(device, dotted_name), 'long_name'):
                long_name = getattr(device, dotted_name).long_name
    return long_name

I think I ended up needing both hasattr due to it getting squirrelly when you build a screen with multiple component devices where the long name is actually in device.component.attr.long_name instead of device.attr.long_name — and the fact that long_name is not in the Ophyd object by default yet. Once they implement it we can probably just replace it with some try block around if getattr(device, attr).long_name instead.

Copy link
Member

@ZLLentz ZLLentz Feb 6, 2025

Choose a reason for hiding this comment

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

Missing here is the pre-release notes docs step, same as how we've done it in pcdsdevices with pre-release-notes.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah derp forgot to commit that, let me fix that after above changes

typhos/panel.py Outdated
try:
if hasattr(getattr(device, attr), 'long_name'):
long_name = getattr(device, attr).long_name
except AttributeError as ex:
Copy link
Member

@ZLLentz ZLLentz Feb 6, 2025

Choose a reason for hiding this comment

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

Small note: the pre-commit CI job is flagging ex as an unused variable and a couple instances of trailing whitespace

Comment on lines +277 to +286
device: (any)
The Ophyd.Device with component signals
attr: (str)
The str name of the signal attribute
dotted_name: (str)
The full dotted name to the signal

Returns
--------
str or None
Copy link
Member

Choose a reason for hiding this comment

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

Super petty spacing nitpick to match the other docstrings

Suggested change
device: (any)
The Ophyd.Device with component signals
attr: (str)
The str name of the signal attribute
dotted_name: (str)
The full dotted name to the signal
Returns
--------
str or None
device: (any)
The Ophyd.Device with component signals
attr: (str)
The str name of the signal attribute
dotted_name: (str)
The full dotted name to the signal
Returns
--------
str or None

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this ever got committed 👀

Copy link
Member

Choose a reason for hiding this comment

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

whoops

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 don't even remember getting this message on the commit o.O

typhos/panel.py Outdated
@@ -266,6 +266,36 @@ def _create_row_label(self, attr, dotted_name, tooltip, long_name=None):
label.setToolTip(_tooltip)
return label

def _get_long_name(self, device, attr, dotted_name) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

More pettiness: I normally wouldn't ask you to annotate, but this one is half annotated. Can you either finish the annotations or remove them?
device: typing.Any
attr: str
dotted_name: str
-> str | None

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'll remove the annotations to be more consistent with the rest of the script, although it probably wouldn't hurt to add the annotations to all of the funcs one day

ZLLentz
ZLLentz previously approved these changes Feb 6, 2025
Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

I've only got nitpicks left
If you're happy and finished we're good to go

I still like the implementations here and the result

@aberges-SLAC
Copy link
Contributor Author

I've only got nitpicks left If you're happy and finished we're good to go

I still like the implementations here and the result

Should pass the checks now, gave it the ole flake8 rundown. Passing black over it changed quite a few things so I'm gonna pass on that to save us a lot of frantic debugging

Copy link
Member

@ZLLentz ZLLentz 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 to me, let's roll
Remaining CI is an unrelated weird python 3.11 race condition that I don't need to think about today

@ZLLentz ZLLentz merged commit 3976918 into pcdshub:master Feb 6, 2025
10 of 11 checks passed
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.

3 participants