Skip to content

Commit ce0ff40

Browse files
[BUILD] Use typing.NamedTuple for packages
1 parent 7fc7b34 commit ce0ff40

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

python/setup.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tarfile
1010
import urllib.request
1111
from distutils.version import LooseVersion
12+
from typing import NamedTuple
1213

1314
from setuptools import Extension, setup
1415
from setuptools.command.build_ext import build_ext
@@ -38,34 +39,42 @@ def use_system_llvm():
3839

3940

4041
def get_thirdparty_packages(triton_cache_path):
42+
class Package(NamedTuple):
43+
package: str
44+
name: str
45+
url: str
46+
test_file: str
47+
include_flag: str
48+
lib_flag: str
49+
4150
packages = [
42-
("pybind11", "pybind11-2.10.0", "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz", "include/pybind11/pybind11.h", "PYBIND11_INCLUDE_DIR", "")
51+
Package("pybind11", "pybind11-2.10.0", "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz", "include/pybind11/pybind11.h", "PYBIND11_INCLUDE_DIR", "")
4352
]
4453
if not use_system_llvm():
4554
# donwload LLVM if no suitable system LLVM is installed
4655
packages.append(
47-
("llvm", "clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04", "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz", "lib", "LLVM_INCLUDE_DIRS", "LLVM_LIBRARY_DIR")
56+
Package("llvm", "clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04", "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz", "lib", "LLVM_INCLUDE_DIRS", "LLVM_LIBRARY_DIR")
4857
)
4958

5059
thirdparty_cmake_args = []
51-
for package, name, url, test_file, include_flag, lib_flag in packages:
52-
package_root_dir = os.path.join(triton_cache_path, package)
53-
package_dir = os.path.join(package_root_dir, name)
54-
test_file_path = os.path.join(package_dir, test_file)
60+
for p in packages:
61+
package_root_dir = os.path.join(triton_cache_path, p.package)
62+
package_dir = os.path.join(package_root_dir, p.name)
63+
test_file_path = os.path.join(package_dir, p.test_file)
5564
if not os.path.exists(test_file_path):
5665
try:
5766
shutil.rmtree(package_root_dir)
5867
except Exception:
5968
pass
6069
os.makedirs(package_root_dir, exist_ok=True)
61-
print('downloading and extracting {} ...'.format(url))
62-
ftpstream = urllib.request.urlopen(url)
70+
print('downloading and extracting {} ...'.format(p.url))
71+
ftpstream = urllib.request.urlopen(p.url)
6372
file = tarfile.open(fileobj=ftpstream, mode="r|*")
6473
file.extractall(path=package_root_dir)
65-
if include_flag:
66-
thirdparty_cmake_args.append("-D{}={}/include".format(include_flag, package_dir))
67-
if lib_flag:
68-
thirdparty_cmake_args.append("-D{}={}/lib".format(lib_flag, package_dir))
74+
if p.include_flag:
75+
thirdparty_cmake_args.append("-D{}={}/include".format(p.include_flag, package_dir))
76+
if p.lib_flag:
77+
thirdparty_cmake_args.append("-D{}={}/lib".format(p.lib_flag, package_dir))
6978
return thirdparty_cmake_args
7079

7180

0 commit comments

Comments
 (0)