Skip to content

Commit 7624a27

Browse files
authored
Use prebuilt wheel dir to resolve necessary azure requirements before using repo version (#33911)
* enable our prebuilt wheel dir to override a located relative path
1 parent 7bb5103 commit 7624a27

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
"azure-ai-anomalydetector",
2929
]
3030

31-
NO_TESTS_ALLOWED = [
32-
]
31+
NO_TESTS_ALLOWED = []
3332

3433

3534
META_PACKAGES = ["azure", "azure-mgmt", "azure-keyvault"]
@@ -282,6 +281,27 @@ def get_package_from_repo(pkg_name: str, repo_root: str = None) -> ParsedSetup:
282281
return None
283282

284283

284+
def get_package_from_repo_or_folder(req: str, prebuilt_wheel_dir: str = None) -> str:
285+
"""Takes a package name and a possible prebuilt wheel directory. Attempts to resolve a wheel that matches the package name, and if it can't,
286+
attempts to find the package within the repo to install directly from path on disk.
287+
288+
During a CI build, it is preferred that the package is installed from a prebuilt wheel directory, as multiple CI environments attempting to install the relative
289+
req can cause inconsistent installation issues during parallel tox environment execution.
290+
"""
291+
292+
local_package = get_package_from_repo(req)
293+
294+
if prebuilt_wheel_dir and os.path.exists(prebuilt_wheel_dir):
295+
prebuilt_package = discover_prebuilt_package(prebuilt_wheel_dir, local_package.setup_filename, "wheel")
296+
if prebuilt_package:
297+
# return the first package found, there should only be a single one matching given that our prebuilt wheel directory
298+
# is populated by the replacement of dev_reqs.txt with the prebuilt wheels
299+
# ref tox_harness replace_dev_reqs() calls
300+
return os.path.join(prebuilt_wheel_dir, prebuilt_package[0])
301+
302+
return local_package.folder
303+
304+
285305
def get_version_from_repo(pkg_name: str, repo_root: str = None) -> str:
286306
pkg_info = get_package_from_repo(pkg_name, repo_root)
287307
if pkg_info:
@@ -411,6 +431,7 @@ def pip_install(requirements: List[str], include_dependencies: bool = True, pyth
411431

412432
return True
413433

434+
414435
def pip_uninstall(requirements: List[str], python_executable: str) -> bool:
415436
"""
416437
Attempts to invoke an install operation using the invoking python's pip. Empty requirements are auto-success.
@@ -480,7 +501,7 @@ def pytest(args: [], cwd: str = None, python_executable: str = None) -> bool:
480501
result = subprocess.run(commands, cwd=cwd)
481502
else:
482503
result = subprocess.run(commands)
483-
504+
484505
return result.returncode == 0
485506

486507

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from ci_tools.build import cleanup_build_artifacts, create_package
1818
from ci_tools.parsing import ParsedSetup, parse_require
19-
from ci_tools.functions import get_package_from_repo, find_whl, get_pip_list_output, pytest
19+
from ci_tools.functions import get_package_from_repo_or_folder, find_whl, get_pip_list_output, pytest
2020
from .managed_virtual_env import ManagedVirtualEnv
2121

2222

@@ -71,6 +71,8 @@ def create_package_and_install(
7171
setup_py_path, distribution_directory, target_setup, package_type, force_create
7272
)
7373

74+
target_package = ParsedSetup.from_path(setup_py_path)
75+
7476
if skip_install:
7577
logging.info("Flag to skip install whl is passed. Skipping package installation")
7678
else:
@@ -116,6 +118,7 @@ def create_package_and_install(
116118
addition_necessary = True
117119
# get all installed packages
118120
installed_pkgs = get_pip_list_output(python_exe)
121+
logging.info("Installed packages: {}".format(installed_pkgs))
119122

120123
# parse the specifier
121124
req_name, req_specifier = parse_require(req)
@@ -150,7 +153,12 @@ def create_package_and_install(
150153

151154
additional_downloaded_reqs = [
152155
os.path.abspath(os.path.join(tmp_dl_folder, pth)) for pth in os.listdir(tmp_dl_folder)
153-
] + [get_package_from_repo(relative_req).folder for relative_req in non_present_reqs]
156+
] + [
157+
get_package_from_repo_or_folder(
158+
package_name, os.path.join(target_package.folder, ".tmp_whl_dir")
159+
)
160+
for package_name in non_present_reqs
161+
]
154162

155163
commands = [python_exe, "-m", "pip", "install", built_pkg_path]
156164
commands.extend(additional_downloaded_reqs)
@@ -343,7 +351,9 @@ def prepare_and_test_optional(mapped_args: argparse.Namespace) -> int:
343351

344352
if mapped_args.optional:
345353
if env_name != mapped_args.optional:
346-
logging.info(f"{env_name} does not match targeted environment {mapped_args.optional}, skipping this environment.")
354+
logging.info(
355+
f"{env_name} does not match targeted environment {mapped_args.optional}, skipping this environment."
356+
)
347357
continue
348358

349359
environment_exe = prepare_environment(mapped_args.target, mapped_args.temp_dir, env_name)

0 commit comments

Comments
 (0)