• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nvidia-holoscan / holoscan-cli / 12994156957

27 Jan 2025 04:58PM UTC coverage: 68.934% (-0.04%) from 68.969%
12994156957

Pull #18

github

mocsharp
Test

Signed-off-by: Victor Chang <vicchang@nvidia.com>
Pull Request #18: Release/2.9.0

0 of 1 new or added line in 1 file covered. (0.0%)

1358 of 1970 relevant lines covered (68.93%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.29
/src/holoscan_cli/packager/packager.py
1
# SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
# http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import json
1✔
16
import logging
1✔
17
import os
1✔
18
import sys
1✔
19
import tempfile
1✔
20
from argparse import Namespace
1✔
21

22
from ..common.enum_types import ApplicationType
1✔
23
from ..common.utils import print_manifest_json
1✔
24
from .arguments import PackagingArguments
1✔
25
from .container_builder import CppAppBuilder, PythonAppBuilder
1✔
26
from .manifest_files import ApplicationManifest, PackageManifest
1✔
27
from .parameters import PlatformBuildResults
1✔
28

29
logger = logging.getLogger("packager")
1✔
30

31

32
def _build_image(args: PackagingArguments, temp_dir: str) -> list[PlatformBuildResults]:
1✔
33
    """Creates dockerfile and builds HAP/MONAI Application Package (HAP/MAP) image
34
    Args:
35
        args (dict): Input arguments for Packager
36
        temp_dir (str): Temporary directory to build MAP
37
    """
38
    if (
×
39
        args.build_parameters.application_type == ApplicationType.PythonFile
40
        or args.build_parameters.application_type == ApplicationType.PythonModule
41
    ):
42
        builder = PythonAppBuilder(args.build_parameters, temp_dir)
×
43
    elif (
×
44
        args.build_parameters.application_type == ApplicationType.Binary
45
        or args.build_parameters.application_type == ApplicationType.CppCMake
46
    ):
47
        builder = CppAppBuilder(args.build_parameters, temp_dir)
×
48

49
    results = [builder.build(platform) for platform in args.platforms]
×
50
    return results
×
51

52

53
def _create_app_manifest(manifest: ApplicationManifest, temp_dir: str):
1✔
54
    """Creates Application manifest .json file
55
    Args:
56
        manifest (Dict): Input arguments for Packager
57
        temp_dir (str): Temporary directory to build MAP
58
    """
59
    map_folder_path = os.path.join(temp_dir, "map")
×
60
    os.makedirs(map_folder_path, exist_ok=True)
×
61
    with open(os.path.join(map_folder_path, "app.json"), "w") as app_manifest_file:
×
62
        app_manifest_file.write(json.dumps(manifest.data))
×
63

64
    print_manifest_json(manifest.data, "app.json")
×
65

66

67
def _create_package_manifest(manifest: PackageManifest, temp_dir: str):
1✔
68
    """Creates package manifest .json file
69
    Args:
70
        manifest (Dict): Input arguments for Packager
71
        temp_dir (str): Temporary directory to build MAP
72
    """
73
    map_folder_path = os.path.join(temp_dir, "map")
×
74
    os.makedirs(map_folder_path, exist_ok=True)
×
75
    with open(os.path.join(temp_dir, "map", "pkg.json"), "w") as package_manifest_file:
×
76
        package_manifest_file.write(json.dumps(manifest.data))
×
77

78
    print_manifest_json(manifest.data, "pkg.json")
×
79

80

81
def _package_application(args: Namespace):
1✔
82
    """Driver function for invoking all functions for creating and
83
    building the Holoscan Application package image
84
    Args:
85
        args (Namespace): Input arguments for Packager from CLI
86
    """
87
    # Initialize arguments for package
88
    with tempfile.TemporaryDirectory(
×
89
        prefix="holoscan_tmp", dir=tempfile.gettempdir()
90
    ) as temp_dir:
91
        packaging_args = PackagingArguments(args, temp_dir)
×
92

93
        # Create Manifest Files
94
        _create_app_manifest(packaging_args.application_manifest, temp_dir)
×
95
        _create_package_manifest(packaging_args.package_manifest, temp_dir)
×
96

97
        results = _build_image(packaging_args, temp_dir)
×
98

99
        logger.info("Build Summary:")
×
100
        for result in results:
×
101
            if result.succeeded:
×
102
                print(
×
103
                    f"""\nPlatform: {result.parameters.platform.value}/{result.parameters.platform_config.value}
104
    Status:     Succeeded
105
    Docker Tag: {result.docker_tag if result.docker_tag is not None else "N/A"}
106
    Tarball:    {result.tarball_filenaem}"""  # noqa: E501
107
                )
108
            else:
109
                print(
×
110
                    f"""\nPlatform: {result.parameters.platform.value}/{result.parameters.platform_config.value}
111
    Status: Failure
112
    Error:  {result.error}
113
    """  # noqa: E501
114
                )
NEW
115
                sys.exit(1)
×
116

117

118
def execute_package_command(args: Namespace):
1✔
119
    try:
×
120
        _package_application(args)
×
121
    except Exception as e:
×
122
        logger.debug(e, exc_info=True)
×
123
        logger.error(f"Error packaging application:\n\n{str(e)}")
×
124
        sys.exit(1)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc