Skip to content

Commit 22998bd

Browse files
committed
COMP: Place python shared libs as subpackage of itk
Variables that are automatically set should be present in the CACHE for easier reviewing. Add sanity check for required file needed for testing When testing, the WrapITK.pth file MUST exist.
1 parent 05a8362 commit 22998bd

20 files changed

+292
-276
lines changed

CMake/ITKModuleExternal.cmake

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ endif()
3737

3838
# Setup build locations.
3939
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
40-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ITK_DIR}/bin)
40+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ITK_DIR}/bin CACHE PATH "Runtime output directory for ITK")
4141
endif()
4242
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
4343
if(ITK_WRAP_PYTHON)
44-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_DIR}/Wrapping/Generators/Python/itk)
44+
# If wrapping for python, then put all the shared libraries (both core shared libs,
45+
# and python shared libs in the itk python package directory under swiglib.
46+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_DIR}/Wrapping/Generators/Python/itk/swiglib CACHE PATH "Shared library directory, in wrapped directory.")
4547
else()
46-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_DIR}/lib)
48+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_DIR}/lib CACHE PATH "Shared library directory")
4749
endif()
4850
endif()
4951
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
50-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_DIR}/lib)
52+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_DIR}/lib CACHE PATH "Static library install directory")
5153
endif()
5254

5355
# ITK installation structure

CMake/ITKModuleTest.cmake

+10-2
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,20 @@ function(itk_python_add_test)
188188
else()
189189
set(itk_wrap_python_binary_dir "${ITK_BINARY_DIR}/Wrapping/Generators/Python")
190190
endif()
191+
# itk_wrap_python_binary_dir *MUST* contain the WrapITK.pth file
192+
set(WrapITK_PTH_FILE "${itk_wrap_python_binary_dir}/WrapITK.pth")
193+
if(NOT EXISTS ${WrapITK_PTH_FILE})
194+
# Final installed version of ITK will leverage the WrapITK.pth paths, so
195+
# the test environment should also use those same paths.
196+
message(FATAL_ERROR "The sys.path must be updated with the WrapITK.pth file content.")
197+
endif()
198+
unset(WrapITK_PTH_FILE)
191199

192200
if(CMAKE_CONFIGURATION_TYPES)
193201
itk_add_test(NAME ${PYTHON_ADD_TEST_NAME}
194202
COMMAND itkTestDriver
195203
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/$<CONFIG>" # parent directory of the itk package
196-
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/$<CONFIG>/itk" # directory of the itk package ( contains __init__.py)
204+
# NOT NEEDED --add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/$<CONFIG>/itk" # directory of the itk package ( contains __init__.py)
197205
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/$<CONFIG>/itk/conf" # directory of the itkConfig module
198206
--add-before-env PYTHONPATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>" # directory of shared libraries + swig artifacts
199207
--add-before-libpath "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>" # itk non-wrapping shared libs
@@ -207,7 +215,7 @@ function(itk_python_add_test)
207215
itk_add_test(NAME ${PYTHON_ADD_TEST_NAME}
208216
COMMAND itkTestDriver
209217
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}" # parent directory of the itk package
210-
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/itk" # directory of the itk package ( contains __init__.py)
218+
# NOT NEEDED --add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/itk" # directory of the itk package ( contains __init__.py)
211219
--add-before-env PYTHONPATH "${itk_wrap_python_binary_dir}/itk/conf" # directory of the itkConfig module
212220
--add-before-env PYTHONPATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" # directory of shared libraries + swig artifacts
213221
--add-before-libpath "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" # itk non-wrapping shared libs

Wrapping/Generators/Python/CMakeLists.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ if(NOT EXTERNAL_WRAP_ITK_PROJECT)
129129
foreach(t ${WRAP_ITK_COMPLEX_REAL})
130130
list(APPEND ITK_WRAP_PYTHON_COMPLEX_REAL ${ITKT_${t}})
131131
endforeach()
132-
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/itk/conf/itkBuildOptions.py.in"
132+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/itk/support/itkBuildOptions.py.in"
133133
"${ITK_PYTHON_PACKAGE_CONFIG_SUPPORT_DIR}/itkBuildOptions.py"
134134
@ONLY)
135135
WRAP_ITK_PYTHON_BINDINGS_INSTALL(/ "ITKCommon" "${ITK_PYTHON_PACKAGE_CONFIG_SUPPORT_DIR}/itkBuildOptions.py")
@@ -144,13 +144,13 @@ if(NOT EXTERNAL_WRAP_ITK_PROJECT)
144144
# Create a list of Python files.
145145
# WrapITK/Python/*.py
146146
set(ITK_PYTHON_FILES
147-
itk/conf/itkBase
148-
itk/conf/itkTemplate
149-
itk/conf/itkTypes
150-
itk/conf/itkExtras
151-
itk/conf/itkLazy
152-
itk/conf/itkHelpers
153-
itk/conf/itkInitHelpers
147+
itk/support/itkBase
148+
itk/support/itkTemplate
149+
itk/support/itkTypes
150+
itk/support/itkExtras
151+
itk/support/itkLazy
152+
itk/support/itkHelpers
153+
itk/support/itkInitHelpers
154154
itk/__init__
155155
itk/itkInitHelpers
156156
)
@@ -262,8 +262,8 @@ macro(itk_setup_swig_python type base_name interface_file python_file cpp_file d
262262
"${_swig_depend}")
263263

