|
| 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. |
0 commit comments