-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
134 lines (104 loc) · 3.47 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
from setuptools import setup, find_packages
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.build_py import build_py as _build_py
import subprocess
import os
import platform
from os.path import exists, join as pjoin
import shutil
import urllib.request
urlretrieve = urllib.request.urlretrieve
# try:
# import urllib.request
# urlretrieve = urllib.request.urlretrieve
# except ImportError: # python 2
# from urllib import urlretrieve
# read the contents of your README file
from pathlib import Path
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
def _run(cmd, cwd):
subprocess.check_call(cmd, shell=True, cwd=cwd)
def _safe_makedirs(*paths):
for path in paths:
try:
os.makedirs(path)
except os.error:
pass
HGS_VERSION = "2.0.0"
HGS_SRC = f"https://github.com/vidalt/HGS-CVRP/archive/v{HGS_VERSION}.tar.gz"
LIB_DIR = "lib"
BUILD_DIR = "lib/build"
BIN_DIR = "lib/bin"
def get_lib_filename():
if platform.system() == "Linux":
lib_ext = "so"
elif platform.system() == "Darwin":
lib_ext = "dylib"
elif platform.system() == "Windows":
lib_ext = "dll"
else:
lib_ext = "so"
return f"libhgscvrp.{lib_ext}"
LIB_FILENAME = get_lib_filename()
def download_build_hgs():
_safe_makedirs(LIB_DIR)
_safe_makedirs(BUILD_DIR)
hgs_src_tarball_name = "{}.tar.gz".format(HGS_VERSION)
hgs_src_path = pjoin(LIB_DIR, hgs_src_tarball_name)
urlretrieve(HGS_SRC, hgs_src_path)
_run(f"tar xzvf {hgs_src_tarball_name}", LIB_DIR)
_run(
f'cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../HGS-CVRP-{HGS_VERSION}',
BUILD_DIR,
)
_run("make lib", BUILD_DIR)
shutil.copyfile(f"{BUILD_DIR}/{LIB_FILENAME}", f"hygese/{LIB_FILENAME}")
# LIB_VERSION = "0.0.1"
# HGS_CVRP_WIN = f"https://github.com/chkwon/Libhgscvrp_jll.jl/releases/download/libhgscvrp-v{LIB_VERSION}%2B0/" + \
# f"libhgscvrp.v{LIB_VERSION}.x86_64-w64-mingw32-cxx11.tar.gz"
# def download_binary_hgs():
# print(HGS_CVRP_WIN)
# _safe_makedirs(LIB_DIR)
# dll_tarball_name = "win_bin.tar.gz"
# hgs_bin_path = pjoin(LIB_DIR, dll_tarball_name)
# urlretrieve(HGS_CVRP_WIN, hgs_bin_path)
# _run(f"tar xzvf {dll_tarball_name}", LIB_DIR)
# shutil.copyfile(f"{BIN_DIR}/{LIB_FILENAME}", f"hygese/{LIB_FILENAME}")
class BuildPyCommand(_build_py):
def run(self):
print("Build!!!!!! Run!!!!")
if platform.system() == "Windows":
# download_binary_hgs()
download_build_hgs()
else:
download_build_hgs()
_build_py.run(self)
setup(
name="hygese",
version="0.0.0.8",
description="A Python wrapper for the HGS-CVRP solver",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/chkwon/PyHygese",
author="Changhyun Kwon",
author_email="[email protected]",
project_urls={
"Bug Tracker": "https://github.com/chkwon/PyHygese/issues",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
package_dir={"": "."},
packages=find_packages(),
python_requires=">=3.6",
cmdclass={
"build_py": BuildPyCommand,
},
package_data={
"": ["libhgscvrp.*"],
},
install_requires=["numpy"],
)