-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use ophyd-async 0.9a2 #770
Changes from all commits
0d13004
ef37d16
85736ee
ba0a6c2
ee40243
402efca
a2ce83f
e6ea813
27fc769
d872de1
fa55104
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from ophyd_async.core import YamlSettingsProvider | ||
from ophyd_async.fastcs.panda import HDFPanda | ||
from ophyd_async.plan_stubs import apply_panda_settings, retrieve_settings | ||
|
||
|
||
def load_panda_from_yaml(yaml_directory: str, yaml_file_name: str, panda: HDFPanda): | ||
provider = YamlSettingsProvider(yaml_directory) | ||
settings = yield from retrieve_settings(provider, yaml_file_name, panda) | ||
yield from apply_panda_settings(settings) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
|
||
# Change once Python<3.12 is dropped - see https://github.com/DiamondLightSource/mx-bluesky/issues/798 | ||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
from datetime import datetime | ||
from enum import Enum | ||
from importlib import resources | ||
from pathlib import Path | ||
|
||
import bluesky.plan_stubs as bps | ||
from bluesky.utils import MsgGenerator | ||
from dodal.common.beamlines.beamline_utils import get_path_provider | ||
from dodal.devices.fast_grid_scan import PandAGridScanParams | ||
from dodal.devices.smargon import Smargon | ||
from ophyd_async.core import load_device | ||
from ophyd_async.fastcs.panda import ( | ||
HDFPanda, | ||
SeqTable, | ||
SeqTrigger, | ||
) | ||
|
||
import mx_bluesky.hyperion.resources.panda as panda_resource | ||
from mx_bluesky.common.device_setup_plans.setup_panda import load_panda_from_yaml | ||
from mx_bluesky.common.utils.log import LOGGER | ||
from mx_bluesky.hyperion.parameters.constants import DeviceSettingsConstants | ||
|
||
MM_TO_ENCODER_COUNTS = 200000 | ||
GENERAL_TIMEOUT = 60 | ||
|
@@ -145,10 +144,11 @@ def setup_panda_for_flyscan( | |
|
||
yield from bps.stage(panda, group="panda-config") | ||
|
||
with resources.as_file( | ||
resources.files(panda_resource) / "panda-gridscan.yaml" | ||
) as config_yaml_path: | ||
yield from load_device(panda, str(config_yaml_path)) | ||
yield from load_panda_from_yaml( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the motivation from moving from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I could see, importlib.resources was very awkward when needing to specify the directory rather than exact path - and we need the directory now for the load plan |
||
DeviceSettingsConstants.PANDA_FLYSCAN_SETTINGS_DIR, | ||
DeviceSettingsConstants.PANDA_FLYSCAN_SETTINGS_FILENAME, | ||
panda, | ||
) | ||
|
||
initial_x = yield from bps.rd(smargon.x.user_readback) | ||
initial_y = yield from bps.rd(smargon.y.user_readback) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For things which we know are resources contained within our python project, I think I prefer to use
importlib.resources
to locate them rather than to use file paths. As far as I can tell it seems to be the "proper" way.Python doesn't guarantee that every module has a
__file__
attribute since modules aren't always in files. Having said that I suspect that our packages will probably always be available as files.I think most of my thoughts in this area derive from analogy with Java ClassLoaders which are a similar concept to python module, and it's best practice to bundle your resources in your jar file (usually in a separate hierarchy), and I think that is the overall intent of things like
importlib.resources
to encourage this, so that python packaging tools also know how to deploy your resources.Having said all this
importlib.resources
does seem to be annoyingly immature as an APIso I leave this here as an opinion you can choose to follow or ignore...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in person - as of Python 3.12, we can use this API to get a directory traversible, but we can't use it just yet. I will leave the code as-is but add a comment + issue to use
resources
again once we drop python < 3.12There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #798