From 084489f93cc6e17b30a6b8844e5dea7e0a803012 Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Sat, 7 Sep 2024 09:47:43 -0400 Subject: [PATCH 1/6] Use is_plan from bluesky utils --- bluesky_queueserver/manager/profile_ops.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bluesky_queueserver/manager/profile_ops.py b/bluesky_queueserver/manager/profile_ops.py index 91c805da..ac46eecb 100644 --- a/bluesky_queueserver/manager/profile_ops.py +++ b/bluesky_queueserver/manager/profile_ops.py @@ -24,6 +24,8 @@ from numpydoc.docscrape import NumpyDocString from packaging import version +from bluesky.utils import is_plan + import bluesky_queueserver from .logging_setup import PPrintForLogging as ppfl @@ -689,13 +691,6 @@ def load_script_into_existing_nspace( sys.path.remove(script_root_path) -def is_plan(obj): - """ - Returns ``True`` if the object is a plan. - """ - return inspect.isgeneratorfunction(obj) - - def is_device(obj): """ Returns ``True`` if the object is a device. From 3ebb9086e1685ad90a382d19b8f246e19864334e Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Sat, 7 Sep 2024 09:55:33 -0400 Subject: [PATCH 2/6] Isort --- bluesky_queueserver/manager/profile_ops.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bluesky_queueserver/manager/profile_ops.py b/bluesky_queueserver/manager/profile_ops.py index ac46eecb..e0dcdef1 100644 --- a/bluesky_queueserver/manager/profile_ops.py +++ b/bluesky_queueserver/manager/profile_ops.py @@ -21,11 +21,10 @@ import jsonschema import pydantic import yaml +from bluesky.utils import is_plan from numpydoc.docscrape import NumpyDocString from packaging import version -from bluesky.utils import is_plan - import bluesky_queueserver from .logging_setup import PPrintForLogging as ppfl From 8b455c50d0780934dddb3d72636573ff2d406594 Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Tue, 24 Sep 2024 11:28:10 -0400 Subject: [PATCH 3/6] Add back internal function, try bs utils version first before reverting to original --- bluesky_queueserver/manager/profile_ops.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bluesky_queueserver/manager/profile_ops.py b/bluesky_queueserver/manager/profile_ops.py index e0dcdef1..9ed1bcdd 100644 --- a/bluesky_queueserver/manager/profile_ops.py +++ b/bluesky_queueserver/manager/profile_ops.py @@ -21,7 +21,6 @@ import jsonschema import pydantic import yaml -from bluesky.utils import is_plan from numpydoc.docscrape import NumpyDocString from packaging import version @@ -690,6 +689,19 @@ def load_script_into_existing_nspace( sys.path.remove(script_root_path) +def is_plan(obj): + """ + Returns ``True`` if the object is a plan. + """ + + try: + # If available, use is_plan from bs utils to catch plans with new decorator. + from bluesky.utils import is_plan as bs_utils_is_plan + return bs_utils_is_plan(obj) + except ImportError: + return inspect.isgeneratorfunction(obj) + + def is_device(obj): """ Returns ``True`` if the object is a device. From 13f0969609f1b71a8226b6d6dfe1dbffa8767a18 Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Tue, 24 Sep 2024 11:30:00 -0400 Subject: [PATCH 4/6] Make black happy --- bluesky_queueserver/manager/profile_ops.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bluesky_queueserver/manager/profile_ops.py b/bluesky_queueserver/manager/profile_ops.py index 9ed1bcdd..300d5680 100644 --- a/bluesky_queueserver/manager/profile_ops.py +++ b/bluesky_queueserver/manager/profile_ops.py @@ -697,6 +697,7 @@ def is_plan(obj): try: # If available, use is_plan from bs utils to catch plans with new decorator. from bluesky.utils import is_plan as bs_utils_is_plan + return bs_utils_is_plan(obj) except ImportError: return inspect.isgeneratorfunction(obj) From 2caf3d1af0c6792f3dec909e5c9a78bfd63aea93 Mon Sep 17 00:00:00 2001 From: Dmitri Gavrilov Date: Thu, 26 Sep 2024 16:13:45 -0400 Subject: [PATCH 5/6] TST: test if 'is_plan' recognizes built-in Bluesky plans --- .../manager/tests/test_profile_ops.py | 14 +++++++++++++- .../profile_collection_sim/00-ophyd.py | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bluesky_queueserver/manager/tests/test_profile_ops.py b/bluesky_queueserver/manager/tests/test_profile_ops.py index 4f8589a7..9d183d21 100644 --- a/bluesky_queueserver/manager/tests/test_profile_ops.py +++ b/bluesky_queueserver/manager/tests/test_profile_ops.py @@ -3760,7 +3760,7 @@ def test_construct_parameters_1(testmode, success, errmsg): # --------------------------------------------------------------------------------- -def test_plans_from_nspace(): +def test_plans_from_nspace_1(): """ Function 'plans_from_nspace' is extracting a subset of callable items from the namespace """ @@ -3771,6 +3771,18 @@ def test_plans_from_nspace(): assert callable(plan), f"Plan '{name}' is not callable" +def test_plans_from_nspace_2(): + """ + Function 'plans_from_nspace' is extracting a subset of callable items from the namespace + """ + pc_path = get_default_startup_dir() + nspace = load_profile_collection(pc_path) + plans = plans_from_nspace(nspace) + assert "mv" in plans + assert "mvr" in plans + assert "null" in plans + + def test_devices_from_nspace(): """ Function 'plans_from_nspace' is extracting a subset of callable items from the namespace diff --git a/bluesky_queueserver/profile_collection_sim/00-ophyd.py b/bluesky_queueserver/profile_collection_sim/00-ophyd.py index df732300..e2dc3131 100644 --- a/bluesky_queueserver/profile_collection_sim/00-ophyd.py +++ b/bluesky_queueserver/profile_collection_sim/00-ophyd.py @@ -1,6 +1,8 @@ # flake8: noqa print(f"Loading file {__file__!r}") +# Import some built-in plans +from bluesky.plan_stubs import mv, mvr, null from ophyd.sim import hw # Import ALL simulated Ophyd objects in global namespace (borrowed from ophyd.sim) From 1bb7f1760f3f2d2b9cc0387186af44e5f0111509 Mon Sep 17 00:00:00 2001 From: Dmitri Gavrilov Date: Thu, 26 Sep 2024 16:29:22 -0400 Subject: [PATCH 6/6] TST: updated existed_plans_and_devices.yaml to include new built-in plans --- .../existing_plans_and_devices.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/bluesky_queueserver/profile_collection_sim/existing_plans_and_devices.yaml b/bluesky_queueserver/profile_collection_sim/existing_plans_and_devices.yaml index e2290cdb..d9b5b165 100644 --- a/bluesky_queueserver/profile_collection_sim/existing_plans_and_devices.yaml +++ b/bluesky_queueserver/profile_collection_sim/existing_plans_and_devices.yaml @@ -2049,6 +2049,60 @@ existing_plans: step: '0.01' properties: is_generator: true + mv: + description: Move one or more devices to a setpoint. Wait for all to complete. + module: bluesky.plan_stubs + name: mv + parameters: + - description: device1, value1, device2, value2, ... + kind: + name: VAR_POSITIONAL + value: 2 + name: args + - default: None + description: Used to mark these as a unit to be waited on. + kind: + name: KEYWORD_ONLY + value: 3 + name: group + - description: passed to obj.set() + kind: + name: VAR_KEYWORD + value: 4 + name: kwargs + properties: + is_generator: true + mvr: + description: Move one or more devices to a relative setpoint. Wait for all to + complete. + module: bluesky.plan_stubs + name: mvr + parameters: + - description: device1, value1, device2, value2, ... + kind: + name: VAR_POSITIONAL + value: 2 + name: args + - default: None + description: Used to mark these as a unit to be waited on. + kind: + name: KEYWORD_ONLY + value: 3 + name: group + - description: passed to obj.set() + kind: + name: VAR_KEYWORD + value: 4 + name: kwargs + properties: + is_generator: true + 'null': + description: Yield a no-op Message. (Primarily for debugging and testing.) + module: bluesky.plan_stubs + name: 'null' + parameters: [] + properties: + is_generator: true plan_test_progress_bars: description: Test visualization of progress bars. module: __main__