1
1
from __future__ import unicode_literals
2
2
3
3
import json
4
+ import os
4
5
from collections import namedtuple
5
6
6
7
import six
11
12
from tox .config import DepConfig , get_py_project_toml
12
13
from tox .constants import BUILD_ISOLATED , BUILD_REQUIRE_SCRIPT
13
14
14
- BuildInfo = namedtuple ("BuildInfo" , ["requires" , "backend_module" , "backend_object" ])
15
+ BuildInfo = namedtuple (
16
+ "BuildInfo" , ["requires" , "backend_module" , "backend_object" , "backend_paths" ],
17
+ )
15
18
16
19
17
20
def build (config , session ):
@@ -47,6 +50,17 @@ def build(config, session):
47
50
return perform_isolated_build (build_info , package_venv , config .distdir , config .setupdir )
48
51
49
52
53
+ def _ensure_importable_in_path (python_path , importable ):
54
+ """Figure out if the importable exists in the given path."""
55
+ mod_chunks = importable .split ("." )
56
+ pkg_path = python_path .join (* mod_chunks [:- 1 ])
57
+ if not pkg_path .exists ():
58
+ return False
59
+ if pkg_path .join (mod_chunks [- 1 ], "__init__.py" ).exists ():
60
+ return True
61
+ return pkg_path .join (mod_chunks [- 1 ] + ".py" ).exists ()
62
+
63
+
50
64
def get_build_info (folder ):
51
65
toml_file = folder .join ("pyproject.toml" )
52
66
@@ -84,7 +98,15 @@ def abort(message):
84
98
module = args [0 ]
85
99
obj = args [1 ] if len (args ) > 1 else ""
86
100
87
- return BuildInfo (requires , module , obj )
101
+ backend_paths = build_system .get ("backend-path" , [])
102
+ if not isinstance (backend_paths , list ):
103
+ abort ("backend-path key at build-system section must be a list, if specified" )
104
+ backend_paths = [folder .join (p ) for p in backend_paths ]
105
+
106
+ if backend_paths and not any (_ensure_importable_in_path (p , module ) for p in backend_paths ):
107
+ abort ("build-backend must exist in one of the paths specified by backend-path" )
108
+
109
+ return BuildInfo (requires , module , obj , backend_paths )
88
110
89
111
90
112
def perform_isolated_build (build_info , package_venv , dist_dir , setup_dir ):
@@ -103,6 +125,7 @@ def perform_isolated_build(build_info, package_venv, dist_dir, setup_dir):
103
125
str (dist_dir ),
104
126
build_info .backend_module ,
105
127
build_info .backend_object ,
128
+ os .path .pathsep .join (str (p ) for p in build_info .backend_paths ),
106
129
],
107
130
returnout = True ,
108
131
action = action ,
0 commit comments