News for hackers. Stuff that matters.
Re:Shshsh is a bridge connects Python and shell by nrclark on Saturday September 23, 2023 @12:39PM (#37624850)
I've always liked Python's "batteries-included" approach, and my take on libraries like this is that they introduce extra dependencies into scripts I write. And often, the juice doesn't feel like it's worth the squeeze.

For me, a little bit of syntax sugar (and maybe a line or two of code savings) isn't worth taking on the dependency burden, especially in production code.

Each and every dependency is one where I invite risk of requirements collision, or that the upstream goes away, or that the maintainer breaks it compatibility, etc. It's more time spent installing dependencies, and more time spent processing lockfiles.

Why carry that burden when subprocess.Popen() exists and works fine?

Re:Shshsh is a bridge connects Python and shell by sneed_chucker on Saturday September 23, 2023 @01:39PM (#37625458)
I agree with you for the most part, I really like writing shebangable dependency-free python scripts.

But I 100% understand the motivation for this project. Like you said, subprocess.Popen works well enough, but it's so much less ergonomic than shelling out in Ruby, Perl, or even Awk.

Re:Shshsh is a bridge connects Python and shell by grrandalf on Saturday September 23, 2023 @01:46PM (#37625541)
Great points. Agreed.

In certain situations though, the readability/maintainability gains from using this library might outweigh the added complexity of a layer of indirection.

Situations like this: whether to build a utility solution completely [1] in shell, or invert things and use mix of Python and shell. E.g., wrapping 'git' to create a note-taking CLI, or shelling out to $WEIRD_INTERNAL_TOOL and scraping its logs and stdout/stderr.

I think infrastructure like this repo can result in more readable and maintainable code than an all-shell OR all-Python solution in such situations.

You'll be less tempted to start doing things completely in shell and then get locked into that lock minimum.

However, you MUST be prepared to understand the source code of all dependencies you take [except the language's standard library, or similarly mature external libs]. e.g., I pick bottlepy.org vs Flask for personal projects.

With a small/medium library like this, I might import it to get a headstart and will be ok with it ultimately ending up as an incompatible, heavily-modified fork of the upstream project. Which IMO doesn't reflect poorly on the user or the library author.

[1] "completely" means some non-trivial processing that makes you use hash tables, arrays, lightweight tokenizing using read, arithmetic evaluation, sed+awk to massage command outputs so Bash's lightweight data structures can handle them, os.path manipulations.

Re:Shshsh is a bridge connects Python and shell by bsimpson on Saturday September 23, 2023 @03:03PM (#37626321)
Also, `>> 'some-cmd --with --args'` is code that's more likely to end up in a deployment script than in a production app. Less likely to be a project that's being edited by many people at once, served to end users, etc.

I respect and often agree with the parent's hesitation to introduce inessential dependencies, but the cost/benefit of making a shell script more comfortable to read/write is very different than that of adding a mystery brick to the foundation of your app.

Re:Shshsh is a bridge connects Python and shell by nrclark on Sunday September 24, 2023 @07:28AM (#37632132)
Deployment scripts are production code, same as whatever you're deploying. If your CI/CD docker images break, you're just as stuck as if your payload breaks.

I totally see the benefit of moving complex shell logic to Python (and still calling some shell helpers) but that doesn't mean you need to have a whole extra dependency for it.

You could write a one-line function that wraps subprocess.Popen.communicate, and use it instead for 90% of the benefit.

If the argument is "I don't want to learn it", or "too much effort", then I'd ask - is saving 15 minutes one time during development really worth a permanent dependency?

And when some other dev has to maintain the code later, how much extra time will they spend figuring out what I>> means or does? A lot of python devs are already familiar with the subprocess Popen API.

Re:Shshsh is a bridge connects Python and shell by dimator on Saturday September 23, 2023 @03:54PM (#37626845)
Unfortunately, the subprocess package is too low level, and usually ends up making scripts excessively verbose.

I wish there was a stdlib package that sat between subprocess and something else with a higher level syntax for process management. Running binary `foo` takes 3 letters in shell, and many many more in subprocess.

Re:Shshsh is a bridge connects Python and shell by krackers on Saturday September 23, 2023 @04:41PM (#37627338)
Re:Shshsh is a bridge connects Python and shell by throwaway290 on Saturday September 23, 2023 @06:31PM (#37628166)
No because they are not stdlib.
Re:Shshsh is a bridge connects Python and shell by slotrans on Saturday September 23, 2023 @07:36PM (#37628656)
because subprocess.Popen() is a giant pain in the ass that's easy to screw up, and I have to read the docs every single time and I'm still not sure it's right