|
1 |
| -import os |
2 |
| -import platform |
3 |
| -import subprocess |
4 | 1 | import sys
|
5 | 2 |
|
6 |
| -import xml.etree.ElementTree as ET |
7 |
| - |
8 |
| -import setuptools |
9 |
| -from setuptools import Extension, setup |
10 |
| -from setuptools.command.build_ext import build_ext |
11 |
| - |
12 |
| - |
13 |
| -""" |
14 |
| -Modified from https://www.benjack.io/2017/06/12/python-cpp-tests.html |
15 |
| -""" |
16 |
| - |
17 |
| - |
18 |
| -class CMakeExtension(Extension): |
19 |
| - |
20 |
| - def __init__(self, name, sourcedir=''): |
21 |
| - Extension.__init__(self, name, sources=[]) |
22 |
| - self.sourcedir = os.path.abspath(sourcedir) |
23 |
| - |
24 |
| - |
25 |
| -class CMakeBuild(build_ext): |
26 |
| - |
27 |
| - def run(self): |
28 |
| - try: |
29 |
| - # out = |
30 |
| - subprocess.check_output(['cmake', '--version']) |
31 |
| - except OSError: |
32 |
| - raise RuntimeError( |
33 |
| - 'CMake must be installed to build the following extensions: ' + |
34 |
| - ', '.join(e.name for e in self.extensions)) |
35 |
| - |
36 |
| - # if platform.system() == "Windows": |
37 |
| - # cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', |
38 |
| - # out.decode()).group(1)) |
39 |
| - # if cmake_version < '3.1.0': |
40 |
| - # raise RuntimeError("CMake >= 3.1.0 is required on Windows") |
41 |
| - |
42 |
| - for ext in self.extensions: |
43 |
| - self.build_extension(ext) |
44 |
| - |
45 |
| - def build_extension(self, ext): |
46 |
| - extdir = os.path.abspath( |
47 |
| - os.path.dirname(self.get_ext_fullpath(ext.name))) |
48 |
| - |
49 |
| - cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
50 |
| - '-DPYTHON_EXECUTABLE=' + sys.executable] |
51 |
| - |
52 |
| - cfg = 'Debug' if self.debug else 'Release' |
53 |
| - build_args = ['--config', cfg] |
54 |
| - |
55 |
| - if platform.system() == 'Windows': |
56 |
| - cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( |
57 |
| - cfg.upper(), |
58 |
| - extdir)] |
59 |
| - if sys.maxsize > 2**32: |
60 |
| - cmake_args += ['-A', 'x64'] |
61 |
| - build_args += ['--', '/m'] |
62 |
| - else: |
63 |
| - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
64 |
| - cmake_args += ['-DBUILD_PYTHON_BINDINGS=ON'] |
65 |
| - build_args += ['--', '-j6'] |
66 |
| - |
67 |
| - env = os.environ.copy() |
68 |
| - env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format( |
69 |
| - env.get('CXXFLAGS', ''), |
70 |
| - self.distribution.get_version()) |
71 |
| - if not os.path.exists(self.build_temp): |
72 |
| - os.makedirs(self.build_temp) |
73 |
| - subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, |
74 |
| - cwd=self.build_temp, env=env) |
75 |
| - subprocess.check_call(['cmake', '--build', '.'] + build_args, |
76 |
| - cwd=self.build_temp) |
77 |
| - |
78 |
| - |
79 |
| -def get_package_xml_version(): |
80 |
| - tree = ET.parse('package.xml') |
81 |
| - return tree.find('version').text |
82 |
| - |
83 |
| - |
84 |
| -with open('README.md', 'r') as f: |
85 |
| - long_description = f.read() |
| 3 | +from cmake_build_extension import BuildExtension, CMakeExtension |
| 4 | +from setuptools import setup |
86 | 5 |
|
87 | 6 | setup(
|
88 |
| - name='manifpy', |
89 |
| - version=get_package_xml_version(), |
90 |
| - author='Jeremie Deray', |
91 |
| - |
92 |
| - description='A small library for Lie theory.', |
93 |
| - long_description=long_description, |
94 |
| - long_description_content_type='text/markdown', |
95 |
| - url='https://github.com/artivis/manif', |
96 |
| - license='MIT', |
97 |
| - packages=setuptools.find_packages(), |
98 |
| - classifiers=[ |
99 |
| - 'Programming Language :: Python :: 3', |
100 |
| - 'Operating System :: POSIX :: Linux' |
| 7 | + ext_modules=[ |
| 8 | + CMakeExtension( |
| 9 | + name="CMakeProject", |
| 10 | + install_prefix="manifpy", |
| 11 | + cmake_depends_on=["pybind11"], |
| 12 | + disable_editable=True, |
| 13 | + cmake_configure_options=[ |
| 14 | + "-DCALL_FROM_SETUP_PY:BOOL=ON", |
| 15 | + "-DBUILD_PYTHON_BINDINGS:BOOL=ON", |
| 16 | + f"-DPython3_EXECUTABLE:PATH={sys.executable}", |
| 17 | + ], |
| 18 | + ) |
101 | 19 | ],
|
102 |
| - ext_modules=[CMakeExtension('manifpy')], |
103 |
| - python_requires='>=3.6', |
104 |
| - cmdclass=dict(build_ext=CMakeBuild), |
105 |
| - zip_safe=False, |
106 |
| - install_requires=['numpy'] |
| 20 | + cmdclass=dict(build_ext=BuildExtension), |
107 | 21 | )
|
0 commit comments