From c0c7e5706aa61aa1dad312ae4216580da89c4872 Mon Sep 17 00:00:00 2001 From: ddelange <14880945+ddelange@users.noreply.github.com> Date: Thu, 13 Jul 2023 14:26:24 +0200 Subject: [PATCH] PR Suggestion Signed-off-by: ddelange <14880945+ddelange@users.noreply.github.com> --- python/packaging/frontend_sdist/setup.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/python/packaging/frontend_sdist/setup.py b/python/packaging/frontend_sdist/setup.py index b3cf791a8..9abd12fd5 100644 --- a/python/packaging/frontend_sdist/setup.py +++ b/python/packaging/frontend_sdist/setup.py @@ -32,17 +32,24 @@ disable_internal_pip = os.environ.get("NVIDIA_TENSORRT_DISABLE_INTERNAL_PIP", False) +def run_pip_command(args, call_func): + try: + return call_func([sys.executable, "-m", "pip"] + args) + except subprocess.CalledProcessError: + return call_func([os.path.join(sys.exec_prefix, "bin", "pip")] + args) + + class InstallCommand(install): def run(self): # pip-inside-pip hack ref #3080 - subprocess.check_call( + run_pip_command( [ - "{}/bin/pip".format(sys.exec_prefix), "install", "--extra-index-url", nvidia_pip_index_url, *tensorrt_submodules, - ] + ], + subprocess.check_call, ) super().run() @@ -50,13 +57,7 @@ def run(self): def pip_config_list(): """Get the current pip config (env vars, config file, etc).""" - return subprocess.check_output( - [ - "{}/bin/pip".format(sys.exec_prefix), - "config", - "list", - ] - ).decode() + return run_pip_command(["config", "list"], subprocess.check_output).decode() def parent_command_line():