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

RSDK-9607: add build and run options for all Python modules; remove run option for Go #4818

Conversation

purplenicole730
Copy link
Member

@purplenicole730 purplenicole730 commented Feb 26, 2025

Originally, users could only use the run.sh script for local Python modules, and only hot reloading for cloud Python modules. Both methods should be available for both, even if there's a default. Go should never be using run.sh, as a user should not be building a Go binary on an embedded device every time a module is updated or restarted.

Changes:

  • adds the build setup for local Python modules
  • adds the run script to cloud Python modules
  • removes the run.sh from Golang modules

Flyby:

  • hot reloading for cloud Python modules were no longer working with directory changes, so made it work for both local and cloud Python modules

Testing Process:

  1. Generate one local Python module, one Python module with cloud build enabled, one local Golang module, and one Golang module with cloud build enabled.
  2. Change each module's do_command to print a log.
  3. Add both Python modules to a machine using the run.sh.
  4. Call do_command() from a sensor using local Python module -- ✅
  5. Call do_command() from a sensor using cloud Python module -- ✅
  6. Add both Go modules to a machine using make setup and make build
  7. Call do_command() from a sensor using local Go module -- ✅
  8. Call do_command() from a sensor using cloud Go module -- ✅
  9. Add both Python modules to a machine using PyInstaller.
  10. Call do_command() from a sensor using local Python module -- ✅
  11. Call do_command() from a sensor using cloud Python module -- ✅

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Feb 26, 2025
@purplenicole730 purplenicole730 changed the title RSDK-9607: add build to local modules; add run to cloud modules RSDK-9607: add build and run options for all Python modules; remove run option for Go Feb 27, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Feb 28, 2025
@purplenicole730 purplenicole730 marked this pull request as ready for review February 28, 2025 21:55
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 3, 2025
@purplenicole730 purplenicole730 force-pushed the RSDK-9607-generate-run.sh-and-populate-build-command branch from 5d840b6 to 9b23811 Compare March 3, 2025 13:08
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 3, 2025
@purplenicole730 purplenicole730 force-pushed the RSDK-9607-generate-run.sh-and-populate-build-command branch from 9b23811 to 7f02db9 Compare March 3, 2025 13:13
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 3, 2025
from viam.module.module import Module
from .models.{{ .ModelSnake }} import {{ .ModelPascal }}
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
Copy link
Member

Choose a reason for hiding this comment

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

What is this for? I don't like the idea of updating the path...

Copy link
Member Author

Choose a reason for hiding this comment

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

Running build.sh and run.sh both fail in opposite ways. Using the relative path .models fails when using the hot reloading method, but succeeds when just writing models. run.sh can't find models, but can find .models. If there's a better way for both methods to find models, that would definitely be best. Python import errors are my nemesis

Copy link
Member

Choose a reason for hiding this comment

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

can we use a try/except block when importing here, along with a comment explaining the details?

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

generally lgtm though I share Naveed's preference for not updating path.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 5, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 5, 2025
Comment on lines 6 to 9
from models.hello_sensor import HelloSensor
except ModuleNotFoundError:
# when running as local module with run.sh
from .models.hello_sensor import HelloSensor
Copy link
Member

Choose a reason for hiding this comment

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

Probably we still want ModelSnake and ModelPascal, rather than hard-coding HelloSensor

Copy link
Member Author

Choose a reason for hiding this comment

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

omg 😅 That would have been embarrassing!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with my new commit: please pay attention nicole

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 6, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 6, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 6, 2025
@purplenicole730 purplenicole730 requested a review from stuqdog March 6, 2025 16:05
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

lgtm!

@purplenicole730 purplenicole730 merged commit 4cca416 into viamrobotics:main Mar 6, 2025
16 checks passed
@purplenicole730 purplenicole730 deleted the RSDK-9607-generate-run.sh-and-populate-build-command branch March 6, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants