Skip to content

Commit 042bd7d

Browse files
author
Davide Caroselli
committed
New setup.py script for dependency setup
1 parent fd65b84 commit 042bd7d

File tree

3 files changed

+100
-200
lines changed

3 files changed

+100
-200
lines changed

cli/__init__.py

+17-82
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,32 @@
11
import glob
22
import os
33

4-
__author__ = 'Davide Caroselli'
5-
6-
__self_dir = os.path.dirname(os.path.realpath(__file__))
7-
8-
PYOPT_DIR = os.path.join(__self_dir, 'opt')
9-
MMT_ROOT = os.path.abspath(os.path.join(__self_dir, os.pardir))
10-
ENGINES_DIR = os.path.join(MMT_ROOT, 'engines')
11-
RUNTIME_DIR = os.path.join(MMT_ROOT, 'runtime')
12-
BUILD_DIR = os.path.join(MMT_ROOT, 'build')
13-
VENDOR_DIR = os.path.join(MMT_ROOT, 'vendor')
14-
15-
PLUGINS_DIR = os.path.join(BUILD_DIR, 'plugins')
16-
LIB_DIR = os.path.join(BUILD_DIR, 'lib')
17-
BIN_DIR = os.path.join(BUILD_DIR, 'bin')
18-
194

205
def mmt_jar(pattern):
216
jars = [f for f in glob.glob(pattern)]
227
jars.sort(key=lambda e: os.path.getmtime(e))
238
return jars[-1] if len(jars) > 0 else None
249

2510

26-
MMT_JAR = mmt_jar(os.path.join(BUILD_DIR, 'mmt-*.jar'))
11+
__this_dir = os.path.dirname(os.path.realpath(__file__))
12+
13+
MMT_HOME_DIR = os.path.abspath(os.path.join(__this_dir, os.pardir))
14+
MMT_OPT_DIR = os.path.join(__this_dir, 'opt')
15+
MMT_ENGINES_DIR = os.path.join(MMT_HOME_DIR, 'engines')
16+
MMT_RUNTIME_DIR = os.path.join(MMT_HOME_DIR, 'runtime')
17+
MMT_BUILD_DIR = os.path.join(MMT_HOME_DIR, 'build')
18+
MMT_VENDOR_DIR = os.path.join(MMT_HOME_DIR, 'vendor')
19+
20+
MMT_PLUGINS_DIR = os.path.join(MMT_BUILD_DIR, 'plugins')
21+
MMT_LIB_DIR = os.path.join(MMT_BUILD_DIR, 'lib')
22+
MMT_BIN_DIR = os.path.join(MMT_BUILD_DIR, 'bin')
23+
MMT_RES_DIR = os.path.join(MMT_BUILD_DIR, 'res')
24+
25+
MMT_JAR = mmt_jar(os.path.join(MMT_BUILD_DIR, 'mmt-*.jar'))
2726

2827
# Environment setup
2928
os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(
30-
[LIB_DIR] + [x for x in os.environ['LD_LIBRARY_PATH'].split(os.pathsep)
31-
if len(x) > 0]) if 'LD_LIBRARY_PATH' in os.environ else LIB_DIR
29+
[MMT_LIB_DIR] + [x for x in os.environ['LD_LIBRARY_PATH'].split(os.pathsep)
30+
if len(x) > 0]) if 'LD_LIBRARY_PATH' in os.environ else MMT_LIB_DIR
3231
os.environ['LC_ALL'] = 'en_US.UTF-8'
3332
os.environ['LANG'] = 'en_US.UTF-8'
34-
35-
36-
def mmt_javamain(main_class, args=None, remote_debug=False, max_heap_mb=None, server=False, logs_path=None):
37-
classpath = [MMT_JAR]
38-
39-
if os.path.isdir(PLUGINS_DIR):
40-
for filename in os.listdir(PLUGINS_DIR):
41-
if filename.endswith('.jar'):
42-
classpath.append(os.path.join(PLUGINS_DIR, filename))
43-
44-
classpath = ':'.join(classpath)
45-
46-
java_ops = []
47-
if remote_debug:
48-
java_ops.append('-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005')
49-
50-
if server:
51-
java_ops.append('-server')
52-
53-
if max_heap_mb is not None:
54-
java_ops.append('-Xms' + str(max_heap_mb) + 'm')
55-
java_ops.append('-Xmx' + str(max_heap_mb) + 'm')
56-
57-
if logs_path is not None:
58-
java_ops += ['-XX:ErrorFile=' + os.path.join(logs_path, 'hs_err_pid%p.log')]
59-
60-
java_ops += ['-XX:+PrintGCDateStamps', '-verbose:gc', '-XX:+PrintGCDetails',
61-
'-Xloggc:' + os.path.join(logs_path, 'gc.log')]
62-
63-
java_ops += ['-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=' + logs_path]
64-
65-
java_ops += ['-XX:+CMSClassUnloadingEnabled', '-XX:+UseConcMarkSweepGC', '-XX:+CMSParallelRemarkEnabled',
66-
'-XX:+UseCMSInitiatingOccupancyOnly', '-XX:CMSInitiatingOccupancyFraction=70',
67-
'-XX:+ScavengeBeforeFullGC', '-XX:+CMSScavengeBeforeRemark', '-XX:+CMSClassUnloadingEnabled',
68-
'-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses']
69-
else:
70-
if max_heap_mb is not None:
71-
java_ops.append('-Xmx' + str(max_heap_mb) + 'm')
72-
73-
java_cmd = ['java'] + java_ops
74-
75-
command = java_cmd + ['-cp', classpath, '-Dmmt.home=' + MMT_ROOT, '-Djava.library.path=' + LIB_DIR, main_class]
76-
if args is not None:
77-
command += args
78-
79-
return command
80-
81-
82-
class IllegalStateException(Exception):
83-
def __init__(self, error):
84-
super(Exception, self).__init__(error)
85-
self.message = error
86-
87-
88-
class IllegalArgumentException(Exception):
89-
def __init__(self, error):
90-
super(Exception, self).__init__(error)
91-
self.message = error
92-
93-
94-
class CorpusNotFoundInFolderException(IllegalArgumentException):
95-
def __init__(self, error):
96-
super(Exception, self).__init__(error)
97-
self.message = error

extras/profile

-65
This file was deleted.

0 commit comments

Comments
 (0)