Skip to content

Commit a22a4e9

Browse files
committed
add a --version option to the hook loader
Use the hook loader --version option to report the version of virtualenvwrapper installed when the user runs the `virtualenvwrapper` command. Fixes #42
1 parent ceaa88f commit a22a4e9

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

docs/source/command_ref.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ Other Commands
591591
virtualenvwrapper
592592
-----------------
593593

594-
Print a list of commands and their descriptions as basic help output.
594+
Print a list of commands, their descriptions, and some details about
595+
the version and locations used by virtualenvwrapper as basic help
596+
output.
595597

596598
Syntax::
597599

tests/test_virtualenvwrapper.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ test_virtualenvwrapper_script_set() {
2626
"echo $VIRTUALENVWRAPPER_SCRIPT | grep -q /virtualenvwrapper.sh"
2727
}
2828

29+
test_virtualenvwrapper_version() {
30+
source "$test_dir/../virtualenvwrapper.sh"
31+
typeset ver=$(_virtualenvwrapper_version)
32+
assertTrue "version is empty" "[ -n $ver ]"
33+
}
34+
35+
test_virtualenvwrapper_help_shows_version() {
36+
source "$test_dir/../virtualenvwrapper.sh"
37+
typeset pattern="Version: $(_virtualenvwrapper_version)"
38+
assertTrue "version not in command output" "virtualenvwrapper | grep \"$pattern\""
39+
}
40+
2941
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,13 @@ function allvirtualenv {
13361336
unset IFS
13371337
}
13381338

1339+
function _virtualenvwrapper_version {
1340+
"$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' --version
1341+
}
1342+
13391343
#:help:virtualenvwrapper: show this help message
13401344
function virtualenvwrapper {
1345+
typeset version=$(_virtualenvwrapper_version)
13411346
cat <<EOF
13421347
13431348
virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
@@ -1350,6 +1355,12 @@ For more information please refer to the documentation:
13501355
13511356
http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html
13521357
1358+
Version: $version
1359+
Script: $VIRTUALENVWRAPPER_SCRIPT
1360+
Python: $VIRTUALENVWRAPPER_PYTHON
1361+
WORKON_HOME: $WORKON_HOME
1362+
PROJECT_HOME: $PROJECT_HOME
1363+
13531364
Commands available:
13541365
13551366
EOF

virtualenvwrapper/hook_loader.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,20 @@ def main():
7979
dest='names',
8080
default=[],
8181
)
82+
parser.add_option(
83+
'--version',
84+
help='Show the version of virtualenvwrapper',
85+
action='store_true',
86+
default=False,
87+
)
8288
parser.disable_interspersed_args() # stop when on option without an '-'
8389
options, args = parser.parse_args()
8490

91+
if options.version:
92+
import importlib.metadata
93+
print(importlib.metadata.version('virtualenvwrapper'))
94+
return 0
95+
8596
root_logger = logging.getLogger('virtualenvwrapper')
8697

8798
# Set up logging to a file

0 commit comments

Comments
 (0)