Thinking cap time... :brain: :tophat: We have a l...
# general
b
Thinking cap time... 🧠 🎩 We have a lot of scripts in our repo, and to mitigate the need for mapping where the live we have a dir tree in our repo which houses "commands" where the dirnames become (sub)commands. Each script is a just a thin shell wrapper shelling out to the real Python script. E.g.
./script-runner devops docs generate
would invoke a shell script at
/scripts/devops/docs/generate.sh
, in turn that script run
./pants run path/to/the/script.py
. Now we can rename or move or change implementations without rewiring brains or other scripts. I want to "bring this into Pants" a bit more, if nothing more than to ensure the Pants spec in the shell script is valid. My thoughts are: β€’ Try and implement a linter for these scripts. Match probable pants commands and specs and then error if the spec isn't valid β€’ Bring the whole system into pants. Then the world is my oyster with a new goal, could be a single TOML file or spread or whatever. Lots more thought and plumbing though Anyone else do something similar? Have ideas?
c
This topic was discussed last fall, I think with @proud-dentist-22844 and the stackstorm project, but I can’t find it (probably too old for Slacks history search by now). Jacob had some nifty Python lib he used for writing tasks a la Gradle for js projects, which I played with a bit, and it made sense for use cases you describe above, I think. Hopefully he remembers more than I πŸ™‚
πŸ™Œ 1
p
Invoke?
πŸ‘ 1
Let me grab a link to my plugin.
πŸ‘€ 1
c
Ah, yeah that sounds about right!
p
Plugin: https://github.com/st2sandbox/st2/tree/pants/pants-plugins/do_invoke Entry script (uses pants internally to bootstrap the invoke venv): https://github.com/st2sandbox/st2/blob/pants/invoke Shorter symlinks to invoke entry point script: https://github.com/st2sandbox/st2/blob/pants/do https://github.com/st2sandbox/st2/blob/pants/inv I ended up not running
invoke
directly via
./pants ...
Because there was significant impedance mismatch between pants' and invoke's help systems, and I really wanted the help to be exposed automatically.
πŸ‘€ 1
πŸ™Œ 1
πŸ™ 1
Invoke (in python) is not the same as a directory of shell scripts. I'm interested to hear how you end up tackling this.
Oh. I should read. Your shell scripts call python scripts. So, it might work well to turn those into invoke tasks.
I forgot. The other key part of that plugin is to make invoke available in the pants venv: https://github.com/st2sandbox/st2/blob/pants/pants.toml#L38
c
Right, thanks @proud-dentist-22844! I can’t find any trace of my tinkering that I did now, but IIRC it involved loading
pyinvoke
as a plugin, and tweaking
./pants
to expose scripts from the Pants venv I could use invoke without any bootstrapping scripts besides pants itself. And also cli aliases to make the syntax for invoke scripts nicer to run.
p
I didn't want to modify
./pants
at all so that upgrades are curl-simple. Oh and I forgot about CLI aliases. I don't remember if I looked into that.
It's been so long.
βž• 1
b
LOL took me waaaay too long to realize
invoke
was the name of a package 😬 https://www.pyinvoke.org/
πŸ€ͺ 1
p
Uhm. Yep sorry. I thought about calling that out and didn't.
b
No worries. All makes more sense now. This might a bit too beefy for my simple use case but I'll take a look!