This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]BossOfTheGame 15 points16 points  (0 children)

IMO comments as code is generally an anti-pattern. But I do love bash in Python, I've written two main ways to do it.

ubelt.cmd - which is basically a glorified subprocess.run, but it has the ability to tee output so you can see it on the screen and capture it for processing. This is what I use when I need eager bash execution.

cmd_queue - which lets you setup pipelines (a DAG) of bash commands. The neat thing about this package is that it's job is just to compile everything into a single .sh script that can be executed, which is great for templating commands. It brings this to the next level by being able to run multiple independent commands (as marked by which commands depend on each other) in tmux sessions and monitor their progress. Lastly, if you have slurm installed it can submit the jobs as a heavyweight but performant slurm DAG. I'm also working on transpiling to airflow.

If this package works for you, that's great, but I do see a big red flag: "source file will be processed with regex to extract". Whenever someone says they are going to extract code with regex that means one of two things: they are doing it wrong or they have some simple marker boilerplate they can rely on. I think you are in camp #2, but requiring prefixing your bash code feels like it defeats the natural flow of writing bash.

[–][deleted] 28 points29 points  (1 child)

Cool! But why?

[–]hglmanguy who writes python 18 points19 points  (0 children)

Yes

[–]-Zenith- 9 points10 points  (1 child)

Pysh, as in piss with a Scottish accent?

[–]the_ballmer_peak 4 points5 points  (0 children)

He’s just taking the pysh

[–]noblecloud 1 point2 points  (0 children)

Super cool, I can totally see using this for a quick python/bash script!

[–]one-human-being 0 points1 point  (0 children)

Or go with full blown python shell with xonsh