[Python-ideas] Interest in seeing sh.py in the stdlib

Jasper St. Pierre jstpierre at mecheye.net
Mon Oct 22 16:52:31 CEST 2012


On Sat, Oct 20, 2012 at 8:33 PM, Andrew Moffat
<andrew.robert.moffat at gmail.com> wrote:
> Hi,
>
> I'm the author of sh.py, an intuitive interface for launching subprocesses
> in Linux and OSX http://amoffat.github.com/sh/.  It has been maintained on
> github https://github.com/amoffat/sh for about 10 months and currently has
> about 25k installs, according to pythonpackages.com
> (http://pythonpackages.com/package/sh,
> http://pythonpackages.com/package/pbs)
>
> Andy Grover maintains the Fedora rpm for sh.py
> http://arm.koji.fedoraproject.org/koji/buildinfo?buildID=94247  and Nick
> Moffit has submitted an older version of sh.py (which was called pbs) to be
> included in Debian distros
> http://pkgs.org/debian-wheezy/debian-main-i386/python-pbs_0.95-1_all.deb.html
>
> I'm interested in making sh.py more accessible to help bring Python forward
> in the area of shell scripting, so I'm interested in seeing if sh would be
> suitable for the standard library.  Is there any other interest in something
> like this?

I'm not one for the sugar. Seems like you're stuffing the Python
syntax where it doesn't quite belong, as evidenced by the many escape
hatches. Basic query of things not covered in the documentation:

If I import a non-existant program, will it give me back a function
that will fail or raise an ImportError?

How do I run a program with a - in the name? You say you replace -
with _, but thatdoesn't specify what happens in the edge case of "if I
have google-chrome and google_chrome, which one wins? What about
/usr/bin/google-chrome and /usr/local/bin/google_chrome"? That is,
will it exhaust the PATH before trying fallbacks replacements or will
it check all replacements at once?

If I have a program that's not on PATH, what do I do? I can manipulate
the PATH environment variable, but am I guaranteed that will work? Are
you going to double fork forever to guarantee that environment? Can I
build a custom prefix, like p =
sh.MagicPrefix(path="/opt/android_devtools/bin"), and have that work
like the regular sh module? p.gcc("whatever") ? Even with the
existence of a regular gcc in the path?

I wonder what happens if you do from sh import *.

Does it block execution before continuing? How can I do parallel
execution of four subprocesses, and get notified when all four are
done? (Seems like this might be a thing for a Future as well, even in
the absence of any scheduler or event loop).

Are newcomers going to be confused by this? What happens if I try and
do something like sh.ls("-l -a")? Will you use the POSIX shell parsing
algorithm, pass it to bash, or pass it as one parameter? Will some
form of injection attack be mitigated by this design?


If you see this magic syntax as your one unique feature, I'd propose
that you add it to the subprocess module, and improve the standard
subprocess module's interface to cope with the new feature.

But I don't see this as a worthwhile thing to have. -1 on the thing.

> Thanks
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>

-- 
  Jasper



More information about the Python-ideas mailing list