Skip to main content

venv-retarget - prepare a virtual environment for moving to another directory

[Home | Download | GitLab | PyPI | ReadTheDocs]

Overview

The venv-retarget tool modifies several files within a virtual environment so that their contents will correspond to what the venv module would have done if that virtual environment were created in a different directory. This may be useful if a virtual environment is created with the intention of being packaged and copied over to other systems in a shared path.

Invocation

venv-retarget [-qv] detect [--use-prefix] path/to/venv

venv-retarget [-qv] retarget
	[-d /dest/venv | --venvdst /dest/venv]
	[-s /source/venv | --venvsrc /source/venv]
	path/to/venv

venv-retarget --features

venv-retarget --help

Detect the path stored into a virtual environment's files

The detect subcommand causes venv-retarget to examine the files within the virtual environment and check several places where venv records the path to the virtual environment:

  • the command = ... line in the pyvenv.cfg file
  • the paths to the source files stored in the precompiled __pycache__/*.pyc files
  • if --use-prefix is specified, the sys.prefix value from the Python interpreter within the virtual environment

Note that the sys.prefix value will reflect the current location of the virtual environment, so if it has already been moved, this path will differ from the rest and result in the detect subcommand failing because of inconsistent paths.

Change the paths to reflect a new location for the virtual environment

The main purpose of the venv-retarget tool is the retarget subcommand: look for files within the virtual environment that record the source path (either specified with the -s / --venvsrc command-line option, or autodetected as per the detect subcommand), and modifies those files to refer to the destination path (either specified with the -d / --venvdst command-line option, or the current path to the virtual environment). This allows retarget to be used in three ways:

  • after the virtual environment was created in a temporary location, in order to prepare to move it to either a temporary buildroot location or its final one
  • after the virtual environment has been moved to a temporary buildroot location
  • after the virtual environment has been moved to its final location

In each of the three cases, the source directly should generally not need to be specified. In any but the last case, the destination directory should be specified, or venv-retarget will record the temporary location of the virtual environment instead.

Examples

Figure out what the files within a virtual environment think about where it is at:

venv-retarget detect /path/to/venv

Prepare the files in an existing virtual environment to be moved somewhere else:

venv-retarget retarget -d /usr/libexec/venvs/agent agent-venv

Update the files after a virtual environment has been moved:

venv-retarget retarget -s /home/build/program/agent-venv buildroot/usr/libexec/venvs/agent

The same, but let the venv-retarget tool figure out the source directory by examining the contents of the files within the virtual environment, e.g. when the installation program was able to copy the files directly to the destination directory instead of a temporary buildroot:

venv-retarget retarget /usr/libexec/venvs/agent

Contact

The venv-retarget tool was written by Peter Pentchev. It is developed in a GitLab repository. This documentation is hosted at Ringlet with a copy at ReadTheDocs.

Metadata

Release files for venv-retarget 0.1.1

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

Source distribution (sdist)

Source distribution for venv-retarget 0.1.1
File Size Uploaded
venv_retarget-0.1.1.tar.gz 56.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for venv-retarget 0.1.1
File Interpreter ABI Platform
venv_retarget-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 69.6 kB

Release files / venv_retarget-0.1.1.tar.gz

Download URL venv_retarget-0.1.1.tar.gz
Size 56.5 kB
Tags Source
SHA-256 checksum
How to use checksums
664a775cef0322a04d1d8196e66fb15db4d41298b657762c9d83f4f11a3a0101
BLAKE2b-256 checksum
How to use checksums
edc74048f92ee6905803019463a1fb9e9cc6d3e9672c738a73597ae41effe435
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / venv_retarget-0.1.1-py3-none-any.whl

Download URL venv_retarget-0.1.1-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb5e748d9215d4309069d2c24ebffbc93acf5ee70a9d7c45f2065efc117722b1
BLAKE2b-256 checksum
How to use checksums
acb0a38f6346bcbf609aded37b2394b07daa90a444d54c483e837d1efe75d3eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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