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

pyenv virtualenv --force not working as expected? #161

Closed
apapanico opened this issue Mar 15, 2016 · 4 comments · Fixed by #232
Closed

pyenv virtualenv --force not working as expected? #161

apapanico opened this issue Mar 15, 2016 · 4 comments · Fixed by #232
Labels

Comments

@apapanico
Copy link

Hi, first let me just say two things: 1) I like the tool. Thanks! 2) My understanding is that -f/--force would overwrite an existing environment of the same name and version.

Here is what happens when I try to use -f with an environment that already exists:

$ pyenv versions
* system (set by ~/.pyenv/version)
  2.7.10
  2.7.10/envs/test-py2.7.10
$ pyenv virtualenv -f 2.7.10 test-py2.7.10
pyenv-virtualenv: `~/.pyenv/versions/test-py2.7.10' already exists.

A little dive into the shell script leads me the following pair of conditionals:

pyenv-virtualenv#L349

...
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
if [[ "${VIRTUALENV_PATH/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then
  COMPAT_VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME##*/}"
fi

if [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
  if [ -e "${COMPAT_VIRTUALENV_PATH}" ] || [ -L "${COMPAT_VIRTUALENV_PATH}" ]; then
    echo "pyenv-virtualenv: \`${COMPAT_VIRTUALENV_PATH}' already exists." 1>&2
    exit 1
  fi
fi
...

I'm really not sure what this section is trying to do but it looks to me like it may always evaluate to true if an environment already exists, regardless of the force tag.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@apapanico
Copy link
Author

Quick comment: I've found pyenv rehash necessary at some points to fix problems. Did not fix this problem.

@drts01
Copy link

drts01 commented Apr 24, 2017

I have the same issue.

--force does not appear to be doing anything.

$ pyenv virtualenv --force --update python3.6
pyenv-virtualenv: `/Users/cmeza/.pyenv/versions/python3.6' already exists.

$ pyenv virtualenv --force --clear python3.6
pyenv-virtualenv: `/Users/cmeza/.pyenv/versions/python3.6' already exists.

@cjerdonek
Copy link

I also noticed that the return code is 1 if a virtualenv of the given name already exists. Since the version already existing is documented as a supported case of --force, it seems like the return code should be 0 in this case.

    $ pyenv virtualenv --force alreadyexists
    pyenv-virtualenv: `/Users/chris/.pyenv/versions/alreadyexists' already exists.
    $ echo $?
    1

@cjerdonek
Copy link

I found some info as to the cause of this issue. These lines have logic to handle the --force flag, and they were added four years ago:

# If the virtualenv exists, prompt for confirmation unless
# the --force option was specified.
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
  if [ -z "$FORCE" ]; then
    echo "pyenv-virtualenv: ${VIRTUALENV_PATH} already exists" 1>&2
    read -p "continue with installation? (y/N) "

    case "$REPLY" in
    y* | Y* ) ;;
    * ) exit 1 ;;
    esac
  fi

However, the lines in the OP, which cause a premature exit with return-code 1, were added two years ago. So it seems like this change from 2 years ago might have broken the force flag: 0b9b192

logikone pushed a commit to logikone/pyenv-virtualenv that referenced this issue Sep 8, 2017
@yyuu yyuu closed this as completed in #232 Sep 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants