ctfsolver.venv.testing.main

Attributes

m

Classes

VenvInfo

ManagerVenv

Cross-platform venv manager that can create, link, resolve and operate inside virtual environments

Module Contents

class VenvInfo[source]
name: str[source]
path: pathlib.Path[source]
python: pathlib.Path[source]
platform: str[source]
created_at: float[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]
venv: VenvInfo | None = None[source]
check_venv_dir()[source]

Create a project shortcut to an existing venv. Prefer a symlink (POSIX) or junction/symlink (Windows). Fallback to .venv.link text file.

Parameters:
Return type:

None

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:
Return type:

VenvInfo

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.

Parameters:
Return type:

str

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:
Return type:

subprocess.CompletedProcess

detect_venvs(root, recursive=True)[source]

Yield venv directories under root.

Parameters:
Return type:

Iterable[pathlib.Path]

list_venvs()[source]

List venvs in the global directory.

Return type:

list[VenvInfo]

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:
Return type:

tuple[pathlib.Path, pathlib.Path]

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:
Return type:

pathlib.Path

delete(venv_path, force=False)[source]

Delete a venv directory recursively.

Parameters:
Return type:

None

Create a global venv and link it to the given project (default: CWD).

Parameters:
Return type:

VenvInfo

static summarize(info)[source]
Parameters:

info (VenvInfo)

Return type:

str

m[source]