Add virtualEnvName config to Python hook executor
Background & Motivation
Python hook scripts default to {baseName}_env for virtual environments, but many Python projects use .venv by convention. Issue #7653 explicitly calls out virtualEnvName as a key config property. The Python framework service (framework_service_python.go) also hardcodes the venv name with no config override — hooks should lead in configurability here.
User Story
As a Python developer, I want to specify virtualEnvName in my hook config so that my Python hooks use my preferred virtual environment directory.
Solution Approach
- Read
Config["virtualEnvName"] in python_executor.go Prepare() phase via execCtx.Config
- Define a strongly-typed
pythonHookConfig struct and unmarshal from execCtx.Config:
type pythonHookConfig struct {
VirtualEnvName string `json:"virtualEnvName"` // override venv dir name
}
- If set, use as the venv name instead of
VenvNameForDir() default
- Validate it's a string, non-empty, and doesn't contain path separators (security: prevent path traversal)
- Pass to existing
EnsureVirtualEnv() and InstallDependencies() methods
Example azure.yaml
hooks:
postprovision:
run: ./hooks/seed.py
kind: python
config:
virtualEnvName: .venv
Acceptance Criteria
Default when omitted: Existing behavior — search for .venv/venv in project dir, then fall back to {baseName}_env
Out of Scope
- Python package manager selection (
uv, poetry, pdm) — future enhancement
- Custom requirements file name — future enhancement
- Python binary path override — future enhancement
Testing Expectations
- Unit tests: table-driven tests for config unmarshalling, validation, and venv name resolution
- Test path traversal rejection (e.g.,
../evil, foo/bar)
- Test empty string rejection
Related Issues
Add
virtualEnvNameconfig to Python hook executorBackground & Motivation
Python hook scripts default to
{baseName}_envfor virtual environments, but many Python projects use.venvby convention. Issue #7653 explicitly calls outvirtualEnvNameas a key config property. The Python framework service (framework_service_python.go) also hardcodes the venv name with no config override — hooks should lead in configurability here.User Story
As a Python developer, I want to specify
virtualEnvNamein my hook config so that my Python hooks use my preferred virtual environment directory.Solution Approach
Config["virtualEnvName"]inpython_executor.goPrepare()phase viaexecCtx.ConfigpythonHookConfigstruct and unmarshal fromexecCtx.Config:VenvNameForDir()defaultEnsureVirtualEnv()andInstallDependencies()methodsExample azure.yaml
Acceptance Criteria
config.virtualEnvName: .venvcreates/uses.venvdirectory for the hookconfig.virtualEnvName: my_envcreates/usesmy_envdirectoryvirtualEnvNamepreserves current behavior (search.venv/venv, fall back to{baseName}_env)/,\) are rejected with a clear errorDefault when omitted: Existing behavior — search for
.venv/venvin project dir, then fall back to{baseName}_envOut of Scope
uv,poetry,pdm) — future enhancementTesting Expectations
../evil,foo/bar)Related Issues
Config map[string]anyonExecutionContext