forked from groops-devs/groopsio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
69 lines (51 loc) · 2.22 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
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import os
import pathlib
import shutil
class CMakeExtension(Extension):
def __init__(self, name, sources=[]):
super().__init__(name=name, sources=sources)
class BuildCMakeExt(build_ext):
def run(self):
for extension in self.extensions:
if isinstance(extension, CMakeExtension):
self.build_cmake(extension)
self.extensions = list(filter(lambda e: not isinstance(e, CMakeExtension), self.extensions))
super().run()
def build_cmake(self, extension: Extension):
self.announce("preparing the build environment", level=3)
workdir = os.getcwd()
build_dir = pathlib.Path('build')
os.makedirs(build_dir, exist_ok=True)
extension_path = pathlib.Path(self.get_ext_fullpath(extension.name))
install_path = extension_path.parent.absolute()
extension_name = extension_path.parts[-1]
os.makedirs(install_path, exist_ok=True)
self.announce("configuring CMake project", level=3)
os.chdir(build_dir)
groops_env_var = os.getenv('GROOPS_SOURCE_DIR')
if groops_env_var is None:
groops_dir = pathlib.Path(os.path.join(os.path.expanduser('~'), 'groops', 'source'))
else:
groops_dir = pathlib.Path(groops_env_var)
cmake_command = ['cmake', '..', '-DGROOPS_SOURCE_DIR={0}'.format(groops_dir), '-DEXTENSION_LIBRARY_NAME={0}'.format(extension_name)]
if os.name == 'nt':
cmake_command.extend(['-G', 'MinGW Makefiles'])
self.spawn(cmake_command)
self.announce("building binaries", level=3)
self.spawn(["cmake", "--build", '.', "--target", extension_name, "--config", "Release"])
shutil.copy(extension_name, install_path)
os.chdir(workdir)
setup(
name='groopsio',
version='0.1',
author='Andreas Kvas',
description='A python package to read and write GROOPS files',
long_description=open("README.md", 'r').read(),
packages=['groopsio'],
ext_modules=[CMakeExtension(name="groopsiobase")],
license='GPL-3.0',
cmdclass={'build_ext': BuildCMakeExt},
install_requires=['cmake>=3.16', 'numpy']
)