Idempotent install
Scenario: a build system reads a file in a repository to know which version of Python is required. The build system uses pythonz to install that version, unless it already exists. Then the build system proceeds with other build tasks.
The ideal solution would be that pythonz install 2.7.9 has a return code of 0 whenever CPython 2.7.9 already exists, so that installation is idempotent. However, that might break behavior someone currently depends on.
An alternative is an additional parameter, like pythonz install 2.7.9 --no-error-if-installed (or maybe --idempotent if shorter is better). That would have a return code of 0 if CPython 2.7.9 already exists. I get my idempotent command but current behavior remains.
My current quick fix is to alter the behavior of locate so that it can be used as a test whether a version exists (pull request pending). Then my code can do the following:
$VERSION = 2.7.9
if ! pythonz locate $VERSION; then
pythonz install $VERSION
fi
Since we do have a --reinstall option, we should probably not do anything if the requested Python version is already installed, if you're up for writing a fix, I'll take it :-)
--reinstall should mean erase and start again. Otherwise we need a --really-reinstall
$ pythonz locate 2.7.9
ERROR: `CPython-2.7.9` is not x installed.
$ echo $?
0
$ `which pythonz` locate 2.7.9
ERROR: `CPython-2.7.9` is not x installed.
$ echo $?
1
It's because pythonz bash function wrapper overrides the error code we want.