ctfsolver.venv.testing.main¶
Attributes¶
Classes¶
Cross-platform venv manager that can create, link, resolve and operate inside virtual environments |
Module Contents¶
- class VenvInfo[source]¶
-
- path: pathlib.Path[source]¶
- python: pathlib.Path[source]¶
- class ManagerVenv[source]¶
Cross-platform venv manager that can create, link, resolve and operate inside virtual environments without in-process “activation”. Instead, it uses the venv’s interpreter directly.
- Conventions:
Global root for venvs is taken from CONFIG[“directories”][“venvs”] (preferred), else $CTFSOLVER_VENVS_HOME, else POSIX: ~/.local/share/ctfsolver/venvs, Windows: %APPDATA%ctfsolvervenvs
Project shortcut: .venv (symlink/junction) preferred; fallback .venv.link text file containing absolute path to the real venv directory.
- Public methods cover:
create (backend: stdlib venv or virtualenv)
link/unlink shortcuts
resolve_for current project
activation_command printer
run_in (execute using the venv’s python)
detect_venvs, export_lockfiles (pip freeze + pipdeptree)
transfer, delete, list_venvs
- venv_dir: pathlib.Path | None[source]¶
- link(project_dir, venv_path)[source]¶
Create a project shortcut to an existing venv. Prefer a symlink (POSIX) or junction/symlink (Windows). Fallback to .venv.link text file.
- Parameters:
project_dir (pathlib.Path)
venv_path (pathlib.Path)
- Return type:
None
- unlink(project_dir)[source]¶
- Parameters:
project_dir (pathlib.Path)
- Return type:
None
- resolve_for(project_dir)[source]¶
Resolve VenvInfo for a project directory, if a shortcut/link exists.
- Parameters:
project_dir (pathlib.Path)
- Return type:
Optional[VenvInfo]
- create(name, python=None, in_project=False, project_dir=None, backend='venv', with_pip=True)[source]¶
Create a venv using stdlib venv or virtualenv, return VenvInfo and link to project_dir if provided.
- Parameters:
name (str)
python (Optional[pathlib.Path])
in_project (bool)
project_dir (Optional[pathlib.Path])
backend (str)
with_pip (bool)
- Return type:
- activation_command(venv, shell=None)[source]¶
Return the shell command string to activate the venv. Does not execute it. shell: one of {‘bash’,’zsh’,’fish’,’pwsh’,’cmd’} or None to auto-detect.
- run_in(venv_path, args, *, cwd=None, env=None, check=True, capture_output=False)[source]¶
Execute a command using the venv’s python interpreter: python -m <module> … or arbitrary script. If args[0] == ‘-m’, we run ‘python -m …’; otherwise we execute the given argv via the venv’s python.
- Parameters:
venv_path (pathlib.Path)
args (Sequence[str])
cwd (Optional[pathlib.Path])
check (bool)
capture_output (bool)
- Return type:
- detect_venvs(root, recursive=True)[source]¶
Yield venv directories under root.
- Parameters:
root (pathlib.Path)
recursive (bool)
- Return type:
Iterable[pathlib.Path]
- export_lockfiles(venv_path, out_dir)[source]¶
Create requirements.txt and pipdeptree.txt for venv. If pipdeptree is not installed, install temporarily and remove afterwards.
- Parameters:
venv_path (pathlib.Path)
out_dir (pathlib.Path)
- Return type:
- transfer(venv_path, dest_root=None, move=True)[source]¶
Move or copy a venv to the global store (or a custom root). Returns the new path.
- Parameters:
venv_path (pathlib.Path)
dest_root (Optional[pathlib.Path])
move (bool)
- Return type:
- delete(venv_path, force=False)[source]¶
Delete a venv directory recursively.
- Parameters:
venv_path (pathlib.Path)
force (bool)
- Return type:
None
- create_and_link_current(name, *, python=None, backend='venv', with_pip=True, project_dir=None)[source]¶
Create a global venv and link it to the given project (default: CWD).
- Parameters:
name (str)
python (Optional[pathlib.Path])
backend (str)
with_pip (bool)
project_dir (Optional[pathlib.Path])
- Return type: