This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
/
setup.py
181 lines (152 loc) · 5.71 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import distutils.command.clean
import os
import platform
import shutil
import subprocess
from pathlib import Path
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
ROOT_DIR = Path(__file__).parent.resolve()
def _get_version():
version = open("./version.txt").read().strip()
sha = "Unknown"
try:
sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=str(ROOT_DIR))
.decode("ascii")
.strip()
)
except Exception:
pass
if os.getenv("BUILD_VERSION"):
version = os.getenv("BUILD_VERSION")
elif sha != "Unknown":
version += "+" + sha[:7]
return version, sha
def _export_version(version, sha):
version_path = ROOT_DIR / "torcharrow" / "version.py"
with open(version_path, "w") as f:
f.write("__version__ = '{}'\n".format(version))
f.write("git_version = {}\n".format(repr(sha)))
VERSION, SHA = _get_version()
_export_version(VERSION, SHA)
print("-- Building version " + VERSION)
class clean(distutils.command.clean.clean):
def run(self):
# Run default behavior first
distutils.command.clean.clean.run(self)
# Remove torcharrow extension
for path in (ROOT_DIR / "torcharrow").glob("**/*.so"):
print(f"removing '{path}'")
path.unlink()
# Remove build directory
build_dirs = [
ROOT_DIR / "build",
]
for path in build_dirs:
if path.exists():
print(f"removing '{path}' (and everything under it)")
shutil.rmtree(str(path), ignore_errors=True)
# Based off of
# https://github.com/pytorch/audio/blob/2c8aad97fc8d7647ee8b2df2de9312cce0355ef6/build_tools/setup_helpers/extension.py#L46
class CMakeBuild(build_ext):
def run(self):
try:
subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError("CMake is not available.")
super().run()
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
# required for auto-detection of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
extdir += os.path.sep
if "DEBUG" in os.environ:
# TODO: is there any better approach?
cfg = "Debug" if os.environ["DEBUG"] == "1" else "Release"
else:
cfg = "Debug" if self.debug else "Release"
if "USE_TORCH" in os.environ:
import torch
CMAKE_PREFIX_PATH = f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}"
USE_TORCH = "-DUSE_TORCH=ON"
TORCH_FLAGS = [CMAKE_PREFIX_PATH, USE_TORCH]
else:
USE_TORCH = "-DUSE_TORCH=OFF"
TORCH_FLAGS = [USE_TORCH]
cmake_args = [
f"-DCMAKE_BUILD_TYPE={cfg}",
f"-DCMAKE_INSTALL_PREFIX={extdir}",
"-DCMAKE_VERBOSE_MAKEFILE=ON",
# f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
"-DVELOX_CODEGEN_SUPPORT=OFF",
"-DVELOX_BUILD_MINIMAL=ON",
] + TORCH_FLAGS
build_args = ["--target", "install"]
# Default to Ninja
if "CMAKE_GENERATOR" not in os.environ:
cmake_args += ["-GNinja"]
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
if hasattr(self, "parallel") and self.parallel:
# CMake 3.12+ only.
build_args += ["-j{}".format(self.parallel)]
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(
["cmake", str(ROOT_DIR)] + cmake_args, cwd=self.build_temp
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)
setup(
name="torcharrow",
version=VERSION,
description="A Pandas inspired, Arrow compatible, Velox supported dataframe library for PyTorch",
url="https://github.com/pytorch/torcharrow",
author="Facebook",
author_email="[email protected]",
license="BSD",
install_requires=[
"arrow",
"cffi",
"numpy==1.21.4",
"pandas<=1.3.5", # Last version that has Python 3.7 wheel
"typing",
"tabulate",
"typing-inspect",
"pyarrow",
],
python_requires=">=3.7",
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX :: Linux",
"Programming Language :: C++",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
packages=find_packages() # TODO ???
+ find_packages(where="./velox_rt")
+ find_packages(where="./numpy_rt")
+ find_packages(where="./test"),
zip_safe=False,
ext_modules=[Extension(name="torcharrow._torcharrow", sources=[])],
cmdclass={
"build_ext": CMakeBuild,
"clean": clean,
},
)