264264
if(NOT EXTERNAL_WRAP_ITK_PROJECT)
265-
file(COPY ${WrapITK_SOURCE_DIR}/Generators/Python/PyBase/pyBase.i
266-
DESTINATION "${WRAP_ITK_TYPEDEFS_DIRECTORY}")
265+
configure_file(${WrapITK_SOURCE_DIR}/Generators/Python/PyBase/pyBase.i
266+
"${WRAP_ITK_TYPEDEFS_DIRECTORY}" COPYONLY)
267267
list(APPEND dependencies "${WRAP_ITK_TYPEDEFS_DIRECTORY}/pyBase.i")
268268
endif()
269269

@@ -353,7 +353,7 @@ macro(itk_end_wrap_module_python)
353353

354354
# and create the file, with the var ITK_WRAP_PYTHON_CONFIGURATION_TEMPLATES and
355355
# ITK_WRAP_PYTHON_CONFIGURATION_DEPENDS created earlier
356-
configure_file("${ITK_WRAP_PYTHON_SOURCE_DIR}/itk/conf/ModuleConfig.py.in"
356+
configure_file("${ITK_WRAP_PYTHON_SOURCE_DIR}/itk/support/ModuleConfig.py.in"
357357
"${ITK_WRAP_PYTHON_LIBRARY_CONFIG_FILE}"
358358
@ONLY)
359359

Wrapping/Generators/Python/PyBase/pyBase.i

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ str = str
301301
return the first up-to-date output of a filter with multiple
302302
outputs.
303303
"""
304-
import itkHelpers
304+
from itk.support import itkHelpers
305305
import warnings
306306

307307
name = self.GetNameOfClass()
@@ -423,7 +423,7 @@ str = str
423423
"""Cast the image to the provided itk pixel type or equivalent NumPy dtype."""
424424
import itk
425425
import numpy as np
426-
import itkTypes
426+
from itk.support import itkTypes
427427
428428
# if both a numpy dtype and a ctype exist, use the latter.
429429
if type(pixel_type) is type:
@@ -441,7 +441,7 @@ str = str
441441
return cast
442442
443443
def SetDirection(self, direction):
444-
import itkHelpers
444+
from itk.support import itkHelpers
445445
if itkHelpers.is_arraylike(direction):
446446
import itk
447447
import numpy as np

Wrapping/Generators/Python/Tests/findEmptyClasses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import itk
2020
import sys
21-
from itkTemplate import itkTemplate
21+
from itk.support.itkTemplate import itkTemplate
2222

2323
itk.auto_progress(2)
2424

Wrapping/Generators/Python/Tests/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717
# ==========================================================================*/
18-
import itkHelpers
18+
from itk.support import itkHelpers
1919

2020
name = "MedianImageFilter"
2121

Wrapping/Generators/Python/Tests/returnedTypeCoverage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import itk
2020
import re
2121
import sys
22-
from itkTemplate import itkTemplate
22+
from itk.support.itkTemplate import itkTemplate
2323
from optparse import OptionParser
2424

2525

Wrapping/Generators/Python/Tests/verifyGetOutputAPIConsistency.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import itk
2222
import sys
23-
import itkTemplate
23+
from itk.support.itkTemplate import itkTemplate
2424

2525
itk.auto_progress(2)
2626

@@ -91,7 +91,7 @@ def checkGetOutputConsistency(o, t):
9191
if t not in exclude:
9292
T = itk.__dict__[t]
9393
# first case - that's a templated class
94-
if isinstance(T, itkTemplate.itkTemplate) and len(T) > 0:
94+
if isinstance(T, itkTemplate) and len(T) > 0:
9595
# Most templated object would simply instantiate the first type
9696
# listed if `New()` is called directly on the template type, but
9797
# this is not the case for all templates

Wrapping/Generators/Python/Tests/verifyTTypeAPIConsistency.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import itk
2222
import sys
23-
import itkTemplate
23+
from itk.support.itkTemplate import itkTemplate
2424

2525
itk.auto_progress(2)
2626

@@ -76,7 +76,7 @@ def checkTTypeConsistency(o, t):
7676
if t not in exclude:
7777
T = itk.__dict__[t]
7878
# Only check template classes.
79-
if isinstance(T, itkTemplate.itkTemplate) and len(T) > 0:
79+
if isinstance(T, itkTemplate) and len(T) > 0:
8080
# Most templated object would simply instantiate the first type
8181
# listed if `New()` is called directly on the template type, but
8282
# this is not the case for all templates

Wrapping/Generators/Python/itk/__init__.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020

2121
from .conf.itkConfig import ITK_GLOBAL_VERSION_STRING as __version__
2222

23-
from .conf.itkTemplate import image
24-
from .conf.itkTemplate import output
25-
from .conf.itkExtras import *
26-
from .conf.itkInitHelpers import *
27-
from itkTypes import *
23+
from .support.itkExtras import *
24+
from .support.itkInitHelpers import *
25+
from .support.itkTypes import *
2826

2927

3028
def _initialize_module():
@@ -48,8 +46,8 @@ def _get_lazy_attributes(local_lazy_attributes, l_module, l_data):
4846
# snake case always appended to end
4947
local_lazy_attributes.setdefault(function, []).append(l_module)
5048

51-
from .conf import itkBase as _itkBase
52-
from .conf import itkLazy as _itkLazy
49+
from .support import itkBase as _itkBase
50+
from .support import itkLazy as _itkLazy
5351
from .conf import itkConfig as _itkConfig
5452
import sys
5553

Wrapping/Generators/Python/itk/conf/itkBase.py Wrapping/Generators/Python/itk/support/itkBase.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# Required to work around weird import error with xarray
2424
import pkg_resources
2525

26-
import itkConfig
27-
import itkTemplate
26+
from itk.conf import itkConfig
27+
from itk.support.itkTemplate import itkTemplate
2828

2929

3030
def create_itk_module(name):

Wrapping/Generators/Python/itk/conf/itkBuildOptions.py.in Wrapping/Generators/Python/itk/support/itkBuildOptions.py.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import itkTemplate
2-
import itkTypes
1+
from itk.support import itkTypes
2+
from itk.support.itkTemplate import itkTemplate
33

44
DIMS = [int(s) for s in "@ITK_WRAP_IMAGE_DIMS@".split(";") if s]
55
USIGN_INTS = [getattr(itkTypes, s) for s in "@WRAP_ITK_USIGN_INT@".split(";") if s]

0 commit comments

Comments
 (0)