Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/source/command_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ Other Commands
virtualenvwrapper
-----------------

Print a list of commands and their descriptions as basic help output.
Print a list of commands, their descriptions, and some details about
the version and locations used by virtualenvwrapper as basic help
output.

Syntax::

Expand Down
12 changes: 12 additions & 0 deletions tests/test_virtualenvwrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ test_virtualenvwrapper_script_set() {
"echo $VIRTUALENVWRAPPER_SCRIPT | grep -q /virtualenvwrapper.sh"
}

test_virtualenvwrapper_version() {
source "$test_dir/../virtualenvwrapper.sh"
typeset ver=$(_virtualenvwrapper_version)
assertTrue "version is empty" "[ -n $ver ]"
}

test_virtualenvwrapper_help_shows_version() {
source "$test_dir/../virtualenvwrapper.sh"
typeset pattern="Version: $(_virtualenvwrapper_version)"
assertTrue "version not in command output" "virtualenvwrapper | grep \"$pattern\""
}

. "$test_dir/shunit2"
11 changes: 11 additions & 0 deletions virtualenvwrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,13 @@ function allvirtualenv {
unset IFS
}

function _virtualenvwrapper_version {
"$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' --version
}

#:help:virtualenvwrapper: show this help message
function virtualenvwrapper {
typeset version=$(_virtualenvwrapper_version)
cat <<EOF

virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
Expand All @@ -1350,6 +1355,12 @@ For more information please refer to the documentation:

http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html

Version: $version
Script: $VIRTUALENVWRAPPER_SCRIPT
Python: $VIRTUALENVWRAPPER_PYTHON
WORKON_HOME: $WORKON_HOME
PROJECT_HOME: $PROJECT_HOME

Commands available:

EOF
Expand Down
11 changes: 11 additions & 0 deletions virtualenvwrapper/hook_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@ def main():
dest='names',
default=[],
)
parser.add_option(
'--version',
help='Show the version of virtualenvwrapper',
action='store_true',
default=False,
)
parser.disable_interspersed_args() # stop when on option without an '-'
options, args = parser.parse_args()

if options.version:
import importlib.metadata
print(importlib.metadata.version('virtualenvwrapper'))
return 0

root_logger = logging.getLogger('virtualenvwrapper')

# Set up logging to a file
Expand Down