-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
125 lines (108 loc) · 3.71 KB
/
setup.py
File metadata and controls
125 lines (108 loc) · 3.71 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
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
"""setup"""
from argparse import ArgumentParser, Namespace
from os import path
from typing import Any, Dict, List, Optional, Tuple
import chess
from Cython.Build import cythonize
from setuptools import setup
BUILD_EXT: str = 'build_ext'
INIT_PY: str = '__init__.py'
CHMENGINE: str = 'chmengine'
CHMUTILS = 'chmutils'
UTILS: str = 'utils'
ENGINES: str = 'engines'
CHESS_PACKAGE: Optional[str] = path.dirname(chess.__file__)
CHESS_SCRIPTS: str = path.join(CHESS_PACKAGE, '*.py')
MAIN_MODULES: Tuple[str, str, str, str, str, str, str, str, str, str, str, str, str, str, str, str] = (
path.join('heatmaps', INIT_PY),
path.join(CHMUTILS, 'concurrent.py'),
path.join(CHMUTILS, 'game_builder.py'),
path.join(CHMUTILS, 'base_chess_tk_app.py'),
path.join(CHMUTILS, 'player.py'),
path.join(CHMUTILS, 'promotion_dialog.py'),
path.join(CHMUTILS, INIT_PY),
path.join(CHMENGINE, UTILS, 'pick.py'),
path.join(CHMENGINE, UTILS, INIT_PY),
path.join(CHMENGINE, ENGINES, 'cmhmey1.py'),
path.join(CHMENGINE, ENGINES, 'quartney.py'),
path.join(CHMENGINE, ENGINES, 'cmhmey2.py'),
path.join(CHMENGINE, ENGINES, 'cmhmey2_pool_executor.py'),
path.join(CHMENGINE, ENGINES, 'cmhmey3.py'),
path.join(CHMENGINE, ENGINES, INIT_PY),
path.join(CHMENGINE, INIT_PY),
)
EXCLUDE: str = path.join(CHESS_PACKAGE, '_interactive.py')
def main(compiler_directives: Dict[str, str]) -> None:
"""Setup function for ChessMoveHeatmap Cython support.
Parameters
----------
compiler_directives : Dict[str,str]
"""
args: Namespace = get_script_args()
both: bool = args.all or (args.chess and args.main)
force_flag: List[str] = ['--force'] if args.force else []
if not args.chess or both:
setup_main(compiler_directives, force_flag)
if not args.main or both:
setup_chess(compiler_directives, force_flag)
def setup_chess(compiler_directives: Dict[str, str], force_flag: List[str]) -> None:
"""Compiles the chess lib (excluding _interactive.py)
Parameters
----------
compiler_directives : Dict[str,str]
force_flag : List[str]
"""
ext_modules_chess: Any = cythonize(
module_list=CHESS_SCRIPTS,
exclude=EXCLUDE,
compiler_directives=compiler_directives
)
setup(
ext_modules=ext_modules_chess,
script_args=[BUILD_EXT, '--build-lib', path.join(CHESS_PACKAGE, '..')] + force_flag
)
def setup_main(compiler_directives: Dict[str, str], force_flag: List[str]) -> None:
"""Compiles the ChessMoveHeatmap lib
Parameters
----------
compiler_directives : Dict[str,str]
force_flag : List[str]
"""
ext_modules_main: Any = cythonize(
module_list=MAIN_MODULES,
compiler_directives=compiler_directives
)
setup(
ext_modules=ext_modules_main,
script_args=[BUILD_EXT, '--inplace'] + force_flag
)
def get_script_args() -> Namespace:
"""Gets script arguments.
Returns
-------
Namespace
"""
parser: ArgumentParser = ArgumentParser(description="Setup script for ChessMoveHeatmap Cython support.")
parser.add_argument(
'--main',
action='store_true',
help="Run the setup for the main modules."
)
parser.add_argument(
'--chess',
action='store_true',
help="Run the setup for the chess modules."
)
parser.add_argument(
'--all',
action='store_true',
help="Run the setup for both main and chess modules."
)
parser.add_argument(
'--force',
action='store_true',
help="Force a rebuild of all modules, even if no changes are detected."
)
return parser.parse_args()
if __name__ == '__main__':
main(compiler_directives={'language_level': "3"})