Skip to content

Commit

Permalink
fix bug with identifying whether GAP is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
perlinm committed Aug 15, 2024
1 parent eee6c56 commit 83ebd28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion checks/all_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import checks_superstaq

if __name__ == "__main__":
skip_args = ["--ruff", "--skip", "requirements", "--"]
skip_args = ["--ruff", "--skip", "requirements", "build_docs", "--"]
exit(checks_superstaq.all_.run(*skip_args, *sys.argv[1:], sphinx_paths=["../qldpc"]))
9 changes: 7 additions & 2 deletions qldpc/external/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from __future__ import annotations

import functools
import re
import subprocess
import urllib.error
Expand Down Expand Up @@ -113,11 +114,15 @@ def get_generators_from_groupnames(group: str) -> GENERATORS_LIST | None:
return generators


@functools.cache
def gap_is_installed() -> bool:
"""Is GAP 4 installed?"""
commands = ["gap", "-q", "-c", r'Print(GAPInfo.Version, "\n"); QUIT;']
result = subprocess.run(commands, capture_output=True, text=True)
return bool(re.match(r"\n4\.[0-9]+\.[0-9]+$", result.stdout))
try:
result = subprocess.run(commands, capture_output=True, text=True)
return bool(re.match(r"\n4\.[0-9]+\.[0-9]+$", result.stdout))
except Exception:
return False


def sanitize_gap_commands(commands: Sequence[str]) -> tuple[str, ...]:
Expand Down
8 changes: 6 additions & 2 deletions qldpc/external/groups_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ def get_mock_process(stdout: str) -> subprocess.CompletedProcess[str]:

def test_gap_is_installed() -> None:
"""Is GAP 4 installed?"""
with unittest.mock.patch("subprocess.run", return_value=get_mock_process("")):
assert not external.groups.gap_is_installed()
with unittest.mock.patch("subprocess.run", return_value=get_mock_process("\n4.12.1")):
assert external.groups.gap_is_installed()
external.groups.gap_is_installed.cache_clear()
with unittest.mock.patch("subprocess.run", return_value=get_mock_process("")):
assert not external.groups.gap_is_installed()
external.groups.gap_is_installed.cache_clear()
with unittest.mock.patch("subprocess.run", side_effect=Exception):
assert not external.groups.gap_is_installed()


def test_get_gap_result() -> None:
Expand Down

0 comments on commit 83ebd28

Please sign in to comment.