qldpc.external.gap

Module for communicating with the GAP computer algebra system.

See https://www.gap-system.org.

Attributes

GAP_ROOT

Functions

get_output(→ str)

Get the output from the given GAP commands.

is_callable(→ bool)

Can we call GAP 4 from the command line?

is_installed(→ bool)

Is GAP 4 installed?

require_package(→ bool)

Enforce the installation of a GAP package.

sanitize_commands(→ tuple[str, ...])

Sanitize GAP commands: don't format Print statements, and quit at the end.

Module Contents

qldpc.external.gap.get_output(*commands: str, use_pipe: bool = False) → str[source]

Get the output from the given GAP commands.

When GAP is callable, this function runs the commands in a subprocess. Otherwise it falls back to a manual workflow that prints the commands, copies them to the system clipboard, and reads the pasted output from standard input (blocking, and raising EOFError if standard input is closed), caching the result to disk.

Raises:
  • FileNotFoundError – If GAP 4 is not installed.

  • ValueError – If GAP reports an error (a nonzero exit code or output on standard error).

qldpc.external.gap.is_callable() → bool[source]

Can we call GAP 4 from the command line?

qldpc.external.gap.is_installed() → bool[source]

Is GAP 4 installed?

When GAP is not callable from the command line, this function prompts on standard input, so it blocks in a non-interactive context (and raises EOFError if standard input is closed).

qldpc.external.gap.require_package(name: str, repo: str | None = None) → bool[source]

Enforce the installation of a GAP package.

If the package is missing and GAP is callable, this function prompts on standard input and, with the user’s consent, installs it by running git clone into the GAP root’s pkg directory.

Parameters:
  • name – The GAP package name.

  • repo – The repository from which to git clone the package, if necessary. Defaults to f”https://github.com/gap-packages/{name}” if no repository is provided.

Raises:
  • ModuleNotFoundError – If the package is missing and GAP cannot be called to install it.

  • ValueError – If the user declines to install a missing package, or the installation fails.

Returns:

True if the requirement is satisfied (raises an error otherwise).

qldpc.external.gap.sanitize_commands(commands: collections.abc.Sequence[str]) → tuple[str, ...][source]

Sanitize GAP commands: don’t format Print statements, and quit at the end.

qldpc.external.gap.GAP_ROOT