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

Move util functions from i22 branch of ophyd_async that may be generally useful #10

Merged
merged 30 commits into from
Oct 23, 2023

Conversation

DiamondJoseph
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #10 (03a65ec) into main (512edd2) will increase coverage by 4.29%.
The diff coverage is 98.11%.

❗ Current head 03a65ec differs from pull request most recent head ed2cae5. Consider uploading reports for the commit ed2cae5 to get more accurate results

@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
+ Coverage   87.17%   91.47%   +4.29%     
==========================================
  Files           9       13       +4     
  Lines          78      129      +51     
==========================================
+ Hits           68      118      +50     
- Misses         10       11       +1     
Files Coverage Δ
src/dls_bluesky_core/core/__init__.py 100.00% <100.00%> (ø)
src/dls_bluesky_core/core/maths.py 100.00% <100.00%> (ø)
src/dls_bluesky_core/core/scanspecs.py 100.00% <100.00%> (ø)
src/dls_bluesky_core/core/types.py 100.00% <100.00%> (ø)
src/dls_bluesky_core/stubs/flyables.py 100.00% <100.00%> (ø)
src/dls_bluesky_core/core/coordination.py 80.00% <80.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@DiamondJoseph
Copy link
Contributor Author

May want to turn off test coverage for the plans and stubs module.

src/dls_bluesky_core/core/scanspecs.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/core/scanspecs.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/core/scanspecs.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/core/types.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/core/coordination.py Show resolved Hide resolved
- get_constant_duration renamed to be clearer intended function, always return None instead of throwing
- in_micros to throw exception when working in negative time
- Add tests for intended behaviour of get_constant_duration
src/dls_bluesky_core/core/maths.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/core/maths.py Outdated Show resolved Hide resolved
DiamondJoseph and others added 3 commits October 16, 2023 15:13
Co-authored-by: Tom C (DLS) <101418278+coretl@users.noreply.github.com>
@DiamondJoseph
Copy link
Contributor Author

Not to be merged until bluesky/ophyd-async#24 has been merged and ophyd_async pin is removed.

Comment on lines +7 to +24
@pytest.fixture(scope="function")
def RE(request):
loop = asyncio.new_event_loop()
loop.set_debug(True)
RE = RunEngine({}, call_returns_result=True, loop=loop)

def clean_event_loop():
if RE.state not in ("idle", "panicked"):
try:
RE.halt()
except TransitionError:
pass
loop.call_soon_threadsafe(loop.stop)
RE._th.join()
loop.close()

request.addfinalizer(clean_event_loop)
return RE
Copy link
Contributor

Choose a reason for hiding this comment

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

A general comment for future reference; I've started peppering this into every repo that needs to run plans with ophyd-async devices, such as dodal, and ophyd-async. And now here! Seems like this bit of code really ought to belong somewhere more common but I'm not sure where. This is just a general comment though. Happy for this to be a 'we will sort it after I22' type deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to have fixtures available from the library (ophyd_async) to libraries (this, dodal) and applications (BlueAPI?) that use it?

Does ophyd_async depend on bluesky for things other than the RunEngine?

Copy link
Contributor

@rosesyrett rosesyrett Oct 23, 2023

Choose a reason for hiding this comment

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

Ophyd-async mainly depends on bluesky for its protocols (as well as the run engine).

For now I'm thinking the best thing is to have a testutils module in bluesky which contains this, i.e.

bluesky/bluesky/utils.py::
def RE(request):
    loop = asyncio.new_event_loop()
    loop.set_debug(True)
    RE = RunEngine({}, call_returns_result=True, loop=loop)

    def clean_event_loop():
        if RE.state not in ("idle", "panicked"):
            try:
                RE.halt()
            except TransitionError:
                pass
        loop.call_soon_threadsafe(loop.stop)
        RE._th.join()
        loop.close()

    request.addfinalizer(clean_event_loop)
    return RE

And then here,

from bluesky.utils import RE

@pytest.fixture(scope="function")
def RunEngine(request):
    return RE(request)

but idk if RE is a good name for it...

Copy link
Contributor

Choose a reason for hiding this comment

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

Protocols

tests/core/test_funcs.py Outdated Show resolved Hide resolved
src/dls_bluesky_core/stubs/flyables.py Show resolved Hide resolved
Comment on lines +7 to +24
@pytest.fixture(scope="function")
def RE(request):
loop = asyncio.new_event_loop()
loop.set_debug(True)
RE = RunEngine({}, call_returns_result=True, loop=loop)

def clean_event_loop():
if RE.state not in ("idle", "panicked"):
try:
RE.halt()
except TransitionError:
pass
loop.call_soon_threadsafe(loop.stop)
RE._th.join()
loop.close()

request.addfinalizer(clean_event_loop)
return RE
Copy link
Contributor

Choose a reason for hiding this comment

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

Protocols

Copy link
Contributor

@callumforrester callumforrester left a comment

Choose a reason for hiding this comment

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

All good, one very minor comment that you can ignore for now if too busy.

src/dls_bluesky_core/stubs/flyables.py Outdated Show resolved Hide resolved
@rosesyrett rosesyrett merged commit fc6625a into main Oct 23, 2023
15 checks passed
@rosesyrett rosesyrett deleted the i22_functions branch October 23, 2023 10:59
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.

5 participants