romkatv / powerlevel10k

A Zsh theme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unexpected behavior in Python `venv`

LucasLarson opened this issue · comments

For example (note that the blank newlines are part of the output):

$ setopt nounset && python3 -m venv . && source bin/activate
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set

$ python --version
Python 3.12.3
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set

$ P9K_PYENV_PYTHON_VERSION='' python --version
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set
zsh: P9K_PYENV_PYTHON_VERSION: parameter not set

$ P9K_PYENV_PYTHON_VERSION='' && python --version # this works, but will rearrange `$PS1` and emulate my overwriting it
Python 3.12.3

You’re amazing and make me miss Reddit. Keep up the good work!

It's not a good idea to use setopt nounset in an interactive shell. Do you really need it?

It’s obviously not essential, and p10k is the backbone of everything else my interactive shell does, but set -u is super useful for debugging projects I work on and in encountering unforeseen issues before others can.

Can you provide a bit more info? How does set -u in your interactive shell helps you?

I often time working with other people’s shell scripts. Before I send content to CI tests or let others access them, it saves time to always have my guard up and to repair content proactively and privately, even if it’s only misspellings.

Changing [[ -n $new_variable ]] to [[ -n ${new_variable-} ]] is effortless for me and ensures that unset-variable errors occur only when there is an actual problem.

Usually unset-variable errors don’t cause such visual and interactive chaos and I assume that if I have this issue, others might, too.

If I had been able to modify my ~/.p10k.zsh line that reads typeset -g POWERLEVEL9K_PYENV_CONTENT_EXPANSION='${P9K_CONTENT}${${P9K_CONTENT:#$P9K_PYENV_PYTHON_VERSION(|/*)}:+ $P9K_PYENV_PYTHON_VERSION}' to something similar to typeset -g POWERLEVEL9K_PYENV_CONTENT_EXPANSION='${P9K_CONTENT}${${P9K_CONTENT:#$P9K_PYENV_PYTHON_VERSION(|/*)-}:+ $P9K_PYENV_PYTHON_VERSION-}' in order to avoid the error, I probably would not have raised an issue here.

I often time working with other people’s shell scripts.

Using set -u in your interactive shell does not help with this. set -u in the interactive shell has no effect on scripts that you run. All it does is produce errors in your prompt and the like, like you were encountering.