Skip to main content

Prepare a virtual environment for moving to another directory

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

venv_retarget-0.1.1.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

venv_retarget-0.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file venv_retarget-0.1.1.tar.gz.

File metadata

  • Download URL: venv_retarget-0.1.1.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for venv_retarget-0.1.1.tar.gz
Algorithm Hash digest
SHA256 664a775cef0322a04d1d8196e66fb15db4d41298b657762c9d83f4f11a3a0101
MD5 f46a98949a28c41dada5fa1683352600
BLAKE2b-256 edc74048f92ee6905803019463a1fb9e9cc6d3e9672c738a73597ae41effe435

See more details on using hashes here.

File details

Details for the file venv_retarget-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: venv_retarget-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for venv_retarget-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb5e748d9215d4309069d2c24ebffbc93acf5ee70a9d7c45f2065efc117722b1
MD5 b7a00267a08d6636f34ee97917e01427
BLAKE2b-256 acb0a38f6346bcbf609aded37b2394b07daa90a444d54c483e837d1efe75d3eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page