Skip to content

Commit 9bfc660

Browse files
committed
Reuse 'CLFinder.py' in 'setup.py'
Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 74db036 commit 9bfc660

File tree

3 files changed

+3
-51
lines changed

3 files changed

+3
-51
lines changed

python/setup.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from setuptools.command.egg_info import egg_info
2727
from wheel.bdist_wheel import bdist_wheel
2828

29+
from CLFinder import initialize_visual_studio_env
30+
2931
import pybind11
3032

3133

@@ -103,56 +105,6 @@ def copy_externals():
103105
]
104106

105107

106-
def find_vswhere():
107-
program_files = os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)")
108-
vswhere_path = Path(program_files) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe"
109-
if vswhere_path.exists():
110-
return vswhere_path
111-
return None
112-
113-
114-
def find_visual_studio(version_ranges):
115-
vswhere = find_vswhere()
116-
if not vswhere:
117-
raise FileNotFoundError("vswhere.exe not found.")
118-
119-
for version_range in version_ranges:
120-
command = [
121-
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
122-
"-products", "*", "-property", "installationPath", "-prerelease"
123-
]
124-
125-
try:
126-
output = subprocess.check_output(command, text=True).strip()
127-
if output:
128-
return output.split("\n")[0]
129-
except subprocess.CalledProcessError:
130-
continue
131-
132-
return None
133-
134-
135-
def set_env_vars(vs_path, arch="x64"):
136-
vcvarsall_path = Path(vs_path) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"
137-
if not vcvarsall_path.exists():
138-
raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}")
139-
140-
command = ["call", vcvarsall_path, arch, "&&", "set"]
141-
output = subprocess.check_output(command, shell=True, text=True)
142-
143-
for line in output.splitlines():
144-
if '=' in line:
145-
var, value = line.split('=', 1)
146-
os.environ[var] = value
147-
148-
149-
def initialize_visual_studio_env(version_ranges, arch="x64"):
150-
vs_path = find_visual_studio(version_ranges)
151-
if not vs_path:
152-
raise EnvironmentError("Visual Studio not found in specified version ranges.")
153-
set_env_vars(vs_path, arch)
154-
155-
156108
# Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py
157109
def check_env_flag(name: str, default: str = "") -> bool:
158110
return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"]

python/triton/runtime/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import subprocess
88
import setuptools
99
import platform
10-
from .CLFinder import initialize_visual_studio_env
10+
from ...CLFinder import initialize_visual_studio_env
1111

1212

1313
def is_xpu():

0 commit comments

Comments
 (0)