Newer
Older
#!/usr/bin/env python
# -*- coding: utf-8 -*-
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
from distutils.core import setup
from distutils.command.build import build
from distutils.command.clean import clean
from distutils.command.install import install
UNITEX_INC = os.path.expandvars("$UNITEX_INC")
if UNITEX_INC == "$UNITEX_INC":
sys.stderr.write( "You need to specify the UNTIEX_INC variable (i.e. Unitex C++ src directory)!\n" )
sys.stderr.write( " -> e.g.: UNITEX_INC=/path/to/unitex/Src/C++ python setup.py cmd\n" )
sys.exit(1)
UNITEX_INC = os.path.abspath(UNITEX_INC)
class CustomBuild(build):
def run(self):
command = "cd %s && make 64BITS=yes LIBRARY=yes" % os.path.join(UNITEX_INC, "build")
try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
except Exception as e:
sys.stderr.write("Error in command: %s\n" % command)
raise e
process.wait()
if process.returncode != 0:
raise OSError(process.stderr.read())
build.run(self)
class CustomClean(clean):
def run(self):
command = "cd %s && make clean" % os.path.join(UNITEX_INC, "build")
try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
except Exception as e:
sys.stderr.write("Error in command: %s\n" % command)
raise e
process.wait()
if process.returncode != 0:
raise OSError(process.stderr.read())
clean.run(self)
class CustomInstall(install):
def run(self):
library = None
if sys.platform == "darwin":
library = "libunitex.dylib"
elif sys.platform == "linux2":
library = "libunitex.so"
else:
sys.stderr.write("Plateform '%s' not supported...\n" % sys.platform)
sys.exit(1)
command = "cd %s && cp %s /usr/local/lib" % (os.path.join(UNITEX_INC, "bin"), library)
try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
except Exception as e:
sys.stderr.write("Error in command: %s\n" % command)
raise e
process.wait()
if process.returncode != 0:
raise OSError(process.stderr.read())
install.run(self)
setup(
name = "unitex",
version = "1.0",
description = "Python 3 binding for the Unitex library",
long_description = open('README').read(),
author = "Patrick Watrin",
author_email = "patrick.watrin@gmail.com",
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3 :: Only",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Scientific/Engineering :: Information Analysis",
],
keywords = "Unitex, Finite-States Transducers, Natural Language Processing",
install_requires = [
# TO FILL
],
packages = ["unitex"],
package_dir = {'unitex': 'unitex'},
data_files = [
],
cmdclass = {
"build": CustomBuild,
"clean": CustomClean,
"install": CustomInstall
}
)