Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a subprocess-compatible interface in cmd #138

Closed
jaraco opened this issue Dec 9, 2022 · 3 comments
Closed

Provide a subprocess-compatible interface in cmd #138

jaraco opened this issue Dec 9, 2022 · 3 comments

Comments

@jaraco
Copy link

jaraco commented Dec 9, 2022

I was exploring using subprocess_tee when I found it doesn't support Windows and has issues with Python 3.12.

When I tried dropping in ubelt.cmd as a replacement, I found it has a very different interface than subprocess, returning a dict instead of an object and having different keys.

It would be nice if the result from command was an object similar to the one returned by subprocess.Popen (or even identical), so that code like this can readily switch between the implementations.

@Erotemic
Copy link
Owner

Erotemic commented Dec 9, 2022

The reason for this return API is because ubelt.cmd can be invoked in several different ways that make it difficult to support a unified result object. For instance it can be used to invoke a command via os.system instead of the normal Popen interface, or with detach=True where it doesn't block and lets the process run in the background. My thought was that an information dictionary that directly contains relevant information would be the most natural result type given its variable nature.

However, in all but the system=True case the return dictionary contains a field "proc", which is the relevant Popen object. So while it's not a drop-in, it does have a simple replacement.

I'm open to the idea of improving the return type, but at the very least it must be backwards compatible with the current return type as it's used in quite a few places.

@Erotemic
Copy link
Owner

@jaraco I've come up with a backwards compatible solution in ac35aaa

If all goes well in testing, version 1.3.0 ubelt.cmd will return a CmdOutput object which will ducktype subprocess.CompletedProcess. It also inherits from a dictionary and maintains the same keys so it will be backwards compatible. Hope that will be useful to you.

@Erotemic
Copy link
Owner

@jaraco 1.3.0 is released and contains the updated interface. I think this can be marked as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants