Isolate util/gpg

This commit is contained in:
Douglas Jacobsen 2023-10-12 19:19:20 -06:00
parent 30cafc553a
commit 3fd543328b
4 changed files with 11 additions and 10 deletions

View File

@ -12,6 +12,7 @@
import spack.bootstrap
import spack.util.executable
import spack.util.gpg
import spack.paths
from spack.main import SpackCommand
from spack.paths import mock_gpg_data_path, mock_gpg_keys_path
from spack.util.executable import ProcessError
@ -46,9 +47,9 @@ def test_find_gpg(cmd_name, version, tmpdir, mock_gnupghome, monkeypatch):
monkeypatch.setenv("PATH", str(tmpdir))
if version == "undetectable" or version.endswith("1.3.4"):
with pytest.raises(spack.util.gpg.SpackGPGError):
spack.util.gpg.init(force=True)
spack.util.gpg.init(force=True, gpg_path=spack.paths.gpg_path)
else:
spack.util.gpg.init(force=True)
spack.util.gpg.init(force=True, gpg_path=spack.paths.gpg_path)
assert spack.util.gpg.GPG is not None
assert spack.util.gpg.GPGCONF is not None
@ -57,7 +58,7 @@ def test_no_gpg_in_path(tmpdir, mock_gnupghome, monkeypatch, mutable_config):
monkeypatch.setenv("PATH", str(tmpdir))
bootstrap("disable")
with pytest.raises(RuntimeError):
spack.util.gpg.init(force=True)
spack.util.gpg.init(force=True, gpg_path=spack.paths.gpg_path)
@pytest.mark.maybeslow

View File

@ -1074,7 +1074,7 @@ def mock_gnupghome(monkeypatch):
# This comes up because tmp paths on macOS are already long-ish, and
# pytest makes them longer.
try:
spack.util.gpg.init()
spack.util.gpg.init(gpg_path=spack.paths.gpg_path)
except spack.util.gpg.SpackGPGError:
if not spack.util.gpg.GPG:
pytest.skip("This test requires gpg")

View File

@ -7,12 +7,13 @@
import pytest
import spack.paths
import spack.util.gpg
@pytest.fixture()
def has_socket_dir():
spack.util.gpg.init()
spack.util.gpg.init(gpg_path=spack.paths.gpg_path)
return bool(spack.util.gpg.SOCKET_DIR)

View File

@ -8,8 +8,7 @@
import os
import re
import spack.error
import spack.paths
import spack.util.error
import spack.util.executable
import spack.version
@ -29,7 +28,7 @@ def clear():
GPG, GPGCONF, SOCKET_DIR, GNUPGHOME = None, None, None, None
def init(gnupghome=None, force=False):
def init(gnupghome=None, force=False, gpg_path=None):
"""Initialize the global objects in the module, if not set.
When calling any gpg executable, the GNUPGHOME environment
@ -56,7 +55,7 @@ def init(gnupghome=None, force=False):
return
# Set the value of GNUPGHOME to be used in this module
GNUPGHOME = gnupghome or os.getenv("SPACK_GNUPGHOME") or spack.paths.gpg_path
GNUPGHOME = gnupghome or os.getenv("SPACK_GNUPGHOME") or gpg_path
# Set the executable objects for "gpg" and "gpgconf"
with spack.bootstrap.ensure_bootstrap_configuration():
@ -165,7 +164,7 @@ def _get_unimported_public_keys(output):
return keys
class SpackGPGError(spack.error.SpackError):
class SpackGPGError(spack.util.error.UtilityError):
"""Class raised when GPG errors are detected."""