Skip to main content

You can manage virtualenv based utilities with this utility. Its primary use in addition to installing and updating is creating links (in /usr/local/bin) for utilities that are installed in separate virtualenvs.

Originally it only created alias definitions that could be ‘sourced’ into bash. But those aliases were difficult to use from non-login shells (and crontab etc). It still can generate those aliases, but only does so for those commands for which it cannot find a link in /usr/local/bin/

In such a setup, where you have a separate virtualenv for each utility, you don’t want to extend your path with the bin directory of each of the virtualenvs, as that gives you:

  • a long PATH

  • multiple python executables in your PATH

  • all utilties that are a result of installing some Python package dependency and for which you might want to use a different version (or not all).

If during install / update /usr/local/bin cannot be written to, the program will call sudo ln -s /usr/local/bin/yourutil /opt/util/yourutil/bin/yourutil (or similar) that will prompt you for the root privilages password.

Of course directly specifying the full path to your virtualenv based utility works as well.

Aliases

This is no longer needed.

virtualenvutils alias dir1 dir2 scans directories, non-recursive, under dir1`, ``dir2 for virtualenvs. Any directory containing bin, lib, include subdirectories as well as a file bin/activate is considered a virtualenv.

For any of those virtualenvs it does one of following (checked in this order):

  • if there is a virtualenvutils.conf file it is loaded to determine the utilties and possibly their mapping.

  • if the name of the directory under dir1, etc., is e.g. do_xyx, and dir1/do_xyz/bin/do_xyz exists and is executable then this is the utility

  • if there is no matching name, then all of the executable files under bin except those matching activate*, easy_install*, pip*, python*, wheel* are considered utilities, unless they have extensions matching “.so”, “.py”, or “.pyc”.

the utility then generates aliases for all utilities found this way, making sure they are unique if added by the last method, and writes those alias definitions to stdout. Any error go to stderr.

Other functionalities include:

  • updating all packages for all virtualenvs

see virtualenvutils --help for the full list of subcommands

virtualenvutils.conf

The virtualenvutils.conf file, if provided, has to be in the toplevel directory of the virtualenv (i.e. next to bin, include and lib and consist of single line with or without a colon (:).

If there is no colon, then the line is considered to be the name of an executable file under that virtualenvs bin.

If there is a colon, the part before the colon is considered the name for executable under bin, for which the executable name is the part behind the colon.

Example

You want to install docker-compose in a virtualenv. If you do:

mkvirtualenv -p /opt/python3/bin/python /opt/util/docker-compose
source !$/bin/activate
pip install docker-compose
deactivate

you will need to call it with:

/opt/util/docker-compose/bin/docker-compose

If you would have specified a different final directory:

mkvirtualenv -p /opt/python3/bin/python /opt/util/compose
source !$/bin/activate
pip install docker-compose
deactivate

you will need to use:

/opt/util/compose/bin/docker-compose

The above can resp. be done using virtualenvutils by using:

virtualenvutils install /opt/util/docker-compose

and:

virtualenvutils install /opt/util/compose --pkg docker-compose

respectively. In both instances a link /usr/local/bin/docker-compose will be created that will be able to start your utility.

Installing virtualenvutils

To bootstrap virtualenvutils:

mkvirtualenv -p /opt/python3/bin/python /opt/util/virtualenvutils
source !$/bin/activate
pip install virtualenvutils
virtualenvutils update virtualenvutils  # this will create the link
deactivate

after which you can use plain virtualenvutils as long as /usr/local/bin is in your PATH.

Updating existing virtualenvs

You can update all packages for all virtualenv utilities (under /opt/util) by using:

virtualenvutils update /opt/util

The arguments to update are checked to see if they are virtualenvs. If they are they get update on an individual basis. If they are not (as in the above example) each of their subdirs are checked to be virtualenvs (non-recursive).

Installing a new util

You can install one or more new virtualenv based utilities using something like:

virtualenvutils install /opt/util/{docker-compose,ruamel.yaml.cmd}

You can use --pkg to give a package name that differs from the final part of the path (in which case you can of course only specify one path), and with --python /opt/python/3/bin/python you can explicitly specify the python version to use.

Don’t forget that you probably have to logout and login for if you set your aliases through as scan initiated in .bashrc, before you can use the commands.

Release files for virtualenvutils 0.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for virtualenvutils 0.6.3
File Size Uploaded
virtualenvutils-0.6.3.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for virtualenvutils 0.6.3
File Interpreter ABI Platform
virtualenvutils-0.6.3-py3-none-any.whl Python 3 none any Details

Total release size: 35.3 kB

Release files / virtualenvutils-0.6.3.tar.gz

Download URL virtualenvutils-0.6.3.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
929086073e528ded0a12d942f20d123bbc89fa5a91808d70147cd8589202f9a7
BLAKE2b-256 checksum
How to use checksums
5f38704d049e9f093cf80a8e6d4a9431744a81901b0a68ddb4cf30d65600232d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / virtualenvutils-0.6.3-py3-none-any.whl

Download URL virtualenvutils-0.6.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2862742f2427adf3cbc80ea6305e4e15c9443f0d742b9ba9db77c39315770fd7
BLAKE2b-256 checksum
How to use checksums
67e0732e147a867705247d0ced58189e2a8ebb777b2c59884f4ff7455206f428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.6.3 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page