forked from princeton-vl/infinigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
70 lines (57 loc) · 2.19 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
from pathlib import Path
import subprocess
import sys
import os
from setuptools import setup, find_packages, Extension
import numpy
from Cython.Build import cythonize
cwd = Path(__file__).parent
str_true = "True"
MINIMAL_INSTALL = os.environ.get('INFINIGEN_MINIMAL_INSTALL') == str_true
BUILD_TERRAIN = os.environ.get('INFINIGEN_INSTALL_TERRAIN', str_true) == str_true
BUILD_OPENGL = os.environ.get('INFINIGEN_INSTALL_CUSTOMGT', "False") == str_true
dont_build_steps = ["clean", "egg_info", "dist_info", "sdist", "--help"]
is_build_step = not any(x in sys.argv[1] for x in dont_build_steps)
def ensure_submodules():
# Inspired by https://github.com/pytorch/pytorch/blob/main/setup.py
with (cwd/'.gitmodules').open() as f:
submodule_folders = [
cwd/line.split("=", 1)[1].strip()
for line in f.readlines()
if line.strip().startswith("path")
]
if any(not p.exists() or not any(p.iterdir()) for p in submodule_folders):
subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
cwd=cwd,
check=True
)
ensure_submodules()
# inspired by https://github.com/pytorch/pytorch/blob/161ea463e690dcb91a30faacbf7d100b98524b6b/setup.py#L290
# theirs seems to not exclude dist_info but this causes duplicate compiling in my tests
if is_build_step and not MINIMAL_INSTALL:
if BUILD_TERRAIN:
subprocess.run(['make', 'terrain'], cwd=cwd, check=True)
if BUILD_OPENGL:
subprocess.run(['make', 'customgt'], cwd=cwd, check=True)
cython_extensions = []
if not MINIMAL_INSTALL:
cython_extensions.append(Extension(
name="bnurbs",
sources=["infinigen/assets/creatures/util/geometry/cpp_utils/bnurbs.pyx"],
include_dirs=[numpy.get_include()]
))
if BUILD_TERRAIN:
cython_extensions.append(
Extension(
name="infinigen.terrain.marching_cubes",
sources=["infinigen/terrain/marching_cubes/_marching_cubes_lewiner_cy.pyx"],
include_dirs=[numpy.get_include()]
)
)
setup(
ext_modules=[
*cythonize(cython_extensions)
]
# other opts come from pyproject.toml
)