4
4
import subprocess
5
5
import shutil
6
6
import logging
7
+ from typing import Optional
7
8
8
9
from ci_tools .environment_exclusions import is_check_enabled
9
10
from ci_tools .variables import in_ci
@@ -172,7 +173,7 @@ def create_package_and_install(
172
173
logging .info ("Installed {w}" .format (w = built_package ))
173
174
174
175
175
- def replace_dev_reqs (file : str , pkg_root : str ) -> None :
176
+ def replace_dev_reqs (file : str , pkg_root : str , wheel_dir : Optional [ str ] ) -> None :
176
177
"""Takes a target requirements file, replaces all local relative install locations with wheels assembled from whatever that target path was.
177
178
This is an extremely important step that runs on every dev_requirements.txt file before invoking any tox runs.
178
179
@@ -181,6 +182,7 @@ def replace_dev_reqs(file: str, pkg_root: str) -> None:
181
182
182
183
:param str file: the absolute path to the dev_requirements.txt file
183
184
:param str pkg_root: the absolute path to the package's root
185
+ :param Optional[str] wheel_dir: the absolute path to the prebuilt wheel directory
184
186
:return: None
185
187
"""
186
188
adjusted_req_lines = []
@@ -198,7 +200,7 @@ def replace_dev_reqs(file: str, pkg_root: str) -> None:
198
200
if extras :
199
201
extras = f"[{ extras } "
200
202
201
- adjusted_req_lines .append (f"{ build_whl_for_req (amended_line , pkg_root )} { extras } " )
203
+ adjusted_req_lines .append (f"{ build_whl_for_req (amended_line , pkg_root , wheel_dir )} { extras } " )
202
204
203
205
req_file_name = os .path .basename (file )
204
206
logging .info ("Old {0}:{1}" .format (req_file_name , original_req_lines ))
@@ -262,7 +264,7 @@ def build_and_install_dev_reqs(file: str, pkg_root: str) -> None:
262
264
263
265
adjusted_req_lines .append (amended_line )
264
266
265
- adjusted_req_lines = list (map (lambda x : build_whl_for_req (x , pkg_root ), adjusted_req_lines ))
267
+ adjusted_req_lines = list (map (lambda x : build_whl_for_req (x , pkg_root , None ), adjusted_req_lines ))
266
268
install_deps_commands = [
267
269
sys .executable ,
268
270
"-m" ,
@@ -285,30 +287,41 @@ def is_relative_install_path(req: str, package_path: str) -> bool:
285
287
return os .path .exists (possible_setup_path )
286
288
287
289
288
- def build_whl_for_req (req : str , package_path : str ) -> str :
290
+ def build_whl_for_req (req : str , package_path : str , wheel_dir : Optional [ str ] ) -> str :
289
291
"""Builds a whl from the dev_requirements file.
290
292
291
293
:param str req: a requirement from the dev_requirements.txt
292
294
:param str package_path: the absolute path to the package's root
295
+ :param Optional[str] wheel_dir: the absolute path to the prebuilt wheel directory
293
296
:return: The absolute path to the whl built or the requirement if a third-party package
294
297
"""
295
298
from ci_tools .build import create_package
296
299
297
300
if is_relative_install_path (req , package_path ):
298
- # Create temp path if it doesn't exist
299
- temp_dir = os .path .join (package_path , ".tmp_whl_dir" )
300
- if not os .path .exists (temp_dir ):
301
- os .mkdir (temp_dir )
302
-
303
301
req_pkg_path = os .path .abspath (os .path .join (package_path , req .replace ("\n " , "" )))
304
302
parsed = ParsedSetup .from_path (req_pkg_path )
305
303
306
- logging .info ("Building wheel for package {}" .format (parsed .name ))
307
- create_package (req_pkg_path , temp_dir , enable_sdist = False )
304
+ # First check for prebuilt wheel
305
+ logging .info ("Checking for prebuilt wheel for package {}" .format (parsed .name ))
306
+ prebuilt_whl = None
307
+ if wheel_dir :
308
+ prebuilt_whl = find_whl (wheel_dir , parsed .name , parsed .version )
309
+
310
+ if prebuilt_whl :
311
+ whl_path = os .path .join (wheel_dir , prebuilt_whl )
312
+ else :
313
+ # Create temp path if it doesn't exist
314
+ temp_dir = os .path .join (package_path , ".tmp_whl_dir" )
315
+ if not os .path .exists (temp_dir ):
316
+ os .mkdir (temp_dir )
317
+
318
+ logging .info ("Building wheel for package {}" .format (parsed .name ))
319
+ create_package (req_pkg_path , temp_dir , enable_sdist = False )
320
+
321
+ whl_path = os .path .join (temp_dir , find_whl (temp_dir , parsed .name , parsed .version ))
308
322
309
- whl_path = os .path .join (temp_dir , find_whl (temp_dir , parsed .name , parsed .version ))
310
323
logging .info ("Wheel for package {0} is {1}" .format (parsed .name , whl_path ))
311
- logging .info ("Replacing dev requirement. Old requirement:{0}, New requirement:{1}" .format (req , whl_path ))
324
+ logging .info ("Replacing dev requirement. Old requirement: {0}, New requirement: {1}" .format (req , whl_path ))
312
325
return whl_path
313
326
else :
314
327
return req
0 commit comments