-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
110 lines (95 loc) · 4.29 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
import os
import subprocess
import shutil
import glob
import platform
import sys
import re
from pathlib import Path
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from packaging import version # following PEP 440 standards on performing version comparison
with open("project-description.md", "r") as fh:
long_description = fh.read()
with open('requirements.txt') as f:
requirements = f.read().splitlines()
class CMakeExtension(Extension):
def __init__(self, name):
Extension.__init__(self, name, sources=[])
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
try:
temp = re.findall("\d+\.\d+", str(subprocess.check_output(["swig", "-version"])))
if version.parse(temp[0]) < version.parse('4.0'):
raise RuntimeError(
"Swig 4.0 or higher is required in order to build pyjass."
)
except OSError:
raise RuntimeError(
"Swig must be installed in order to build pyjass. Please run apt-get install swig or brew install swig"
)
try:
temp = re.findall("\d+\.\d+", str(subprocess.check_output(["cmake", "--version"])))
if version.parse(temp[0]) < version.parse('3.7'):
raise RuntimeError(
"CMake 3.8 or higher is required in order to build pyjass"
)
except OSError:
raise RuntimeError(
"CMake must be installed in order to build pyjass. Please run apt-get install cmake or brew install cmake"
+ ", ".join(e.name for e in self.extensions)
)
cwd = Path().absolute()
# these dirs will be created in build_py, so if you don't have
# any python sources to bundle, the dirs will be missing
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir
]
build_args = ["--config", "Release", "--", "-j2"]
self.announce("Running CMake prepare", level=3)
subprocess.check_call(["cmake", cwd] + cmake_args, cwd=self.build_temp)
self.announce("Building extensions")
cmake_cmd = ["cmake", "--build", "."] + build_args
subprocess.check_call(cmake_cmd, cwd=(self.build_temp))
dir1 = self.build_temp + "/anytime/pyjass.py" # copy our swig script into the lib so it gets installed together
# This is a workaround for MacOS X
# clang (Xcode) expects some sort of file but in Linux it gets compiled anyway. We just copy the _so file to dummy and install it
if platform.system() == "Darwin":
fakeLib = extdir + "/dummy.cpython-" + str(sys.version_info[0]) + str(sys.version_info[1]) + "-darwin.so" #create a Darwin Version to handle pythons' cmake
shutil.copy((extdir + "/_pyjass.so"), fakeLib)
shutil.copy(dir1, extdir)
setup(
cmdclass=dict(build_ext=CMakeBuild),
name='pyjass',
version='0.2a7',
author='Andrew Trotman',
description='The JASS experimental Score-at-a-Time search engine.',
long_description= long_description,
include_dirs =[''],
author_email='[email protected]',
download_url='',
keywords='search engine, search tool, jass, SaaT',
project_urls={ # Optional
'Bug Reports': 'https://github.com/andrewtrotman/JASSv2/issues',
'Source': 'https://github.com/andrewtrotman/JASSv2',
},
# packages=[''],
# package_dir={'': '.'},
# package_data={'': ['_example.so']}, #replace me with your package data
classifiers=[
'Programming Language :: Python :: 3',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux', # WSL will be treated as Linux so it's not a problem
],
python_requires='>=3.6',
install_requires= requirements,
long_description_content_type="text/markdown", #added the type markdown
ext_modules=[CMakeExtension("dummy")] # force python to generate a dummy.so/pyc bindings - cmake script takes care of that
)