Skip to content

Commit be655f6

Browse files
authored
Add skip_pip_install to build.py (microsoft#25982)
### Description <!-- Describe your changes. --> - Introduce a new command-line flag `--skip_pip_install`, similar to the existing `--skip_submodule_sync`, to allow users to prevent `build.py` from modifying their current Python environment. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> - This is useful for scenarios where dependencies are already managed externally or when users want to avoid unintended changes during the build process.
1 parent 4cb138a commit be655f6

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

tools/ci_build/build.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,12 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
17381738
if is_windows():
17391739
cwd = os.path.join(cwd, config)
17401740

1741-
if args.enable_transformers_tool_test and not args.disable_contrib_ops and not args.use_rocm:
1741+
if (
1742+
not args.skip_pip_install
1743+
and args.enable_transformers_tool_test
1744+
and not args.disable_contrib_ops
1745+
and not args.use_rocm
1746+
):
17421747
# PyTorch is required for transformers tests, and optional for some python tests.
17431748
# Install cpu only version of torch when cuda is not enabled in Linux.
17441749
extra = [] if args.use_cuda and is_linux() else ["--index-url", "https://download.pytorch.org/whl/cpu"]
@@ -1822,21 +1827,23 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
18221827

18231828
numpy_init_version = numpy.__version__
18241829
pb_init_version = google.protobuf.__version__
1825-
run_subprocess(
1826-
[
1827-
sys.executable,
1828-
"-m",
1829-
"pip",
1830-
"install",
1831-
"-r",
1832-
"requirements/transformers-test/requirements.txt",
1833-
],
1834-
cwd=SCRIPT_DIR,
1835-
)
1830+
if not args.skip_pip_install:
1831+
run_subprocess(
1832+
[
1833+
sys.executable,
1834+
"-m",
1835+
"pip",
1836+
"install",
1837+
"-r",
1838+
"requirements/transformers-test/requirements.txt",
1839+
],
1840+
cwd=SCRIPT_DIR,
1841+
)
18361842
run_subprocess([sys.executable, "-m", "pytest", "--durations=0", "transformers"], cwd=cwd)
1837-
# Restore initial numpy/protobuf version in case other tests use it
1838-
run_subprocess([sys.executable, "-m", "pip", "install", "numpy==" + numpy_init_version])
1839-
run_subprocess([sys.executable, "-m", "pip", "install", "protobuf==" + pb_init_version])
1843+
if not args.skip_pip_install:
1844+
# Restore initial numpy/protobuf version in case other tests use it
1845+
run_subprocess([sys.executable, "-m", "pip", "install", "numpy==" + numpy_init_version])
1846+
run_subprocess([sys.executable, "-m", "pip", "install", "protobuf==" + pb_init_version])
18401847

18411848
if not args.disable_ml_ops:
18421849
run_subprocess(
@@ -2524,7 +2531,7 @@ def main():
25242531
log.info("Activating emsdk...")
25252532
run_subprocess([emsdk_file, "activate", emsdk_version], cwd=emsdk_dir)
25262533

2527-
if args.enable_pybind and is_windows():
2534+
if not args.skip_pip_install and args.enable_pybind and is_windows():
25282535
run_subprocess(
25292536
[sys.executable, "-m", "pip", "install", "-r", "requirements/pybind/requirements.txt"],
25302537
cwd=SCRIPT_DIR,

tools/ci_build/build_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def add_cmake_build_config_args(parser: argparse.ArgumentParser) -> None:
186186
"--use_vcpkg_ms_internal_asset_cache", action="store_true", help="[MS Internal] Use internal vcpkg asset cache."
187187
)
188188
parser.add_argument("--skip_submodule_sync", action="store_true", help="Skip 'git submodule update'.")
189+
parser.add_argument("--skip_pip_install", action="store_true", help="Skip 'pip install'.")
189190

190191

191192
def add_testing_args(parser: argparse.ArgumentParser) -> None:

0 commit comments

Comments
 (0)