zestsoftware / zest.releaser

Python software releasing made easy and repeatable
https://zestreleaser.readthedocs.io
GNU General Public License v2.0
198 stars 62 forks source link

Use subprocess.run for executing commands #379

Closed mauritsvanrees closed 2 years ago

mauritsvanrees commented 2 years ago

If I recall correctly, our _execute_command function started out as a copy of some code from zc.buildout, with as comment that it was a "commands.getoutput() replacement that also works on windows". Meanwhile, the entire commands module was removed in Py 3 and you should use subprocess now.

We already did this, but we were using subprocess.Popen. The subprocess documentation says:

The recommended approach to invoking subprocesses is to use the run() function for all use cases it can handle. For more advanced use cases, the underlying Popen interface can be used directly. The run() function was added in Python 3.5

It looks like our use cases can be handled just fine by run, so I did that. And I got rid of some more encoding-related and Windows-specific code, with the idea that standard Python probably knows better how to handle this than we do.

The amount of code changed in this PR is not so much, but it covers some complicated code that I don't usually touch. It may help to look at the smaller individual commits that simplify the code step by step.