pythonz icon indicating copy to clipboard operation
pythonz copied to clipboard

Idempotent install

Open ibuchanan opened this issue 10 years ago • 3 comments

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

ibuchanan avatar May 22 '15 15:05 ibuchanan

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 :-)

saghul avatar Jun 03 '15 06:06 saghul

--reinstall should mean erase and start again. Otherwise we need a --really-reinstall

jayvdb avatar May 08 '19 04:05 jayvdb

$ 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.

ifduyue avatar Oct 24 '19 06:10 ifduyue