mirror of https://github.com/pypa/pep517.git
Explicitly raise an exception if backend isn't available
This commit is contained in:
parent
567cd47653
commit
81cfee6274
|
@ -21,11 +21,17 @@ import sys
|
|||
# This is run as a script, not a module, so it can't do a relative import
|
||||
import compat
|
||||
|
||||
class BackendUnavailable(Exception):
|
||||
"""Raised if we cannot import the backend"""
|
||||
|
||||
def _build_backend():
|
||||
"""Find and load the build backend"""
|
||||
ep = os.environ['PEP517_BUILD_BACKEND']
|
||||
mod_path, _, obj_path = ep.partition(':')
|
||||
obj = import_module(mod_path)
|
||||
try:
|
||||
obj = import_module(mod_path)
|
||||
except ImportError:
|
||||
raise BackendUnavailable
|
||||
if obj_path:
|
||||
for path_part in obj_path.split('.'):
|
||||
obj = getattr(obj, path_part)
|
||||
|
@ -173,6 +179,8 @@ def main():
|
|||
json_out = {'unsupported': False, 'return_val': None}
|
||||
try:
|
||||
json_out['return_val'] = hook(**hook_input['kwargs'])
|
||||
except BackendUnavailable:
|
||||
json_out['no_backend'] = True
|
||||
except GotUnsupportedOperation:
|
||||
json_out['unsupported'] = True
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ def tempdir():
|
|||
finally:
|
||||
shutil.rmtree(td)
|
||||
|
||||
class BackendUnavailable(Exception):
|
||||
"""Will be raised if the backend cannot be imported in the hook process."""
|
||||
|
||||
class UnsupportedOperation(Exception):
|
||||
"""May be raised by build_sdist if the backend indicates that it can't."""
|
||||
|
||||
|
@ -130,5 +133,7 @@ class Pep517HookCaller(object):
|
|||
data = compat.read_json(pjoin(td, 'output.json'))
|
||||
if data.get('unsupported'):
|
||||
raise UnsupportedOperation
|
||||
if data.get('no_backend'):
|
||||
raise BackendUnavailable
|
||||
return data['return_val']
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ import pytest
|
|||
import pytoml
|
||||
import zipfile
|
||||
|
||||
from pep517.wrappers import Pep517HookCaller, UnsupportedOperation
|
||||
from pep517.wrappers import Pep517HookCaller
|
||||
from pep517.wrappers import UnsupportedOperation, BackendUnavailable
|
||||
|
||||
SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
|
||||
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')
|
||||
|
@ -18,6 +19,12 @@ def get_hooks(pkg):
|
|||
data = pytoml.load(f)
|
||||
return Pep517HookCaller(source_dir, data['build-system']['build-backend'])
|
||||
|
||||
def test_missing_backend_gives_exception():
|
||||
hooks = get_hooks('pkg1')
|
||||
with modified_env({'PYTHONPATH': ''}):
|
||||
with pytest.raises(BackendUnavailable):
|
||||
res = hooks.get_requires_for_build_wheel({})
|
||||
|
||||
def test_get_requires_for_build_wheel():
|
||||
hooks = get_hooks('pkg1')
|
||||
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
|
||||
|
|
Loading…
Reference in New Issue