forked from DMOJ/judge-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
133 lines (112 loc) · 4.77 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import sys
import traceback
from distutils.errors import DistutilsPlatformError
from distutils.msvccompiler import MSVCCompiler
from setuptools import setup, Extension
from setuptools.command import build_ext
from setuptools.command.build_ext import build_ext as build_ext_old
class build_ext_dmoj(build_ext_old):
def run(self):
try:
build_ext_old.run(self)
except DistutilsPlatformError as e:
self.unavailable(e)
def build_extensions(self):
if isinstance(self.compiler, MSVCCompiler):
self.compiler.initialize()
self.compiler.compile_options.remove('/W3')
self.compiler.compile_options.remove('/MD')
if '/GS-' in self.compiler.compile_options:
self.compiler.compile_options.remove('/GS-')
self.compiler.compile_options += ['/Ox', '/W4', '/EHsc', '/GL', '/MT']
self.compiler.ldflags_shared += ['/OPT:REF,ICF', '/LTCG']
else:
if os.uname()[4].startswith('arm') or os.environ.get('DMOJ_REDIST'):
extra_compile_args = ['-O3']
else:
extra_compile_args = ['-march=native', '-O3']
self.distribution.ext_modules[0].extra_compile_args = extra_compile_args
build_ext_old.build_extensions(self)
def unavailable(self, e):
print '*' * 79
print 'Please procure the necessary *.pyd or *.so files yourself.'
traceback.print_exc()
print '*' * 79
build_ext.build_ext = build_ext_dmoj
wbox_sources = ['_wbox.pyx', 'handles.cpp', 'process.cpp', 'user.cpp', 'helpers.cpp', 'firewall.cpp']
cptbox_sources = ['_cptbox.pyx', 'helper.cpp', 'ptdebug.cpp', 'ptdebug_x86.cpp', 'ptdebug_x64.cpp',
'ptdebug_x86_on_x64.cpp', 'ptdebug_x32.cpp', 'ptdebug_arm.cpp', 'ptproc.cpp']
SOURCE_DIR = os.path.dirname(__file__)
wbox_sources = [os.path.join(SOURCE_DIR, 'dmoj', 'wbox', f) for f in wbox_sources]
cptbox_sources = [os.path.join(SOURCE_DIR, 'dmoj', 'cptbox', f) for f in cptbox_sources]
extensions = [Extension('dmoj.checkers._checker', sources=['dmoj/checkers/_checker.c'])]
if os.name == 'nt':
extensions += [Extension('dmoj.wbox._wbox', sources=wbox_sources, language='c++',
libraries=['netapi32', 'advapi32', 'ole32'],
define_macros=[('UNICODE', None)]),
Extension('dmoj.utils.debugger.win._win_debugger',
sources=['dmoj/utils/debugger/win/_win_debugger.c'],
include_dirs=['dmoj/utils/debugger'], libraries=['kernel32'])]
else:
libs = ['rt']
if sys.platform.startswith('freebsd'):
libs += ['procstat']
macros = []
try:
with open('/proc/version') as f:
if 'microsoft' in f.read().lower():
macros.append(('WSL', None))
except IOError:
pass
extensions += [Extension('dmoj.cptbox._cptbox', sources=cptbox_sources,
language='c++', libraries=libs, define_macros=macros),
Extension('dmoj.utils.debugger.nix._nix_debugger',
sources=['dmoj/utils/debugger/nix/_nix_debugger.c'],
include_dirs=['dmoj/utils/debugger'], libraries=['rt'])]
class cythonized(list):
def __init__(self, extensions):
super(cythonized, self).__init__()
self._list = None
self.extensions = extensions
def c_list(self):
if self._list is None:
from Cython.Build import cythonize
self._list = cythonize(self.extensions)
return self._list
def __iter__(self):
return iter(self.c_list())
def __getitem__(self, i):
return self.c_list()[i]
def __len__(self):
return len(self.extensions)
setup(
name='dmoj',
version='0.1',
packages=['dmoj'],
entry_points={
'console_scripts': [
'dmoj = dmoj.judge:main',
'dmoj-cli = dmoj.cli:main',
]
},
ext_modules=cythonized(extensions),
setup_requires=['cython'],
install_requires=['cython', 'watchdog', 'pyyaml', 'ansi2html', 'termcolor'],
author='quantum5, Xyene',
author_email='[email protected]',
url='https://github.com/DMOJ/judge',
description='The judge component of the Don Mills Online Judge platform',
keywords='online-judge',
classifiers=[
'Development Status :: 3 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Education',
'Topic :: Software Development',
],
)