-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
139 lines (97 loc) · 3.82 KB
/
Copy pathsetup.py
File metadata and controls
139 lines (97 loc) · 3.82 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# NOTE: The configuration for the package, including the name, version, and
# other information are set in the setup.cfg file.
import os
import sys
import pathlib
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as build_ext_orig
# First provide helpful messages if contributors try and run legacy commands
# for tests or docs.
API_HELP = """
Note: Generating api.rst files is no longer done using 'python setup.py api'. Instead
you will need to run:
desi_api_file
which is part of the desiutil package. If you don't already have desiutil installed, you can install it with:
pip install desiutil
"""
MODULE_HELP = """
Note: Generating Module files is no longer done using 'python setup.py api'. Instead
you will need to run:
desiInstall
or
desi_module_file
depending on your exact situation. desiInstall is preferred. Both commands are
part of the desiutil package. If you don't already have desiutil installed, you can install it with:
pip install desiutil
"""
VERSION_HELP = """
Note: Generating version strings is no longer done using 'python setup.py version'. Instead
you will need to run:
desi_update_version [-t TAG] desiutil
which is part of the desiutil package. If you don't already have desiutil installed, you can install it with:
pip install desiutil
"""
TEST_HELP = """
Note: running tests is no longer done using 'python setup.py test'. Instead
you will need to run:
pytest
If you don't already have pytest installed, you can install it with:
pip install pytest
"""
DOCS_HELP = """
Note: building the documentation is no longer done using
'python setup.py {0}'. Instead you will need to run:
sphinx-build -W --keep-going -b html doc doc/_build/html
If you don't already have Sphinx installed, you can install it with:
pip install Sphinx
"""
message = {'api': API_HELP,
'module_file': MODULE_HELP,
'test': TEST_HELP,
'version': VERSION_HELP,
'build_docs': DOCS_HELP.format('build_docs'),
'build_sphinx': DOCS_HELP.format('build_sphinx'), }
for m in message:
if m in sys.argv:
print(message[m])
sys.exit(1)
# Define classes needed for compiling C++.
class CMakeExtension(Extension):
def __init__(self, name):
# don't invoke the original build_ext for this special extension
super().__init__(name, sources=[])
class build_ext(build_ext_orig):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
# these dirs will be created in build_py, so if you don't have
# any python sources to bundle, the dirs will be missing
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.parent.mkdir(parents=True, exist_ok=True)
# example of cmake args
config = 'Debug' if self.debug else 'Release'
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
'-DCMAKE_BUILD_TYPE=' + config
]
# example of build args
build_args = [
'--config', config,
'--', '-j8'
]
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'] + build_args)
os.chdir(str(cwd))
for ext in self.extensions:
dest_path = pathlib.Path(self.get_ext_fullpath(ext.name)).resolve()
print('dest_path:',dest_path)
setup(ext_modules=[CMakeExtension('specex._libspecex')],
cmdclass={'build_ext': build_ext,})