File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ import sys
5+
6+ IS_WINDOWS = sys .platform == "win32"
7+
8+
9+ def quote_for_shell (s : str ) -> str :
10+ if IS_WINDOWS :
11+ # This is a relatively heavy import; keep pathfinder if possible.
12+ from subprocess import list2cmdline # nosec B404
13+
14+ return list2cmdline ([s ])
15+ else :
16+ import shlex
17+
18+ return shlex .quote (s )
Original file line number Diff line number Diff line change 44import functools
55import json
66import os
7- import shlex
8- from subprocess import list2cmdline # nosec B404
97from unittest .mock import patch
108
119import pytest
1614from cuda .pathfinder ._dynamic_libs import supported_nvidia_libs
1715from cuda .pathfinder ._utils .find_site_packages_dll import find_all_dll_files_via_metadata
1816from cuda .pathfinder ._utils .find_site_packages_so import find_all_so_files_via_metadata
17+ from cuda .pathfinder ._utils .platform_aware import quote_for_shell
1918
2019STRICTNESS = os .environ .get ("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS" , "see_what_works" )
2120assert STRICTNESS in ("see_what_works" , "all_must_work" )
@@ -93,12 +92,6 @@ def _get_libnames_for_test_load_nvidia_dynamic_lib():
9392 return tuple (result )
9493
9594
96- def _quote_for_shell_copypaste (s ):
97- if os .name == "nt" :
98- return list2cmdline ([s ])
99- return shlex .quote (s )
100-
101-
10295@pytest .mark .parametrize ("libname" , _get_libnames_for_test_load_nvidia_dynamic_lib ())
10396def test_load_nvidia_dynamic_lib (info_summary_append , libname ):
10497 # We intentionally run each dynamic library operation in a child process
@@ -120,5 +113,5 @@ def raise_child_process_failed():
120113 info_summary_append (f"Not found: { libname = !r} " )
121114 else :
122115 abs_path = json .loads (result .stdout .rstrip ())
123- info_summary_append (f"abs_path={ _quote_for_shell_copypaste (abs_path )} " )
116+ info_summary_append (f"abs_path={ quote_for_shell (abs_path )} " )
124117 assert os .path .isfile (abs_path ) # double-check the abs_path
You can’t perform that action at this time.
0 commit comments