Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ set(PCT_LIBRARIES PCT)
if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
endif()
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
if(GIT_SHA1 MATCHES ".*NOTFOUND")
set(PCT_VERSION_HASH "")
else()
set(PCT_VERSION_HASH ", git hash ${GIT_SHA1}")
endif()

if(NOT ITK_SOURCE_DIR)
include(ITKModuleExternal)
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
Expand Down Expand Up @@ -41,16 +51,6 @@ if(PCT_BUILD_APPLICATIONS)
add_subdirectory(applications)
endif()

#-----------------------------------------------------------------------------
# Common revision info between applications
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
if(GIT_SHA1 MATCHES ".*NOTFOUND")
set(PCT_VERSION_HASH "")
else()
set(PCT_VERSION_HASH ", git hash ${GIT_SHA1}")
endif()

#=========================================================
# Build doc
option(PCT_BUILD_SPHINX "Build Sphinx Documentation" OFF)
Expand Down
4 changes: 2 additions & 2 deletions applications/pctargumentparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class PCTHelpFormatter(argparse.ArgumentDefaultsHelpFormatter):
def _format_usage(self, usage, actions, groups, prefix=None):
if prefix is None:
prefix = pct.version() + "\n\nusage: "
prefix = pct.__version__ + "\n\nusage: "
return super()._format_usage(usage, actions, groups, prefix)


Expand All @@ -22,7 +22,7 @@ def __init__(self, description=None, **kwargs):
self.formatter_class = PCTHelpFormatter
# allow negative numeric tokens to be treated as values, not options. This mirrors CPython behavior in python 3.14
self._negative_number_matcher = re.compile(r"-\.?\d")
self.add_argument("-V", "--version", action="version", version=pct.version())
self.add_argument("-V", "--version", action="version", version=pct.__version__)

def build_signature(self) -> inspect.Signature:
"""Build a compact Python signature: only required kwargs + **kwargs."""
Expand Down
7 changes: 3 additions & 4 deletions wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ itk_wrap_module(PCT)
itk_auto_load_submodules()
itk_end_wrap_module()

set(PCT_VERSION_SCRIPT "${PCT_BINARY_DIR}/applications/pctversion.py")
configure_file(
${PCT_SOURCE_DIR}/applications/pctversion.py.in
${PCT_VERSION_SCRIPT}
${PCT_SOURCE_DIR}/wrapping/pctConfig.py.in
${PCT_BINARY_DIR}/Wrapping/Generators/Python/pctConfig.py
)

file(
Expand All @@ -17,9 +16,9 @@ file(
wrap_itk_python_bindings_install(/itk "PCT"
__init_pct__.py
${PCT_PYTHON_APP}
${PCT_VERSION_SCRIPT}
${PCT_SOURCE_DIR}/wrapping/pctExtras.py
${PCT_SOURCE_DIR}/applications/pctargumentparser.py
${PCT_BINARY_DIR}/Wrapping/Generators/Python/pctConfig.py
)

# Copy python applications to the ITK wrapping directory to ensure they can be imported in tests.
Expand Down
5 changes: 4 additions & 1 deletion wrapping/__init_pct__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
itk_module = sys.modules["itk"]
pct_module = getattr(itk_module, "PCT")

# Load the CMake-generated version and assign it to `itk.PCT.__version__`.
pct_version = importlib.import_module("itk.pctConfig").PCT_GLOBAL_VERSION_STRING
setattr(pct_module, "__version__", pct_version)

# Import PCT submodules
pct_submodules = [
"itk.pctversion",
"itk.pctargumentparser",
"itk.pctExtras",
]
Expand Down
1 change: 1 addition & 0 deletions wrapping/pctConfig.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PCT_GLOBAL_VERSION_STRING = "@PCT_VERSION_MAJOR@.@PCT_VERSION_MINOR@.@PCT_VERSION_PATCH@@PCT_VERSION_HASH@"
2 changes: 1 addition & 1 deletion wrapping/pctExtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def app_func(*args, **kwargs):
options = _parser.format_help()
idx = options.lower().find("options:")
opt_text = options[idx:].strip()
parts = [pct.version(), description, examples, opt_text]
parts = [pct.__version__, description, examples, opt_text]
app_func.__doc__ = "\n\n".join(parts)

return app_func
Loading