-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
58 lines (52 loc) · 1.83 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
from setuptools import setup, Extension
from Cython.Build import cythonize
import os,glob,urllib.request,gzip,tarfile
from io import BytesIO
PACKAGE = "lzo"
VERSION = "1.0.0"
LZO_VERSION=os.environ.get('LZO_VERSION') or '2.10'
LZO_SRC_PATH=os.environ.get("LZO_SRC_PATH") or '.'
def download(url,file):
print('Downloading ',url)
if os.path.exists(file):
return
urllib.request.urlretrieve(url,file,lambda x,y,z:print("[%s%s]%3s%%"%('='*int(100*x*y/z),' '*int(100-100*x*y/z),int(100*x*y/z)),end='\r'))
print()
def extract(file):
print('Extracting ',file)
with open(file,'rb')as fp:
data=gzip.decompress(fp.read())
with BytesIO(data) as io:
with tarfile.open(fileobj=io) as tar:
tar.extractall()
def download_and_extract():
name='lzo.tar.gz'
dest='lzo-%s'%(LZO_VERSION)
if not os.path.exists(dest):
download('https://www.oberhumer.com/opensource/lzo/download/lzo-%s.tar.gz'%(LZO_VERSION),name)
extract(name)
return dest
def check_source_dir():
return os.path.exists(os.path.join(LZO_SRC_PATH,'include/lzo/lzoconf.h'))
ERROR_MESSAGE='Please set LZO_SRC_PATH or LZO_VERSION (like "2.10") environment variable and try again.'
if __name__=="__main__":
try:
if not check_source_dir():
LZO_SRC_PATH=download_and_extract()
if not check_source_dir():
assert check_source_dir()
except Exception as e:
import traceback
traceback.print_exc()
raise Exception(ERROR_MESSAGE)
setup(
name=PACKAGE,
version=VERSION,
ext_modules=cythonize([
Extension(
name='lzo',
sources=['lzo.pyx',*glob.glob(os.path.join(LZO_SRC_PATH,'src/*.c'))],
include_dirs=[os.path.join(LZO_SRC_PATH,'include')]
),
])
)