-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
130 lines (112 loc) · 4.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import sys
from distutils.command.build import build
from setuptools import Extension, setup, find_packages, Command
from setuptools.command.build_ext import build_ext
extra_link_args = []
runtime_library_dirs = []
if sys.platform.startswith('win32'):
so_ext = '.dll'
capi_filename = 'choco_capi' + so_ext
if sys.platform.startswith('linux'):
so_ext = '.so'
capi_filename = 'libchoco_capi' + so_ext
runtime_library_dirs = ['$ORIGIN']
elif sys.platform.startswith('darwin'):
so_ext = '.dylib'
capi_filename = 'libchoco_capi' + so_ext
extra_link_args = ['-Wl,-rpath,@loader_path']
class CopySharedLibrary(Command):
user_options = []
def initialize_options(self):
self.build_lib = None
self.inplace = 0
self.build_dir = "choco-solver-capi/target"
self.filename = capi_filename
self.lib_source_path = os.path.join(self.build_dir, self.filename)
self.package_name = 'pychoco'
def finalize_options(self):
self.set_undefined_options('build', ('build_lib', 'build_lib'), )
self.set_undefined_options('build_ext', ('inplace', 'inplace'), )
def run(self) -> None:
self.inplace = self.get_finalized_command('build_ext').inplace
if self.inplace:
lib_target_path = self.package_name
else:
lib_target_path = os.path.join(self.build_lib, self.package_name)
self.mkpath(lib_target_path)
self.copy_file(self.lib_source_path, os.path.join(lib_target_path, self.filename))
if sys.platform.startswith('win32'):
self.copy_file(self.lib_source_path, os.path.join(lib_target_path, "lib{}".format(self.filename)))
os.environ["ORIGIN"] = os.path.abspath(lib_target_path)
class CustomBuild(build):
sub_commands = [
('build_clib', build.has_c_libraries),
('build_ext', build.has_ext_modules),
('build_py', build.has_pure_modules),
('build_scripts', build.has_scripts),
]
class CustomBuildExt(build_ext):
def run(self):
self.run_command('copy_chocolib')
super().run()
lib_choco = Extension(
'pychoco._backend', ['pychoco/backend.i', 'pychoco/backend.c'],
include_dirs=["pychoco/", "choco-solver-capi/target"],
library_dirs=["pychoco/", "choco-solver-capi/target"],
libraries=["choco_capi"],
runtime_library_dirs=runtime_library_dirs,
extra_link_args=extra_link_args
)
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name='pychoco',
cmdclass={
'copy_chocolib': CopySharedLibrary,
'build_ext': CustomBuildExt,
'build': CustomBuild,
},
version='0.2.1',
author="Dimitri Justeau-Allaire, Charles Prud'homme",
author_email="[email protected], [email protected]",
description="Python bindings to the Choco Constraint Programming solver",
long_description=long_description,
long_description_content_type='text/markdown',
license="BSD-4",
platforms=['any'],
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Information Technology',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'License :: OSI Approved :: BSD License',
'Programming Language :: C',
'Programming Language :: Java',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Documentation :: Sphinx',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Java Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
],
keywords='constraint programming,optimization,graphs,artificial intelligence,combinatorics',
python_requires='>=3.6',
packages=find_packages(),
ext_modules=[lib_choco],
package_data={
'pychoco': ['py.typed'],
},
)