plesty.server.services.gitbin

Finding a git executable — and putting one on a bench that has none.

Installing a device module from its repository needs git. A Windows lab PC usually has none: git is not part of Windows, installing it system-wide is an administrator’s job, and the person at the bench is rarely one. So the bench keeps its own — the portable MinGit archive git-for-windows publishes, unpacked into <home>/tools/git and run from there. No installer, no PATH change, no administrator; fetched once, verified against the digest pinned in config.yaml, and found again on every later run.

A POSIX bench is told to install git instead. There it is one package-manager command, and system-wide is where it belongs.

Attributes

AUTO_ENV

GIT_DIR

ARCHITECTURES

Fetcher

Echo

POSIX_GIT_DIRECTORIES

Exceptions

GitUnavailable

No git on the bench, and none could be installed.

Functions

auto_install_enabled(→ bool)

Whether a missing git may be fetched (AUTO_ENV, else the packaged default).

bench_git(→ pathlib.Path)

Where the bench keeps its own git (whether or not one is there yet).

find_git(→ str | None)

A usable git: PATH first, then the usual installs, then the bench's own.

_candidates(→ collections.abc.Iterator[pathlib.Path])

Paths a git may sit at without being on PATH, best first.

install_git(→ str)

Unpack a portable git into <home>/tools/git; returns the executable.

_download(→ bytes)

GET url into memory (tens of MB), with the standard library.

_unpack(→ None)

Extract the verified zip archive into target.

Module Contents

plesty.server.services.gitbin.AUTO_ENV = 'PLESTY_SERVER_AUTO_GIT'
plesty.server.services.gitbin.GIT_DIR = 'git'
plesty.server.services.gitbin.ARCHITECTURES
plesty.server.services.gitbin.Fetcher
plesty.server.services.gitbin.Echo
exception plesty.server.services.gitbin.GitUnavailable

Bases: RuntimeError

No git on the bench, and none could be installed.

Initialize self. See help(type(self)) for accurate signature.

plesty.server.services.gitbin.auto_install_enabled() bool

Whether a missing git may be fetched (AUTO_ENV, else the packaged default).

Return type:

bool

plesty.server.services.gitbin.bench_git(home: plesty.server.model.home.Home) pathlib.Path

Where the bench keeps its own git (whether or not one is there yet).

Parameters:

home (plesty.server.model.home.Home)

Return type:

pathlib.Path

plesty.server.services.gitbin.find_git(home: plesty.server.model.home.Home) str | None

A usable git: PATH first, then the usual installs, then the bench’s own.

Parameters:

home (plesty.server.model.home.Home) – The bench home, which may hold a git of its own.

Returns:

The executable, or None when the bench has none.

Return type:

str | None

plesty.server.services.gitbin.POSIX_GIT_DIRECTORIES = ('/usr/bin', '/usr/local/bin', '/opt/homebrew/bin')
plesty.server.services.gitbin._candidates(home: plesty.server.model.home.Home) collections.abc.Iterator[pathlib.Path]

Paths a git may sit at without being on PATH, best first.

Parameters:

home (plesty.server.model.home.Home)

Return type:

collections.abc.Iterator[pathlib.Path]

plesty.server.services.gitbin.install_git(home: plesty.server.model.home.Home, echo: Echo | None = None, fetch: Fetcher | None = None) str

Unpack a portable git into <home>/tools/git; returns the executable.

Windows only: it is the platform where a bench routinely has no git and no way to install one. The archive is verified against the pinned digest before anything is unpacked — a mismatch is an error, not a warning.

Parameters:
Raises:

GitUnavailable – Not Windows, unknown architecture, download failed, digest mismatch, or the archive held no git.

Return type:

str

plesty.server.services.gitbin._download(url: str, timeout: float = 300.0) bytes

GET url into memory (tens of MB), with the standard library.

Parameters:
  • url (str)

  • timeout (float)

Return type:

bytes

plesty.server.services.gitbin._unpack(archive: bytes, target: pathlib.Path) None

Extract the verified zip archive into target.

Raises:

GitUnavailable – When the archive is not a readable zip.

Parameters:
  • archive (bytes)

  • target (pathlib.Path)

Return type:

None