Skip to content

Commit 746bda8

Browse files
committed
Add README
1 parent 272edce commit 746bda8

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

README.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
pyenv-users
2+
===========
3+
4+
Search a directory for virtual environments that use pyenv-managed versions of
5+
Python.
6+
7+
I find it helpful for verifying that I can safely uninstall old Python
8+
versions. Unlike the `pyenv-virtualenv
9+
<https://github.com/pyenv/pyenv-virtualenv>`_ plugin, this will list all
10+
virtual environments, regardless of how they were created (``python -m venv
11+
<venv>``, ``poetry install``, etc).
12+
13+
14+
Prerequisites
15+
-------------
16+
17+
Requires ``find`` from GNU ``findutils`` to collect a list of candidates.
18+
19+
Uses ``column`` from the ``util-linux`` package (if available) for
20+
pretty-printing the output. If ``column`` is not available, the output is the
21+
simple form ``<version>:<venv path>``.
22+
23+
24+
Installation
25+
------------
26+
27+
Verify that ``$PYENV_ROOT`` has been configured:
28+
29+
.. code-block:: bash
30+
31+
$ echo $PYENV_ROOT
32+
33+
Install the plugin:
34+
35+
.. code-block:: bash
36+
37+
$ git clone https://github.com/pfheatwole/pyenv-users.git "$PYENV_ROOT"/plugins/pyenv-users
38+
39+
40+
Usage
41+
-----
42+
43+
Run ``pyenv users`` to search the current directory for virtual environments,
44+
or ``pyenv users <directory>`` to search a specific directory. For example, to
45+
search your home directory:
46+
47+
.. code-block:: bash
48+
49+
$ pyenv users ~
50+
3.7.9 /home/peter/.cache/pypoetry/virtualenvs/my_project-KM_3YcvM-py3.7
51+
3.7.9 /home/peter/work/venvs/long name with spaces
52+
3.8.6 /home/peter/.cache/pypoetry/virtualenvs/my_project-KM_3YcvM-py3.8
53+
pypy3.6-7.3.1 /home/peter/work/venvs/example1
54+
55+
56+
Disclaimer
57+
----------
58+
59+
I'm not a script writer so it's probably a bit crude. It's not blazingly fast,
60+
since it uses a brute force scan, but on my system it only takes 3 seconds,
61+
and I like the simplicity.
62+
63+
I've been using it on Fedora 33 with no issues, but it could use more testing.
64+
In particular, users on MacOS and Windows will probably prefer the addition of
65+
a pretty-printing solution that doesn't rely on ``column``.
66+
67+
Also, I seem to recall that not all versions of ``column`` support the ``-s``
68+
parameter for setting the separator. I haven't had time to research that.
69+
70+
Tested with ``bash v5.0.17(1)``, ``find v4.7.0``, and ``column v2.36.1`` on
71+
Fedora 33.

bin/pyenv-users

100644100755
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
#
77
# Scans [directory] for virtual environments whose `python` commands
88
# are symlinks back into a pyenv version. Default: current directory.
9-
#
10-
# I'm not a script writer so it's probably a bit crude, but I find it
11-
# helpful for checking if I can uninstall old Python versions. Uses
12-
# the `column` command from the util-linux package (if available) for
13-
# pretty-printing the output.
149

1510
if [ -n "$1" ]; then
1611
DIR="$1"
@@ -49,4 +44,4 @@ for link in "${links[@]}"; do
4944
version="${BASH_REMATCH[1]}"
5045
echo "$version":"${link%/bin/python}"
5146
fi
52-
done | sort | $output
47+
done | sort | $output

0 commit comments

Comments
 (0)