onnxruntime/cmake/deps_update_and_upload.py
Yifan Li d0aee204af
[ORT 1.18.1 Release] Cherry pick 3rd round (#21129)
### Description
<!-- Describe your changes. -->
Adding critical TensorRT EP support


### 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. -->

---------

Co-authored-by: Chi Lo <54722500+chilo-ms@users.noreply.github.com>
Co-authored-by: Ye Wang <52801275+wangyems@users.noreply.github.com>
Co-authored-by: Michal Guzek <moraxu@users.noreply.github.com>
Co-authored-by: pengwa <pengwa@microsoft.com>
Co-authored-by: wejoncy <wejoncy@163.com>
Co-authored-by: Yi Zhang <zhanyi@microsoft.com>
Co-authored-by: Yi Zhang <your@email.com>
Co-authored-by: Pranav Sharma <prs@microsoft.com>
Co-authored-by: Adam Pocock <adam.pocock@oracle.com>
Co-authored-by: cao lei <jslhcl@gmail.com>
Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com>
Co-authored-by: inisis <46103969+inisis@users.noreply.github.com>
Co-authored-by: Jeff Bloomfield <38966965+jeffbloo@users.noreply.github.com>
Co-authored-by: mo-ja <60505697+mo-ja@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: Sumit Agarwal <sumitagarwal330@gmail.com>
Co-authored-by: Atanas Dimitrov <70822030+neNasko1@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Yufeng Li <liyufeng1987@gmail.com>
Co-authored-by: Dhruv Matani <dhruvbird@gmail.com>
Co-authored-by: Dhruv Matani <dhruv.matani@grammarly.com>
Co-authored-by: wangshuai09 <391746016@qq.com>
Co-authored-by: Xiaoyu <85524621+xiaoyu-work@users.noreply.github.com>
Co-authored-by: Xu Xing <xing.xu@intel.com>
Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com>
Co-authored-by: Rachel Guo <35738743+YUNQIUGUO@users.noreply.github.com>
Co-authored-by: Sai Kishan Pampana <sai.kishan.pampana@intel.com>
Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net>
Co-authored-by: Jian Chen <cjian@microsoft.com>
Co-authored-by: Shubham Bhokare <32080845+shubhambhokare1@users.noreply.github.com>
Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
Co-authored-by: Andrew Fantino <15876180+afantino951@users.noreply.github.com>
Co-authored-by: Thomas Boby <thomas@boby.uk>
Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
Co-authored-by: Scott McKay <skottmckay@gmail.com>
Co-authored-by: Michal Guzek <mguzek@nvidia.com>
Co-authored-by: George Wu <jywu@microsoft.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>
2024-06-24 10:02:38 -07:00

109 lines
4.2 KiB
Python

# If deps.txt is updated, run this file to update and upload the dependencies so that CI can use them.
#
# Before running the script, find the latest version number at:
# https://aiinfra.visualstudio.com/Lotus/_artifacts/feed/Lotus/UPack/onnxruntime_build_dependencies/versions
# Increment it to obtain a new version number to use.
#
# Run without --do-upload once to verify downloading. Use --do-upload when you are ready to publish.
# E.g.:
# python cmake/deps_update_and_upload.py --root-path C:/temp/onnxruntime_deps --version 1.0.164
# # check contents of C:/temp/onnxruntime_deps
# python cmake/deps_update_and_upload.py --root-path C:/temp/onnxruntime_deps --version 1.0.164 --no-download --do-upload
#
# Next, update the version number in tools/ci_build/github/azure-pipelines/templates/download-deps.yml.
import argparse
import contextlib
import pathlib
import re
import subprocess
import tempfile
script_dir = pathlib.Path(__file__).parent
parser = argparse.ArgumentParser(description="Update dependencies and publish to Azure Artifacts")
parser.add_argument(
"--root-path",
type=pathlib.Path,
help="Target root path for downloaded files. If not provided, a temporary directory is used.",
)
parser.add_argument(
"--version",
type=str,
help="Package version to publish",
)
parser.add_argument(
"--do-upload",
action="store_true",
dest="upload",
help="Upload the package to Azure Artifacts",
)
parser.add_argument(
"--no-download",
action="store_false",
dest="download",
help="Skip downloading the dependency files. "
"Use with '--do-upload' and '--root-path' to upload the package from existing dependency files.",
)
args = parser.parse_args()
if args.upload:
assert args.version is not None, "'--version' must be specified if uploading."
if args.upload != args.download:
assert args.root_path is not None, "'--root-path' must be specified if only downloading or uploading."
deps_path = script_dir / "deps.txt"
with open(deps_path) as file:
text = file.read()
lines = [line for line in text.split("\n") if not line.startswith("#") and ";" in line]
with contextlib.ExitStack() as context_stack:
if args.root_path is not None:
root_path = args.root_path.resolve()
root_path.mkdir(parents=True, exist_ok=True)
else:
temp_dir_name = context_stack.enter_context(tempfile.TemporaryDirectory())
root_path = pathlib.Path(temp_dir_name)
if args.download:
print(f"Downloading dependencies to directory: {root_path}")
dep_pattern = re.compile(r"^[^;]+;https://([^;]+);.*$")
for line in lines:
match = dep_pattern.fullmatch(line)
if match is None:
continue
dep_path = match[1]
url = f"https://{dep_path}"
full_path = root_path / dep_path
subprocess.run(["curl", "-sSL", "--create-dirs", "-o", str(full_path), url], check=True)
package_name = "onnxruntime_build_dependencies"
version = args.version if args.version is not None else "VERSION_PLACEHOLDER"
if args.upload:
# Check if the user is logged in to Azure
result = subprocess.run("az account show", shell=True, capture_output=True, text=True, check=False)
if "No subscriptions found" in result.stderr:
# Prompt the user to log in to Azure
print("You are not logged in to Azure. Please log in to continue.")
subprocess.run("az login", shell=True, check=True)
# Publish the package to Azure Artifacts if --do-upload is specified
cmd = f'az artifacts universal publish --organization https://dev.azure.com/onnxruntime --feed onnxruntime --name {package_name} --version {version} --description "onnxruntime build time dependencies" --path {root_path}'
if args.upload:
subprocess.run(cmd, shell=True, check=True)
else:
print("would have run: " + cmd)
cmd = f'az artifacts universal publish --organization https://dev.azure.com/aiinfra --feed Lotus --name {package_name} --version {version} --description "onnxruntime build time dependencies" --path {root_path}'
if args.upload:
subprocess.run(cmd, shell=True, check=True)
else:
print("would have run: " + cmd)