robotpy / robotpy-installer

RobotPy installer program
MIT License
5 stars 11 forks source link

add --pre-deploy-script arg to robotpy-installer #75

Closed otherjon closed 8 months ago

otherjon commented 8 months ago

Hi robotpy team,

I was wondering how you folks might feel about allowing a pre-release script to be specified on the command line when deploying code to a RoboRIO.

A pre-deploy script can serve the same purpose as Gradle tasks, e.g. to determine the Git commit hash and branch and write them to files to be deployed to the RoboRIO. (See this WPILib page for the Java equivalent.)

In this draft implementation, pre-deploy scripts must be written in Python (this allows equivalent invocation on Windows or Linux), and will receive a command-line argument of --robot_path <path/to/dir/of/robot.py>

Sample predeploy script: available here

I see that you're in the process of moving deploy functionality from pyfrc to robot-installer, so I'm submitting my pull request as a commit on top of the robotpy-installer/add-deploy branch, but let me know if there's a better strategy.

auscompgeek commented 8 months ago

e.g. to determine the Git commit hash and branch and write them to files to be deployed to the RoboRIO.

Do you have a use-case which isn't well suited by the above? I'm not sure this complexity makes sense here in this form.

otherjon commented 8 months ago

Thanks for the pointer to the deploy artifact information. I hadn't looked at the developer documentation earlier because I hadn't considered myself a robotpy developer until now. Since the Git info was my primary motivation, I'll cancel the pull request.

While obviously I run "robot.py deploy" in order to deploy, I'm at a loss to explain how I'd add code to my robot.py to execute a pre-release script. Do you have a pointer to info about that, or the name a method I should override?

virtuald commented 8 months ago

It's also documented in the user docs at https://robotpy.readthedocs.io/projects/robotpy/en/latest/wpilib.deployinfo.html, but... it wasn't documented in prior years even though it was there if you looked for it.

Strictly speaking, you could put whatever arbitrary code you want in the if __name__ == "__main__": block of your code, including something that checks sys.argv to see if deploy is occurring.