|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
Compilation command: python setup.py build_ext |
|
|
|
|
|
Hugo Raguet 2020 |
|
|
""" |
|
|
|
|
|
from setuptools import setup, Extension |
|
|
from distutils.command.build import build |
|
|
import numpy |
|
|
import shutil |
|
|
import os |
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.name == 'nt': |
|
|
extra_compile_args = ["/std:c++11", "/openmp", |
|
|
"-DMIN_OPS_PER_THREAD=10000"] |
|
|
extra_link_args = ["/lgomp"] |
|
|
elif os.name == 'posix': |
|
|
extra_compile_args = ["-std=c++11", "-fopenmp", |
|
|
"-DMIN_OPS_PER_THREAD=10000"] |
|
|
extra_link_args = ["-lgomp"] |
|
|
else: |
|
|
raise NotImplementedError('OS not yet supported.') |
|
|
|
|
|
|
|
|
class build_class(build): |
|
|
def initialize_options(self): |
|
|
build.initialize_options(self) |
|
|
self.build_lib = "bin" |
|
|
def run(self): |
|
|
build_path = self.build_lib |
|
|
|
|
|
def purge(dir, pattern): |
|
|
for f in os.listdir(dir): |
|
|
if re.search(pattern, f): |
|
|
os.remove(os.path.join(dir, f)) |
|
|
|
|
|
|
|
|
|
|
|
tmp_work_dir = os.path.realpath(os.curdir) |
|
|
os.chdir(os.path.realpath(os.path.dirname(__file__))) |
|
|
|
|
|
if not os.path.exists("bin"): |
|
|
os.mkdir("bin") |
|
|
|
|
|
|
|
|
purge("bin/", "grid_graph") |
|
|
|
|
|
|
|
|
name = "grid_graph" |
|
|
mod = Extension( |
|
|
name, |
|
|
|
|
|
["cpython/grid_graph_cpy.cpp", |
|
|
"../src/edge_list_to_forward_star.cpp", |
|
|
"../src/grid_to_graph.cpp"], |
|
|
include_dirs=[numpy.get_include(), "../include"], |
|
|
extra_compile_args=extra_compile_args, |
|
|
extra_link_args=extra_link_args) |
|
|
|
|
|
setup(name=name, ext_modules=[mod], cmdclass=dict(build=build_class)) |
|
|
|
|
|
|
|
|
try: |
|
|
shutil.rmtree("build") |
|
|
except FileNotFoundError: |
|
|
pass |
|
|
|
|
|
os.chdir(tmp_work_dir) |
|
|
|