Skip to content

Commit df2d397

Browse files
Allow replace_dev_reqs to pull from prebuilt wheels (#34924)
1 parent 7c4c062 commit df2d397

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

scripts/devops_tasks/tox_harness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ def prep_and_run_tox(targeted_packages: List[str], parsed_args: Namespace) -> No
300300
file.write("\n")
301301

302302
if in_ci():
303-
replace_dev_reqs(destination_dev_req, package_dir)
304-
replace_dev_reqs(test_tools_path, package_dir)
305-
replace_dev_reqs(dependency_tools_path, package_dir)
303+
replace_dev_reqs(destination_dev_req, package_dir, parsed_args.wheel_dir)
304+
replace_dev_reqs(test_tools_path, package_dir, parsed_args.wheel_dir)
305+
replace_dev_reqs(dependency_tools_path, package_dir, parsed_args.wheel_dir)
306306
os.environ["TOX_PARALLEL_NO_SPINNER"] = "1"
307307

308308
inject_custom_reqs(destination_dev_req, parsed_args.injected_packages, package_dir)

tools/azure-sdk-tools/ci_tools/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ def find_whl(whl_dir: str, pkg_name: str, pkg_version: str) -> str:
558558
whls = [os.path.relpath(w, whl_dir) for w in whls]
559559

560560
if not whls:
561-
logging.error("No whl is found in directory %s with package name format %s", whl_dir, pkg_name_format)
562-
logging.info("List of whls in directory: %s", glob.glob(os.path.join(whl_dir, "*.whl")))
561+
logging.info(f"No whl is found in directory {whl_dir} with package name format {pkg_name_format}")
562+
logging.info(f"List of whls in directory: {glob.glob(os.path.join(whl_dir, '*.whl'))}")
563563
return
564564

565565
compatible_tags = get_interpreter_compatible_tags()

tools/azure-sdk-tools/ci_tools/scenario/generation.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import shutil
66
import logging
7+
from typing import Optional
78

89
from ci_tools.environment_exclusions import is_check_enabled
910
from ci_tools.variables import in_ci
@@ -172,7 +173,7 @@ def create_package_and_install(
172173
logging.info("Installed {w}".format(w=built_package))
173174

174175

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:
176177
"""Takes a target requirements file, replaces all local relative install locations with wheels assembled from whatever that target path was.
177178
This is an extremely important step that runs on every dev_requirements.txt file before invoking any tox runs.
178179
@@ -181,6 +182,7 @@ def replace_dev_reqs(file: str, pkg_root: str) -> None:
181182
182183
:param str file: the absolute path to the dev_requirements.txt file
183184
: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
184186
:return: None
185187
"""
186188
adjusted_req_lines = []
@@ -198,7 +200,7 @@ def replace_dev_reqs(file: str, pkg_root: str) -> None:
198200
if extras:
199201
extras = f"[{extras}"
200202

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}")
202204

203205
req_file_name = os.path.basename(file)
204206
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:
262264

263265
adjusted_req_lines.append(amended_line)
264266

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))
266268
install_deps_commands = [
267269
sys.executable,
268270
"-m",
@@ -285,30 +287,41 @@ def is_relative_install_path(req: str, package_path: str) -> bool:
285287
return os.path.exists(possible_setup_path)
286288

287289

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:
289291
"""Builds a whl from the dev_requirements file.
290292
291293
:param str req: a requirement from the dev_requirements.txt
292294
: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
293296
:return: The absolute path to the whl built or the requirement if a third-party package
294297
"""
295298
from ci_tools.build import create_package
296299

297300
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-
303301
req_pkg_path = os.path.abspath(os.path.join(package_path, req.replace("\n", "")))
304302
parsed = ParsedSetup.from_path(req_pkg_path)
305303

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))
308322

309-
whl_path = os.path.join(temp_dir, find_whl(temp_dir, parsed.name, parsed.version))
310323
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))
312325
return whl_path
313326
else:
314327
return req

0 commit comments

Comments
 (0)