-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsetup.py
More file actions
93 lines (82 loc) · 3.25 KB
/
setup.py
File metadata and controls
93 lines (82 loc) · 3.25 KB
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
from distutils.core import setup, Extension
import sys
import os
import numpy
from distutils.command.install import install
# NumPy header file path.
numpy_include = os.path.join(os.path.dirname(
numpy.__file__), "core", "include", "numpy")
print(numpy_include)
setup_path = os.path.dirname(os.path.realpath(__file__))
# Customization for different platforms
dbr_lib_dir = ''
dbr_dll = ''
dbr_include = ''
dbr_lib_name = 'DynamsoftBarcodeReader'
if sys.platform == "linux" or sys.platform == "linux2":
# linux
dbr_lib_dir = os.path.dirname(os.path.realpath(__file__))
elif sys.platform == "darwin":
# OS X
dbr_lib_dir = os.path.dirname(os.path.realpath(__file__))
pass
elif sys.platform == "win32":
# Windows
dbr_lib_name = 'DBRx64'
dbr_lib_dir = r'c:\Program Files (x86)\Dynamsoft\Barcode Reader 7.2.2\Components\C_C++\Lib'
dbr_dll = r'c:\Program Files (x86)\Dynamsoft\Barcode Reader 7.2.2\Components\C_C++\Redist\x64'
if sys.platform == "linux" or sys.platform == "linux2":
ext_args = dict(
include_dirs = [numpy_include],
library_dirs = [dbr_lib_dir],
extra_compile_args = ['-std=c99'],
extra_link_args = ["-Wl,-rpath=$ORIGIN"],
libraries = [dbr_lib_name]
)
elif sys.platform == "darwin":
ext_args = dict(
include_dirs = [numpy_include],
library_dirs = [dbr_lib_dir],
extra_compile_args = ['-std=c99'],
libraries = [dbr_lib_name]
)
if sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
module_dbr = Extension('dbr', ['dbr.c'], **ext_args)
else:
module_dbr = Extension('dbr', sources=['dbr.c'], include_dirs=[
numpy_include], library_dirs=[dbr_lib_dir], libraries=[dbr_lib_name])
class CustomInstall(install):
def run(self):
install.run(self)
if sys.platform == "win32":
import shutil
from distutils.sysconfig import get_python_lib
src = dbr_dll
dst = get_python_lib()
if os.path.isdir(src):
lst = os.listdir(src)
for f in lst:
dll = os.path.join(src, f)
shutil.copy2(dll, dst)
else:
shutil.copy2(src, dst)
elif sys.platform == "linux" or sys.platform == "linux2":
dst = get_python_lib()
lib = setup_path + "/libDynamsoftBarcodeReader.so"
os.system("cp {} {}".format(lib, dst))
elif sys.platform == "darwin":
dst = get_python_lib()
lib = setup_path + "/libDynamsoftBarcodeReader.dylib"
os.system("cp {} {}".format(lib, dst))
setup(name='dbr',
version='7.2.2',
description='Python barcode extension',
author='Dynamsoft',
author_email='support@dynamsoft.com',
url='https://www.dynamsoft.com/Products/Dynamic-Barcode-Reader.aspx',
license='https://www.dynamsoft.com/Products/barcode-reader-license-agreement.aspx',
ext_modules=[module_dbr],
long_description='Dynamsoft Barcode Reader is a software development toolkit which enables barcode recognition of Code 39, Code 129, QR Code, DataMatrix, PDF417 and Aztec.',
platforms=['Windows', 'Linux', 'macOS'],
cmdclass={'install': CustomInstall}
)