dlt.common.runners.venv
Venv Objects
class Venv()
Creates and wraps the Python Virtual Environment to allow for code execution
__init__
def __init__(context: types.SimpleNamespace, current: bool = False) -> None
Please use Venv.create
, Venv.restore
or Venv.restore_current
methods to create Venv instance
create
@classmethod
def create(cls, venv_dir: str, dependencies: List[str] = None) -> "Venv"
Creates a new Virtual Environment at the location specified in venv_dir
and installs dependencies
via pip. Deletes partially created environment on failure.
restore
@classmethod
def restore(cls, venv_dir: str, current: bool = False) -> "Venv"
Restores Virtual Environment at venv_dir
restore_current
@classmethod
def restore_current(cls) -> "Venv"
Wraps the current Python environment.
delete_environment
def delete_environment() -> None
Deletes the Virtual Environment.
run_command
def run_command(entry_point: str, *script_args: Any) -> str
Runs any command
with specified script_args
. Current os.environ
and cwd is passed to executed process
run_script
def run_script(script_path: str, *script_args: Any) -> str
Runs a python script
source with specified script_args
. Current os.environ
and cwd is passed to executed process
run_module
def run_module(module: str, *module_args: Any) -> str
Runs a python module
with specified module_args
. Current os.environ
and cwd is passed to executed process
set_pip_tool
@staticmethod
def set_pip_tool(pip_tool: str) -> ContextManager[None]
Sets pip tool in context manager, not thread safe
get_pip_tool
@staticmethod
def get_pip_tool() -> str
Gets configured tool to manage python packages, using DLT_PIP_TOOL or by
autodetecting uv
and pip
.
get_pip_command
@staticmethod
def get_pip_command(context: types.SimpleNamespace, command: str) -> List[str]
Returns a sequence that is a pip-like command
install_deps
@staticmethod
def install_deps(context: types.SimpleNamespace,
dependencies: List[str]) -> None
Install a set of dependencies
into Venv context using current pip tool. Makes
sure that the right command context and arguments are used.
is_virtual_env
@staticmethod
def is_virtual_env() -> bool
Checks if we are running in virtual environment
is_venv_activated
@staticmethod
def is_venv_activated() -> bool
Checks if virtual environment is activated in the shell