@@ -47,18 +47,23 @@ def contained_in(filename, directory):
47
47
48
48
def _build_backend ():
49
49
"""Find and load the build backend"""
50
+ # Add in-tree backend directories to the front of sys.path.
51
+ backend_path = os .environ .get ('PEP517_BACKEND_PATH' )
52
+ if backend_path :
53
+ extra_pathitems = backend_path .split (os .pathsep )
54
+ sys .path [:0 ] = extra_pathitems
55
+
50
56
ep = os .environ ['PEP517_BUILD_BACKEND' ]
51
57
mod_path , _ , obj_path = ep .partition (':' )
52
58
try :
53
59
obj = import_module (mod_path )
54
60
except ImportError :
55
61
raise BackendUnavailable (traceback .format_exc ())
56
62
57
- backend_path = os .environ .get ('PEP517_BACKEND_PATH' )
58
63
if backend_path :
59
64
if not any (
60
65
contained_in (obj .__file__ , path )
61
- for path in backend_path . split ( os . pathsep )
66
+ for path in extra_pathitems
62
67
):
63
68
raise BackendInvalid ("Backend was not loaded from backend-path" )
64
69
@@ -222,11 +227,6 @@ def main():
222
227
223
228
hook_input = compat .read_json (pjoin (control_dir , 'input.json' ))
224
229
225
- # Add in-tree backend directories to the front of sys.path.
226
- backend_path = os .environ .get ('PEP517_BACKEND_PATH' )
227
- if backend_path :
228
- sys .path [:0 ] = backend_path .split (os .pathsep )
229
-
230
230
json_out = {'unsupported' : False , 'return_val' : None }
231
231
try :
232
232
json_out ['return_val' ] = hook (** hook_input ['kwargs' ])
0 commit comments