-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
188 lines (157 loc) · 5.43 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Copyright 2018 Francesco Ceccon
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: skip-file
import os
import subprocess
import sys
from distutils.cmd import Command
from distutils.spawn import find_executable
from pathlib import Path
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
project_root = Path(__file__).resolve().parent
about = {}
version_path = project_root / 'galini' / '__version__.py'
with version_path.open() as f:
exec(f.read(), about)
with (project_root / 'README.rst').open() as f:
readme = f.read()
with (project_root / 'CHANGELOG.rst').open() as f:
changelog = f.read()
class PyTestCommand(TestCommand):
user_options = [
('unit', None, 'Specify to run unit tests only.'),
('e2e', None, 'Specify to run end to end tests only.'),
('pdb', None, 'Drop into PDB on failure.'),
]
def initialize_options(self):
super().initialize_options()
self.pytest_args = [
'--cov', 'galini',
'--cov-report=html',
'--cov-report=term',
]
self.unit = None
self.e2e = None
self.pdb = None
def run_tests(self):
import pytest
if self.unit and self.e2e:
raise ValueError('Must specify only one of e2e or unit.')
if self.unit:
# run unit tests only
self.pytest_args.append('tests/unit')
if self.e2e:
# run e2e tests only
self.pytest_args.append('tests/e2e')
if self.pdb:
self.pytest_args.append('--pdb')
errno = pytest.main(self.pytest_args)
return sys.exit(errno)
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
protoc = os.environ['PROTOC']
else:
protoc = find_executable('protoc')
def generate_proto(source):
output = source.replace('.proto', '_pb2.py')
print('Generating {}...'.format(output))
if not os.path.exists(source):
print('Protobuf file {} does not exist.'.format(source), file=sys.stderr)
sys.exit(-1)
if protoc is None:
print('protoc executable not found. Please install it.', file=sys.stderr)
sys.exit(-1)
command = [protoc, '-Iproto', '--python_out=galini/io', source]
if subprocess.call(command) != 0:
sys.exit(-1)
class GenerateProto(Command):
description = 'Generate _pb2.py files from .proto definition.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
generate_proto('proto/message.proto')
setup(
name='galini',
description=about['__description__'],
author=about['__author__'],
author_email=about['__author_email__'],
license=about['__license__'],
version=about['__version__'],
long_description=readme + '\n\n' + changelog,
packages=find_packages(exclude=['tests']),
entry_points={
'console_scripts': [
'galini=galini.cli:main',
],
'galini.commands': [
'solve=galini.commands.solve:SolveCommand',
'special_structure=galini.commands.special_structure:SpecialStructureCommand',
'info=galini.commands.info:InfoCommand',
'plugins=galini.commands.plugins:PluginsCommand',
],
'galini.algorithms': [
'bac=galini.branch_and_cut:BranchAndCutAlgorithm',
],
'galini.initial_primal_search': [
'default=galini.branch_and_cut.primal:DefaultInitialPrimalSearchStrategy',
'no_primal=galini.branch_and_cut.primal:NoInitialPrimalSearchStrategy',
],
'galini.primal_heuristic': [
'default=galini.branch_and_cut.primal:DefaultPrimalHeuristic',
],
'galini.branching_strategy': [
'default=galini.branch_and_cut.branching:BranchAndCutBranchingStrategy',
],
'galini.node_selection_strategy': [
'default=galini.branch_and_bound.selection:BestLowerBoundSelectionStrategy',
],
'galini.relaxation': [
'default=galini.branch_and_cut.relaxation:DefaultRelaxation',
],
'galini.cuts_generators': [
'outer_approximation=galini.outer_approximation:OuterApproximationCutsGenerator',
'triangle=galini.triangle:TriangleCutsGenerator',
'sdp=galini.sdp:SdpCutsGenerator',
],
},
cmdclass={
'test': PyTestCommand,
'generate_proto': GenerateProto,
},
include_package_data=True,
install_requires=[
'pyomo>=6',
'cog-suspect>=2.1.2',
'numpy>=1.15',
'toml',
'pydot',
'texttable>=1.4.0',
'pytimeparse>=1.1.8',
'protobuf>=3.0',
'h5py>=2.0',
'networkx>=2.4',
'coramin==0.1.1',
'scipy>=1.5.2',
],
setup_requires=['pytest-runner'],
tests_require=[
'pytest',
'pytest-cov',
'hypothesis',
'pytest-benchmark',
],
)