Files changed (1) hide show
  1. setup.py +2 -98
setup.py CHANGED
@@ -1,98 +1,2 @@
1
- # Adapted from https://github.com/pybind/cmake_example/blob/master/setup.py
2
- import os
3
- import re
4
- import sys
5
- import platform
6
- import subprocess
7
- import importlib
8
- from sysconfig import get_paths
9
-
10
- import importlib
11
- from setuptools import setup, Extension
12
- from setuptools.command.build_ext import build_ext
13
- from setuptools.command.install import install
14
- from distutils.sysconfig import get_config_var
15
- from distutils.version import LooseVersion
16
-
17
- class CMakeExtension(Extension):
18
- def __init__(self, name, sourcedir, build_with_cuda):
19
- Extension.__init__(self, name, sources=[])
20
- self.sourcedir = os.path.abspath(sourcedir)
21
- self.build_with_cuda = build_with_cuda
22
-
23
- class Build(build_ext):
24
- def run(self):
25
- try:
26
- out = subprocess.check_output(['cmake', '--version'])
27
- except OSError:
28
- raise RuntimeError("CMake must be installed to build the following extensions: " +
29
- ", ".join(e.name for e in self.extensions))
30
-
31
- super().run()
32
-
33
- def build_extension(self, ext):
34
- if isinstance(ext, CMakeExtension):
35
- extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
36
- info = get_paths()
37
- include_path = info['include']
38
- cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
39
- '-DPYTHON_INCLUDE_PATH=' + include_path]
40
-
41
- cfg = 'Debug' if self.debug else 'Release'
42
- build_args = ['--config', cfg]
43
-
44
- if platform.system() == "Windows":
45
- cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir),
46
- '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
47
- if sys.maxsize > 2**32:
48
- cmake_args += ['-A', 'x64']
49
- build_args += ['--', '/m']
50
- else:
51
- cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
52
- build_args += ['--', '-j8']
53
-
54
- if ext.build_with_cuda:
55
- cmake_args += ['-DDIFFVG_CUDA=1']
56
- else:
57
- cmake_args += ['-DDIFFVG_CUDA=0']
58
-
59
- env = os.environ.copy()
60
- env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
61
- self.distribution.get_version())
62
- if not os.path.exists(self.build_temp):
63
- os.makedirs(self.build_temp)
64
- subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
65
- subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
66
- else:
67
- super().build_extension(ext)
68
-
69
- torch_spec = importlib.util.find_spec("torch")
70
- tf_spec = importlib.util.find_spec("tensorflow")
71
- packages = []
72
- build_with_cuda = False
73
- if torch_spec is not None:
74
- packages.append('pydiffvg')
75
- import torch
76
- if torch.cuda.is_available():
77
- build_with_cuda = True
78
- if tf_spec is not None and sys.platform != 'win32':
79
- packages.append('pydiffvg_tensorflow')
80
- if not build_with_cuda:
81
- import tensorflow as tf
82
- if tf.test.is_gpu_available(cuda_only=True, min_cuda_compute_capability=None):
83
- build_with_cuda = True
84
- if len(packages) == 0:
85
- print('Error: PyTorch or Tensorflow must be installed. For Windows platform only PyTorch is supported.')
86
- exit()
87
- # Override build_with_cuda with environment variable
88
- if 'DIFFVG_CUDA' in os.environ:
89
- build_with_cuda = os.environ['DIFFVG_CUDA'] == '1'
90
-
91
- setup(name = 'diffvg',
92
- version = '0.0.1',
93
- install_requires = ["svgpathtools"],
94
- description = 'Differentiable Vector Graphics',
95
- ext_modules = [CMakeExtension('diffvg', '', build_with_cuda)],
96
- cmdclass = dict(build_ext=Build, install=install),
97
- packages = packages,
98
- zip_safe = False)
 
1
+ # Adapted
2
+ import r