-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsetup.py
More file actions
49 lines (41 loc) · 1.78 KB
/
setup.py
File metadata and controls
49 lines (41 loc) · 1.78 KB
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
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import setuptools
import subprocess
import os
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
# Assuming the setup.py is located at the project root which also contains the CMakeLists.txt
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable]
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
# Determine the number of cores to use
num_cores = os.cpu_count() # Get the number of cores available on your system
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', '.', '--config', cfg, '--', f'-j{num_cores}'], cwd=self.build_temp) # Adjusted line
setup(
name='pysuperansac',
version='1.0',
author='Daniel Barath',
author_email="majti89@gmail.com",
description='A RANSAC implementation for robust estimation.',
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
ext_modules=[CMakeExtension('SupeRANSAC', sourcedir='.')],
cmdclass=dict(build_ext=CMakeBuild),
url="https://github.com/you/superansac",
zip_safe=False,
license='MIT',
)