forked from facebookresearch/pyvrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
137 lines (113 loc) · 4.38 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
#!/usr/bin/env python
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
import sys
from pathlib import Path
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
def _get_sha():
sha = "Unknown"
try:
sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=str(ROOT_DIR))
.decode("ascii")
.strip()
)
except Exception:
pass
return sha
def get_version():
path = os.path.join(ROOT_DIR, "version.txt")
version = open(path, "r").read().strip()
if os.getenv("PYVRS_TEST_BUILD"):
sha = _get_sha()
if sha != "Unknown":
version += "+" + sha[:7]
return version
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
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)))
if not extdir.endswith(os.path.sep):
extdir += os.path.sep
if "DEBUG" in os.environ:
cfg = "Debug" if os.environ["DEBUG"] == "1" else "Release"
else:
cfg = "Debug" if self.debug else "Release"
#moverse stuff
VCPKG_ENV_VAR = 'VCPKG_ROOT'
if VCPKG_ENV_VAR in os.environ:
vcpkg_path = os.path.join(os.environ[VCPKG_ENV_VAR], "scripts", "buildsystems", "vcpkg.cmake")
else:
vcpkg_path = os.path.join(Path(__file__).parent.parent, "vcpkg", "scripts", "buildsystems", "vcpkg.cmake")
cmake_args = [
f"-DCMAKE_BUILD_TYPE={cfg}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
# r"-DCMAKE_TOOLCHAIN_FILE=..\vcpkg\scripts\buildsystems\vcpkg.cmake",
# r"-DCMAKE_TOOLCHAIN_FILE=C:\Users\vlad\code\vcpkg_vrs_player\scripts\buildsystems\vcpkg.cmake",
f"-DCMAKE_TOOLCHAIN_FILE={vcpkg_path}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
"-GCodeBlocks",
# '-DVCPKG_TARGET_TRIPLET=x64-windows-vc142',
]
build_args = ["--target", os.path.basename(ext.name)]
VCPKG_TRIPLET_ENV_VAR = 'VCPKG_TRIPLET'
if VCPKG_TRIPLET_ENV_VAR in os.environ:
cmake_args += [f'-DVCPKG_TARGET_TRIPLET={os.environ[VCPKG_TRIPLET_ENV_VAR]}']
# Default to Ninja
if "CMAKE_GENERATOR" not in os.environ:
cmake_args += ["-GNinja"]
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)
def main():
with open(os.path.join(ROOT_DIR, "README.md"), encoding="utf-8") as f:
long_description = f.read()
setup(
name="vrs",
version=get_version(),
description="Python API for VRS",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/facebookresearch/pyvrs",
author="Meta Reality Labs Research",
license="Apache-2.0",
install_requires=["numpy", "typing", "dataclasses"],
python_requires=">=3.7",
packages=find_packages(),
zip_safe=False,
ext_modules=[CMakeExtension("vrsbindings", sourcedir=ROOT_DIR)],
cmdclass={
"build_ext": CMakeBuild,
},
)
if __name__ == "__main__":
main()