Skip to content

Commit 03c981f

Browse files
authored
Merge pull request #46 from thewtex/window-module-wheel
Add windows_build_module_wheels.py
2 parents 15caf39 + fe3b7dd commit 03c981f

File tree

3 files changed

+108
-28
lines changed

3 files changed

+108
-28
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
__all__ = ['DEFAULT_PY_ENVS', 'venv_paths']
2+
3+
import os
4+
5+
DEFAULT_PY_ENVS = ["27-x64", "35-x64", "36-x64"]
6+
7+
SCRIPT_DIR = os.path.dirname(__file__)
8+
ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "..", ".."))
9+
10+
def venv_paths(python_version):
11+
venv_dir = os.path.join(ROOT_DIR, "venv-%s" % python_version)
12+
13+
python_executable = os.path.join(venv_dir, "Scripts", "python.exe")
14+
python_include_dir = os.path.join(venv_dir, "Include")
15+
16+
# XXX It should be possible to query skbuild for the library dir associated
17+
# with a given interpreter.
18+
xy_ver = python_version.split("-")[0]
19+
20+
python_library = "C:/Python%s/libs/python%s.lib" % (python_version, xy_ver)
21+
22+
print("")
23+
print("PYTHON_EXECUTABLE: %s" % python_executable)
24+
print("PYTHON_INCLUDE_DIR: %s" % python_include_dir)
25+
print("PYTHON_LIBRARY: %s" % python_library)
26+
27+
pip = os.path.join(venv_dir, "Scripts", "pip.exe")
28+
29+
ninja_executable = os.path.join(
30+
ROOT_DIR, "venv-27-x64", "Scripts", "ninja.exe")
31+
print("NINJA_EXECUTABLE:%s" % ninja_executable)
32+
33+
# Update PATH
34+
path = os.path.join(venv_dir, "Scripts")
35+
36+
return python_executable, \
37+
python_include_dir, \
38+
python_library, \
39+
pip, \
40+
ninja_executable, \
41+
path
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from subprocess import check_call
2+
import os
3+
import sys
4+
5+
SCRIPT_DIR = os.path.dirname(__file__)
6+
ROOT_DIR = os.path.abspath(os.getcwd())
7+
8+
9+
print("SCRIPT_DIR: %s" % SCRIPT_DIR)
10+
print("ROOT_DIR: %s" % ROOT_DIR)
11+
12+
sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal"))
13+
14+
from wheel_builder_utils import push_dir, push_env
15+
from windows_build_common import DEFAULT_PY_ENVS, venv_paths
16+
17+
def build_wheels(py_envs=DEFAULT_PY_ENVS):
18+
for py_env in py_envs:
19+
python_executable, \
20+
python_include_dir, \
21+
python_library, \
22+
pip, \
23+
ninja_executable, \
24+
path = venv_paths(py_env)
25+
26+
with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):
27+
28+
# Install dependencies
29+
requirements_file = os.path.join(ROOT_DIR, "requirements-dev.txt")
30+
if os.path.exists(requirements_file):
31+
check_call([pip, "install", "--upgrade", "-r", requirements_file])
32+
check_call([pip, "install", "cmake"])
33+
34+
build_type = "Release"
35+
source_path = ROOT_DIR
36+
itk_build_path = os.path.abspath("%s/ITK-win_%s" % (os.path.join(SCRIPT_DIR, '..'), py_env))
37+
print('ITKDIR: %s' % itk_build_path)
38+
39+
# Generate wheel
40+
check_call([
41+
python_executable,
42+
"setup.py", "bdist_wheel",
43+
"--build-type", build_type, "-G", "Ninja",
44+
"--",
45+
"-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
46+
"-DITK_DIR:PATH=%s" % itk_build_path,
47+
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
48+
"-DSWIG_EXECUTABLE:FILEPATH=%s/Wrapping/Generators/SwigInterface/swig/bin/swig.exe" % itk_build_path,
49+
"-DBUILD_TESTING:BOOL=OFF",
50+
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
51+
"-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
52+
"-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
53+
])
54+
# Cleanup
55+
check_call([python_executable, "setup.py", "clean"])
56+
57+
if __name__ == '__main__':
58+
build_wheels()

scripts/windows_build_wheels.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal"))
2222
from wheel_builder_utils import push_dir, push_env
23+
from windows_build_common import DEFAULT_PY_ENVS, venv_paths
2324

2425

2526
def pip_install(python_dir, package, upgrade=True):
@@ -104,30 +105,13 @@ def build_wrapped_itk(
104105
def build_wheel(python_version, single_wheel=False,
105106
cleanup=False, wheel_names=None):
106107

107-
venv_dir = os.path.join(ROOT_DIR, "venv-%s" % python_version)
108-
109-
python_executable = os.path.join(venv_dir, "Scripts", "python.exe")
110-
python_include_dir = os.path.join(venv_dir, "Include")
111-
112-
# XXX It should be possible to query skbuild for the library dir associated
113-
# with a given interpreter.
114-
xy_ver = python_version.split("-")[0]
115-
116-
python_library = "C:/Python%s/libs/python%s.lib" % (python_version, xy_ver)
108+
python_executable, \
109+
python_include_dir, \
110+
python_library, \
111+
pip, \
112+
ninja_executable, \
113+
path = venv_paths(python_version)
117114

118-
print("")
119-
print("PYTHON_EXECUTABLE: %s" % python_executable)
120-
print("PYTHON_INCLUDE_DIR: %s" % python_include_dir)
121-
print("PYTHON_LIBRARY: %s" % python_library)
122-
123-
pip = os.path.join(venv_dir, "Scripts", "pip.exe")
124-
125-
ninja_executable = os.path.join(
126-
ROOT_DIR, "venv-27-x64", "Scripts", "ninja.exe")
127-
print("NINJA_EXECUTABLE:%s" % ninja_executable)
128-
129-
# Update PATH
130-
path = os.path.join(venv_dir, "Scripts")
131115
with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):
132116

133117
# Install dependencies
@@ -234,12 +218,9 @@ def test_wheels(single_wheel=False):
234218
pass
235219

236220

237-
def build_wheels(py_envs=None, single_wheel=False,
221+
def build_wheels(py_envs=DEFAULT_PY_ENVS, single_wheel=False,
238222
cleanup=False, wheel_names=None):
239223

240-
if py_envs is None:
241-
py_envs = ["27-x64", "35-x64", "36-x64"]
242-
243224
prepare_build_env("27-x64")
244225
prepare_build_env("35-x64")
245226
prepare_build_env("36-x64")
@@ -269,7 +250,7 @@ def build_wheels(py_envs=None, single_wheel=False,
269250
cleanup=cleanup, wheel_names=wheel_names)
270251

271252

272-
def main(py_envs=None, wheel_names=None, cleanup=True):
253+
def main(py_envs=DEFAULT_PY_ENVS, wheel_names=None, cleanup=True):
273254
single_wheel = False
274255

275256
build_wheels(

0 commit comments

Comments
 (0)