Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Remove one of three filesystem structures #2971

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
17 changes: 6 additions & 11 deletions cmake/MakePythonExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,28 @@ set(BINPATH_CONTENTS
"\n"
)

# Three possible interfaces:
# Two possible interfaces:
# 1. Standalone file residing in commands/
# 2. File stored in location commands/<cmdname>/<cmdname>.py, which will contain usage() and execute() functions
# 3. Two files stored at commands/<cmdname>/usage.py and commands/<cmdname>/execute.py, defining the two corresponding functions
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}/__init__.py")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}/usage.py" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}/execute.py")
string(APPEND BINPATH_CONTENTS
"module_usage = importlib.import_module('.usage', 'mrtrix3.commands.${CMDNAME}')\n"
"module_execute = importlib.import_module('.execute', 'mrtrix3.commands.${CMDNAME}')\n"
"_execute(module_usage.usage, module_execute.execute)\n"
)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}/${CMDNAME}.py")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}/${CMDNAME}.py")
string(APPEND BINPATH_CONTENTS
"module = importlib.import_module('.${CMDNAME}', 'mrtrix3.commands.${CMDNAME}')\n"
"_execute(module.usage, module.execute)\n"
)
else()
message(FATAL_ERROR "Malformed filesystem structure for Python command ${CMDNAME}")
endif()
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CMDNAME}.py")
string(APPEND BINPATH_CONTENTS
"module = importlib.import_module('.${CMDNAME}', 'mrtrix3.commands')\n"
"_execute(module.usage, module.execute)\n"
)
else()
message(FATAL_ERROR "Malformed filesystem structure for Python command ${CMDNAME}")
endif()
string(APPEND BINPATH_CONTENTS
"_execute(module.usage, module.execute)\n"
)


if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
file(WRITE ${OUTPUT_DIR}/${CMDNAME} ${BINPATH_CONTENTS})
Expand Down
23 changes: 23 additions & 0 deletions python/mrtrix3/commands/population_template/population_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2008-2024 the MRtrix3 contributors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Covered Software is provided under this License on an "as is"
# basis, without warranty of any kind, either expressed, implied, or
# statutory, including, without limitation, warranties that the
# Covered Software is free of defects, merchantable, fit for a
# particular purpose or non-infringing.
# See the Mozilla Public License v. 2.0 for more details.
#
# For more details, see http://www.mrtrix.org/.

from .usage import usage as my_usage
from .execute import execute as my_execute

def usage(cmdline): #pylint: disable=unused-variable
return my_usage(cmdline)

def execute(): #pylint: disable=unused-variable
return my_execute()
Loading