dephell venv run

Runs command in the virtual environment of current project and environment.

  1. If the virtual environment doesn’t exist DepHell will create it.
  2. If script doesn’t exist in the virtual environment DepHell tries to install it from PyPI.

For example, get help for sphinx-build from docs environment of current project:

$ dephell venv run --env=docs sphinx-build --help

Command can be specified in the config:

command = "sphinx-build --help"

In this case command can be omitted:

$ dephell venv run --env=docs

Environment variables

This command passes next environment variables into running command:

  1. Your current environment variables.
  2. Values from vars in config.
  3. Values from .env file.

example of .env file:

export POSTGRES_USERNAME="dephell"
export POSTGRES_PASSWORD="PasswordExample"

DepHell supports any format of .env file: export word optional, quotes optional, = can be surrounded by spaces. However, we recommend to use above format, because it allows you to use source command to load these variables in your current shell.

Features for .env file:

  1. Parameters expansion. In the example above POSTGRES_URL value will be expanded into psql://dephell:PasswordExample@localhost. If variable does not exist DepHell won’t touch it. You can explicitly escape $ sign (\$) to avoid expansion.
  2. Escape sequences. You can insert escape sequences like \n in values, and DepHell will process it.

Config example:

vars = {PYTHONPATH = "."}
command = "python"

vars = {TOXENV = "flake8"}
command = "tox"

Use .env for secret things like database credentials and vars in config for some environment-specific settings for running commands like environment for flake.

If you want to pass temporary variable that not intended to be stored in any file then just set this variable in your current shell:

$ CHECK=me dephell venv run python -c "print(__import__('os').environ['CHECK'])"
INFO running...
INFO command successfully completed

See also

  1. dephell venv shell to activate virtual environment for your current shell.