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

Document using globals() in python expressions #1860

Merged
merged 6 commits into from
Jan 28, 2025
Merged

Document using globals() in python expressions #1860

merged 6 commits into from
Jan 28, 2025

Conversation

jmthomas
Copy link
Member

closes #1612

@jmthomas jmthomas requested a review from ryanmelt January 24, 2025 00:32
@jmthomas jmthomas marked this pull request as ready for review January 24, 2025 00:32
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.56%. Comparing base (67da6a9) to head (c251df4).
Report is 31 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1860   +/-   ##
=======================================
  Coverage   79.56%   79.56%           
=======================================
  Files         519      519           
  Lines       40763    40763           
=======================================
+ Hits        32434    32435    +1     
+ Misses       8329     8328    -1     
Flag Coverage Δ
python 84.27% <ø> (+<0.01%) ⬆️
ruby-api 48.61% <ø> (ø)
ruby-backend 82.57% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Member

@ryanmelt ryanmelt left a comment

Choose a reason for hiding this comment

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

Remove change to code-workspace. Add examples to procedures for INST2 with python check_expression

@ryanmelt
Copy link
Member

These functions need to use both globals() and locals() otherwise they will not work inside of functions

@jmthomas
Copy link
Member Author

These functions need to use both globals() and locals() otherwise they will not work inside of functions

I don't think so. I was able to put the call inside a method successfully. According to the eval docs, if locals() is not given it defaults to globals().

@ryanmelt
Copy link
Member

# Works
def dude():
     y = 10
     eval("print(y)")

# Doesn't work
def dude():
     y = 10
     eval("print(y)", globals())

# Works
def dude():
     y = 10
     eval("print(y)", globals(), locals())

@jmthomas
Copy link
Member Author

This works:

def check():
    value = 0
    wait_check_expression(f"tlm('INST HEALTH_STATUS TEMP1') > {value}", 5, 0.25, globals())

check()

@ryanmelt
Copy link
Member

It doesn't really work.
The f string is being evaluated before it gets into wait_check_expression

@ryanmelt
Copy link
Member

This won't work:

def check():
    value = 0
    wait_check_expression("tlm('INST HEALTH_STATUS TEMP1') > value", 5, 0.25, globals())

check()

@jmthomas jmthomas merged commit 6de3c5c into main Jan 28, 2025
27 of 28 checks passed
@jmthomas jmthomas deleted the py_expression branch January 28, 2025 02:49
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.

Python wait_check_expression (and friends), don't have API methods in context
2 participants