|
40 | 40 | from pex.exceptions import production_assert |
41 | 41 | from pex.fingerprinted_distribution import FingerprintedDistribution |
42 | 42 | from pex.installed_wheel import InstalledWheel |
43 | | -from pex.jobs import Raise, SpawnedJob, execute_parallel, iter_map_parallel |
| 43 | +from pex.jobs import Job, Raise, SpawnedJob, execute_parallel, iter_map_parallel |
44 | 44 | from pex.network_configuration import NetworkConfiguration |
45 | 45 | from pex.orderedset import OrderedSet |
46 | 46 | from pex.pep_425 import CompatibilityTags |
@@ -1060,43 +1060,58 @@ def _spawn_wheel_build(self, build_request): |
1060 | 1060 | # type: (BuildRequest) -> SpawnedJob[BuildResult] |
1061 | 1061 | source_path, editable = build_request.prepare() |
1062 | 1062 | build_result = build_request.result(source_path) |
| 1063 | + |
| 1064 | + def spawn_build_wheel(): |
| 1065 | + # type: () -> SpawnedJob[BuildResult] |
| 1066 | + build_job = get_pip( |
| 1067 | + interpreter=build_request.target.get_interpreter(), |
| 1068 | + version=self._pip_version, |
| 1069 | + resolver=self._resolver, |
| 1070 | + extra_requirements=( |
| 1071 | + self._package_index_configuration.extra_pip_requirements |
| 1072 | + if self._package_index_configuration is not None |
| 1073 | + else () |
| 1074 | + ), |
| 1075 | + ).spawn_build_wheels( |
| 1076 | + requirements=[source_path], |
| 1077 | + wheel_dir=build_result.build_dir, |
| 1078 | + package_index_configuration=self._package_index_configuration, |
| 1079 | + interpreter=build_request.target.get_interpreter(), |
| 1080 | + build_configuration=self._build_configuration, |
| 1081 | + verify=self._verify_wheels, |
| 1082 | + ) |
| 1083 | + return SpawnedJob.wait(job=build_job, result=build_result) |
| 1084 | + |
1063 | 1085 | if editable: |
1064 | 1086 | if not self._resolver: |
1065 | 1087 | raise BuildError( |
1066 | 1088 | "A resolver is required to build an local editable project.\n" |
1067 | 1089 | "Cannot build: {project}".format(project=source_path) |
1068 | 1090 | ) |
1069 | 1091 |
|
| 1092 | + def maybe_spawn_build_wheel(err): |
| 1093 | + # type: (Job.Error) -> SpawnedJob[BuildResult] |
| 1094 | + if pep_517.is_hook_unavailable_error(err): |
| 1095 | + return spawn_build_wheel() |
| 1096 | + raise err |
| 1097 | + |
1070 | 1098 | # N.B.: We're forced to do this ourselves because Pip refuses to honor its |
1071 | 1099 | # otherwise apparently supported `pip wheel -e ...` CLI interface. Pip ignores -e and |
1072 | 1100 | # silently builds a full wheel :/. |
1073 | 1101 | # See: https://github.com/pypa/pip/issues/12414 |
1074 | | - return pep_517.spawn_build_editable( |
1075 | | - project_directory=source_path, |
1076 | | - wheel_dir=build_result.build_dir, |
1077 | | - target=build_request.target, |
1078 | | - resolver=self._resolver, |
1079 | | - pip_version=self._pip_version, |
1080 | | - ).map(lambda _: build_result) |
| 1102 | + return ( |
| 1103 | + pep_517.spawn_build_editable( |
| 1104 | + project_directory=source_path, |
| 1105 | + wheel_dir=build_result.build_dir, |
| 1106 | + target=build_request.target, |
| 1107 | + resolver=self._resolver, |
| 1108 | + pip_version=self._pip_version, |
| 1109 | + ) |
| 1110 | + .map(lambda _: build_result) |
| 1111 | + .or_else(maybe_spawn_build_wheel) |
| 1112 | + ) |
1081 | 1113 |
|
1082 | | - build_job = get_pip( |
1083 | | - interpreter=build_request.target.get_interpreter(), |
1084 | | - version=self._pip_version, |
1085 | | - resolver=self._resolver, |
1086 | | - extra_requirements=( |
1087 | | - self._package_index_configuration.extra_pip_requirements |
1088 | | - if self._package_index_configuration is not None |
1089 | | - else () |
1090 | | - ), |
1091 | | - ).spawn_build_wheels( |
1092 | | - requirements=[source_path], |
1093 | | - wheel_dir=build_result.build_dir, |
1094 | | - package_index_configuration=self._package_index_configuration, |
1095 | | - interpreter=build_request.target.get_interpreter(), |
1096 | | - build_configuration=self._build_configuration, |
1097 | | - verify=self._verify_wheels, |
1098 | | - ) |
1099 | | - return SpawnedJob.wait(job=build_job, result=build_result) |
| 1114 | + return spawn_build_wheel() |
1100 | 1115 |
|
1101 | 1116 | def build_wheels( |
1102 | 1117 | self, |
|
0 commit comments