Skip to content
Merged
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
8 changes: 0 additions & 8 deletions src/holoscan_cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,6 @@ def handle_create(cli, args: argparse.Namespace) -> None:

if is_module:
operators_dir = project_dir / "operators"
if use_packaged_template and languages == ["python"]:
try:
module = json.loads(metadata_path.read_text(encoding="utf-8")).get("module", {})
namespace = module.get("namespace", {}).get("python")
except (OSError, ValueError, AttributeError):
namespace = None
if isinstance(namespace, str) and namespace:
operators_dir = project_dir / "python" / namespace / "operators"
msg_next = (
f"Possible next steps:\n"
f"- Implement your operator in {operators_dir}/\n"
Expand Down
6 changes: 3 additions & 3 deletions src/holoscan_cli/templates/module/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def remove_empty_dirs(root: str = ".") -> None:
CPP_PATHS = (
".clang-format",
"pkg",
"operators/CMakeLists.txt",
f"operators/{OPERATOR_SLUG}/CMakeLists.txt",
f"operators/{OPERATOR_SLUG}/{OPERATOR_SLUG}.cpp",
f"operators/{OPERATOR_SLUG}/{OPERATOR_SLUG}.hpp",
f"applications/{MODULE_SLUG}_pipeline/cpp",
f"python/_{MODULE_SLUG}.cpp",
"tests/cpp",
# operators/ replaces the python/ package's operators subpackage.
f"python/holoscan_{MODULE_SLUG}/operators",
)

if PURE_PYTHON == "yes":
Expand All @@ -77,7 +77,7 @@ def remove_empty_dirs(root: str = ".") -> None:
print(f"\n\033[32mHoloscan Module '{MODULE_SLUG}' created successfully!\033[0m\n")
print(f"Implement your operator ({OPERATOR_CLASS}) in:")
if PURE_PYTHON == "yes":
print(f" python/holoscan_{MODULE_SLUG}/operators/{OPERATOR_SLUG}.py\n")
print(f" operators/{OPERATOR_SLUG}/{OPERATOR_SLUG}.py\n")
else:
print(f" operators/{OPERATOR_SLUG}/{OPERATOR_SLUG}.cpp\n")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ unless you pass `--local`.
- With the SDK on the host, add `--local` and set
`HOLOSCAN_CLI_BUILD_PARENT_DIR="$PWD/build-native"` so native output stays apart from container
output.
- Without the CLI, `python -m pip install -e . pytest` and `python -m pytest tests/python` work
in any environment with the SDK wheels.
- Without the CLI, an editable install (see README.md) and `python -m pytest tests/python` work in
any environment with the SDK wheels. The editable install rebuilds on import, so source edits
take effect without reinstalling.

A change is done when `holoscan lint` and `holoscan test` pass.

Expand All @@ -58,9 +59,11 @@ A change is done when `holoscan lint` and `holoscan test` pass.
`metadata.json` files.
- SDK version and image: `Dockerfile`, `pyproject.toml`, `.github/workflows/ci.yml`, and the
Module, operator, and application `metadata.json` files.
- New operators: a module under `python/holoscan_{{ cookiecutter.module_slug }}/operators/`, its export in
`operators/__init__.py`, an `operators/<name>/metadata.json`, `module.operator_names` in the
root `metadata.json`, the tests, and the operator table in README.md.
- New operators: an `operators/<name>/` directory with `__init__.py`, the implementation,
`metadata.json`, and `CMakeLists.txt`, `add_holohub_operator(<name>)` in
`operators/CMakeLists.txt`, a `TYPE_CHECKING` import in `operators/__init__.py`,
`cmake.define.OP_<name>` in `pyproject.toml`, `module.operator_names` in the root
`metadata.json`, the tests, and the operator table in README.md.
- Operator ports or parameters: the operator's `metadata.json`, the tests, and the operator table in
README.md.
- Third-party dependencies: `pyproject.toml` and `NOTICE`, which lists each one with its version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ project(holoscan_{{ cookiecutter.module_slug }}
LANGUAGES NONE
)

# Wheel builds (scikit-build-core) take the package and its metadata from pyproject.toml.
if(SKBUILD)
return()
endif()

# ---------------------------------------------------------------------------
# Build options
# ---------------------------------------------------------------------------
# BUILD_ALL toggles every application on by default. Each application is a
# CMake option (APP_<name>) defined by add_holohub_application, defaulting to
# ${BUILD_ALL}. It is ON when this is the top-level project and OFF when the
# Module is nested in another project.
# BUILD_ALL toggles every operator and application on by default. Each one is a
# CMake option (OP_<name> or APP_<name>) defined by add_holohub_operator or
# add_holohub_application, defaulting to ${BUILD_ALL}. It is ON when this is the
# top-level project and OFF when the Module is nested in another project.
if(NOT DEFINED BUILD_ALL)
if(PROJECT_IS_TOP_LEVEL)
set(BUILD_ALL ON CACHE BOOL "Build all applications by default")
set(BUILD_ALL ON CACHE BOOL "Build all operators and applications by default")
else()
set(BUILD_ALL OFF)
endif()
Expand Down Expand Up @@ -69,6 +64,7 @@ install(FILES LICENSE NOTICE
# Subprojects
# ---------------------------------------------------------------------------
add_subdirectory(python)
add_subdirectory(operators)
add_subdirectory(applications)
Comment thread
tbirdso marked this conversation as resolved.
Resolved

if({{ cookiecutter.module_slug | upper }}_BUILD_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ distributing this Holoscan Module.
├── cmake/ # CMake helpers copied from the CLI at create time
├── python/
│ ├── CMakeLists.txt # Stages holoscan_{{ cookiecutter.module_slug }} in the build tree
│ └── holoscan_{{ cookiecutter.module_slug }}/
│ └── operators/
│ └── {{ cookiecutter.operator_slug }}.py # Operator implementation (typed ports)
├── operators/
│ └── holoscan_{{ cookiecutter.module_slug }}/ # Package root (__init__.py, py.typed)
├── operators/ # holoscan_{{ cookiecutter.module_slug }}.operators
│ ├── CMakeLists.txt # add_holohub_operator() per operator (OP_<name>)
│ ├── __init__.py # Exports every enabled operator
│ └── {{ cookiecutter.operator_slug }}/
│ └── metadata.json # Operator-level metadata
│ ├── CMakeLists.txt # Stages the operator's Python sources
│ ├── __init__.py
│ ├── {{ cookiecutter.operator_slug }}.py # Operator implementation (typed ports)
│ └── metadata.json # Operator-level metadata (not packaged)
├── applications/
│ └── {{ cookiecutter.module_slug }}_pipeline/
│ └── python/ # Python pipeline (compose → compile → run) + metadata.json
Expand All @@ -41,8 +44,14 @@ import holoscan as hs
from holoscan_{{ cookiecutter.module_slug }}.operators import {{ op_class }}
```

- Add each new operator as a module under `python/holoscan_{{ cookiecutter.module_slug }}/operators/`, export it from
`operators/__init__.py`, and describe it in an `operators/<name>/metadata.json`.
- Add each new operator in its own `operators/<name>/` directory with an `__init__.py` that exports
it, the implementation, a `metadata.json`, and a `CMakeLists.txt` calling
`holoscan_{{ cookiecutter.module_slug }}_add_python_operator()`. Then add `add_holohub_operator(<name>)` to
`operators/CMakeLists.txt` and `cmake.define.OP_<name> = "ON"` to `pyproject.toml`.
- Only operators whose `OP_<name>` option is ON (default `${BUILD_ALL}`) are staged in the build tree
and installed into the wheel as `holoscan_{{ cookiecutter.module_slug }}.operators.<name>`;
`operators/__init__.py` exports whichever are present at runtime. Also add the operator to its
`if TYPE_CHECKING:` imports so type checkers and IDEs resolve it.
- The package's `holoscan.modules` entry point makes `import holoscan.{{ cookiecutter.module_slug }}` load
`holoscan_{{ cookiecutter.module_slug }}`. `pyproject.toml` declares it for the wheel, and `python/CMakeLists.txt` writes
the same `holoscan-{{ cookiecutter.module_slug.replace('_', '-') }}` metadata into the build tree's `python/lib`.
Expand All @@ -51,7 +60,7 @@ from holoscan_{{ cookiecutter.module_slug }}.operators import {{ op_class }}
use `PYTHONPATH=build/python/lib:$PYTHONPATH python3
applications/{{ cookiecutter.module_slug }}_pipeline/python/{{ cookiecutter.module_slug }}_pipeline.py`.
- `tests/python` runs through CTest (label `python`), or directly with pytest after
`python -m pip install -e .`.
an editable install (see [Working without the Holoscan CLI](#working-without-the-holoscan-cli)).
- `holoscan package {{ cookiecutter.module_repo_name }} --pkg-generator WHEEL` builds a `py3-none-any`
`holoscan-{{ cookiecutter.module_slug.replace('_', '-') }}` wheel that depends on `holoscan-core-cu13`. There is no Debian package.

Expand Down Expand Up @@ -122,11 +131,17 @@ With Python 3.12+ and glibc 2.39 or newer (for example Ubuntu 24.04), pip instal
the Holoscan SDK wheels it depends on:

```bash
python -m pip install -e . pytest
python -m pip install "scikit-build-core~=1.0.3" cmake ninja pytest
python -m pip install --no-build-isolation -Ceditable.rebuild=true -e .
python -m pytest tests/python
python -m pip wheel --no-deps -w dist .
```

The editable install keeps its CMake build in `build/editable` and re-stages the enabled operators
when the package is imported, so source edits take effect without reinstalling.
`--no-build-isolation` lets that rebuild find CMake and Ninja. A plain `pip install -e .` also
works, but it copies the operators, so rerun it after editing them.

The CMake project needs only CMake 3.24 or newer and Python; it enables no compiled languages:

```bash
Expand All @@ -145,11 +160,11 @@ and `OFF` when this module is included by a parent project. The standard

| Field | Purpose |
| --- | --- |
| `[build-system]` | scikit-build-core builds the wheel; `CMakeLists.txt` returns early for wheel builds |
| `[build-system]` | scikit-build-core builds the wheel; CMake stages the package and compiles nothing |
| `[project].version` | Sync with `metadata.json:module.version` |
| `[project].dependencies` | Runtime dependencies; `holoscan-core-cu13` installs the Holoscan SDK core; add `holoscan-vision-cu13`, `holoscan-visualization-cu13` or `holoscan-inference-cu13` if the Module imports them |
| `[project.entry-points."holoscan.modules"]` | Exposes `holoscan_{{ cookiecutter.module_slug }}` as `holoscan.{{ cookiecutter.module_slug }}` |
| `[tool.scikit-build]` | Packages `python/holoscan_{{ cookiecutter.module_slug }}` into a pure-Python wheel |
| `[tool.scikit-build]` | Installs the `holoscan-{{ cookiecutter.module_slug }}-python_libs` component, with the operators enabled by `cmake.define.OP_<name>`, into a pure-Python wheel |
| `[dependency-groups].dev` | Exact CLI convenience pin, ruff, and pytest; keep the CLI pin synchronized with `requirements-cli.txt` |
| `[tool.uv]` | NVIDIA index selection for the pinned `holoscan-cli` development dependency |
| `[tool.holoscan]` | Optional Module-wide CUDA, CTest, Docker, environment, and base-image defaults consumed by the CLI |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ The Holoscan SDK wheels need glibc 2.39 or newer, for example Ubuntu 24.04. Inst
with pip, then run its tests:

```bash
python -m pip install -e . pytest
python -m pip install "scikit-build-core~=1.0.3" cmake ninja pytest
python -m pip install --no-build-isolation -Ceditable.rebuild=true -e .
python -m pytest tests/python
```

The editable install rebuilds on import, so operator edits take effect without reinstalling. It
needs `--no-build-isolation` so the rebuild can find CMake and Ninja.

Building the wheel needs CMake 3.24 or newer, which pip downloads when it is missing, but no
compiler.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# SPDX-FileCopyrightText: Copyright (c) {% now 'utc', '%Y' %} {{ cookiecutter.full_name }}{% if cookiecutter.affiliation %} / {{ cookiecutter.affiliation }}{% endif %}. All rights reserved.
# SPDX-License-Identifier: {{ cookiecutter._license }}
{%- if cookiecutter.__pure_python == 'yes' %}

# Stage operators/__init__.py, which exports every operator staged next to it.
set(_python_build_var {{ cookiecutter.module_slug | upper }}_PYTHON_BUILD_DIR)
configure_file(__init__.py
"${${_python_build_var}}/holoscan_{{ cookiecutter.module_slug }}/operators/__init__.py" COPYONLY)
{%- endif %}

# Each operator is gated on its own OP_<name> option, defaulting to ${BUILD_ALL}.
# Add one add_holohub_operator() call per operator.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: Copyright (c) {% now 'utc', '%Y' %} {{ cookiecutter.full_name }}{% if cookiecutter.affiliation %} / {{ cookiecutter.affiliation }}{% endif %}. All rights reserved.
# SPDX-License-Identifier: {{ cookiecutter._license }}
{%- set op_class = cookiecutter.operator_slug.split('_')|map('capitalize')|join('') %}

"""{{ cookiecutter.project_name }} operators.

Exports every operator package staged next to this file. The build and the wheel include an
operator only when its ``OP_<name>`` CMake option is ON.
"""

import importlib
import pkgutil
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
from typing import TYPE_CHECKING

if TYPE_CHECKING: # one import per operator, for type checkers and IDEs
from .{{ cookiecutter.operator_slug }} import {{ op_class }} as {{ op_class }}

__all__: list[str] = []
for _info in pkgutil.iter_modules(__path__):
_operator = importlib.import_module(f".{_info.name}", __name__)
for _name in getattr(_operator, "__all__", ()):
globals()[_name] = getattr(_operator, _name)
__all__.append(_name)
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# SPDX-FileCopyrightText: Copyright (c) {% now 'utc', '%Y' %} {{ cookiecutter.full_name }}{% if cookiecutter.affiliation %} / {{ cookiecutter.affiliation }}{% endif %}. All rights reserved.
# SPDX-License-Identifier: {{ cookiecutter._license }}
{%- if cookiecutter.__pure_python == 'yes' %}

# Stage this operator's Python sources as holoscan_{{ cookiecutter.module_slug }}.operators.{{ cookiecutter.operator_slug }}.
holoscan_{{ cookiecutter.module_slug }}_add_python_operator()
{%- else %}

add_library({{ cookiecutter.operator_slug }} {{ cookiecutter.operator_slug }}.cpp)
add_library(holoscan::{{ cookiecutter.operator_slug }} ALIAS {{ cookiecutter.operator_slug }})
Expand All @@ -21,3 +26,4 @@ install(FILES {{ cookiecutter.operator_slug }}.hpp DESTINATION include/{{ cookie
# holoscan::{{ cookiecutter.operator_slug }}.
install(TARGETS {{ cookiecutter.operator_slug }}
EXPORT holoscan_{{ cookiecutter.module_slug }}_targets)
{%- endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: Copyright (c) {% now 'utc', '%Y' %} {{ cookiecutter.full_name }}{% if cookiecutter.affiliation %} / {{ cookiecutter.affiliation }}{% endif %}. All rights reserved.
# SPDX-License-Identifier: {{ cookiecutter._license }}
{%- set op_class = cookiecutter.operator_slug.split('_')|map('capitalize')|join('') %}

"""The {{ op_class }} operator package."""

from .{{ cookiecutter.operator_slug }} import {{ op_class }}

__all__ = ["{{ op_class }}"]
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,21 @@ package = false
{%- if cookiecutter.__pure_python == 'yes' %}

[tool.scikit-build]
# The wheel holds only the Python package; CMake builds nothing (see CMakeLists.txt).
wheel.packages = ["python/holoscan_{{ cookiecutter.module_slug }}"]
# CMake compiles nothing; it stages the package and the operators enabled below.
# Add one cmake.define.OP_<name> = "ON" line per operator the wheel ships.
wheel.packages = []
wheel.platlib = false
install.components = ["holoscan-{{ cookiecutter.module_slug }}-python_libs"]
cmake.define.BUILD_ALL = "OFF"
cmake.define.OP_{{ cookiecutter.operator_slug }} = "ON"
cmake.define.{{ cookiecutter.module_slug | upper }}_BUILD_TESTING = "OFF"

[[tool.scikit-build.overrides]]
# Editable installs keep a build directory, so
# `pip install --no-build-isolation -Ceditable.rebuild=true -e .` re-stages edited
# operators on import.
if.state = "editable"
build-dir = "build/editable"
{%- elif cookiecutter.__python_bindings == 'yes' %}

[tool.scikit-build]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,54 @@

# Stage the holoscan_{{ cookiecutter.module_slug }} package and its holoscan-{{ cookiecutter.module_slug.replace('_', '-') }} distribution metadata in the
# build tree, so `holoscan run` and the tests can import it as holoscan_{{ cookiecutter.module_slug }} and as
# holoscan.{{ cookiecutter.module_slug }}. Wheels take the same package and metadata from pyproject.toml.
# holoscan.{{ cookiecutter.module_slug }}. Operators join the package through
# holoscan_{{ cookiecutter.module_slug }}_add_python_operator() when their OP_<name> option is ON.
# Wheel builds install the same component; pyproject.toml supplies the metadata.

set(_package holoscan_{{ cookiecutter.module_slug }})
set(_python_root "${CMAKE_CURRENT_BINARY_DIR}/lib")
set({{ cookiecutter.module_slug | upper }}_PYTHON_BUILD_DIR "${_python_root}" PARENT_SCOPE)
if(SKBUILD)
set({{ cookiecutter.module_slug | upper }}_PYTHON_INSTALL_DIR "." CACHE PATH "" FORCE)
endif()
set({{ cookiecutter.module_slug | upper }}_PYTHON_INSTALL_DIR
"lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages"
CACHE PATH "Install directory of the holoscan_{{ cookiecutter.module_slug }} Python package")
set(_python_install_var {{ cookiecutter.module_slug | upper }}_PYTHON_INSTALL_DIR)

# Drop operators staged by an earlier configure, in case their OP_<name> option is now OFF.
file(REMOVE_RECURSE "${_python_root}/${_package}/operators")

file(GLOB_RECURSE _package_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS
"${_package}/*.py" "${_package}/*.pyi" "${_package}/py.typed")
foreach(package_file IN LISTS _package_files)
configure_file("${package_file}" "${_python_root}/${package_file}" COPYONLY)
endforeach()

set(_dist_info "${_python_root}/holoscan_{{ cookiecutter.module_slug }}-${PROJECT_VERSION}.dist-info")
file(WRITE "${_dist_info}/METADATA"
"Metadata-Version: 2.1\nName: holoscan-{{ cookiecutter.module_slug.replace('_', '-') }}\nVersion: ${PROJECT_VERSION}\n")
# Root-Is-Purelib marks the build as complete without a compiled extension for `holoscan install --dev`.
file(WRITE "${_dist_info}/WHEEL"
"Wheel-Version: 1.0\nGenerator: holoscan-cli\nRoot-Is-Purelib: true\nTag: py3-none-any\n")
file(WRITE "${_dist_info}/entry_points.txt"
"[holoscan.modules]\n{{ cookiecutter.module_slug }} = holoscan_{{ cookiecutter.module_slug }}\n")
# Stage the Python sources of the calling operators/<name>/ directory as
# holoscan_{{ cookiecutter.module_slug }}.operators.<name>. add_holohub_operator() only adds that directory when
# OP_<name> is ON, so disabled operators stay out of the build tree and the wheel.
function(holoscan_{{ cookiecutter.module_slug }}_add_python_operator)
get_filename_component(_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
set(_python_build_var {{ cookiecutter.module_slug | upper }}_PYTHON_BUILD_DIR)
file(GLOB _sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "*.py" "*.pyi")
foreach(source IN LISTS _sources)
configure_file("${source}"
"${${_python_build_var}}/holoscan_{{ cookiecutter.module_slug }}/operators/${_name}/${source}"
COPYONLY)
endforeach()
endfunction()

if(NOT SKBUILD)
set(_dist_info "${_python_root}/holoscan_{{ cookiecutter.module_slug }}-${PROJECT_VERSION}.dist-info")
file(WRITE "${_dist_info}/METADATA"
"Metadata-Version: 2.1\nName: holoscan-{{ cookiecutter.module_slug.replace('_', '-') }}\nVersion: ${PROJECT_VERSION}\n")
# Root-Is-Purelib marks the build as complete without a compiled extension for `holoscan install --dev`.
file(WRITE "${_dist_info}/WHEEL"
"Wheel-Version: 1.0\nGenerator: holoscan-cli\nRoot-Is-Purelib: true\nTag: py3-none-any\n")
file(WRITE "${_dist_info}/entry_points.txt"
"[holoscan.modules]\n{{ cookiecutter.module_slug }} = holoscan_{{ cookiecutter.module_slug }}\n")
endif()

# Install the staged package without a packaging backend:
# cmake --install <build> --component holoscan-{{ cookiecutter.module_slug }}-python_libs
Expand Down
Loading
Loading