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

nvidia-holoscan / holoscan-cli / 14098947973

27 Mar 2025 04:33AM UTC coverage: 85.6% (-0.2%) from 85.772%
14098947973

Pull #33

github

mocsharp
Use GITHUB_RUN_ID if avaialble to avoid upload failures

Signed-off-by: Victor Chang <vicchang@nvidia.com>
Pull Request #33: Enable test-app with nv-gha-runner

40 of 51 new or added lines in 8 files covered. (78.43%)

3 existing lines in 3 files now uncovered.

1712 of 2000 relevant lines covered (85.6%)

0.86 hits per line

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

92.31
/src/holoscan_cli/common/argparse_types.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 argparse
1✔
16
import os
1✔
17
from pathlib import Path
1✔
18
from .constants import SDK
1✔
19
from .enum_types import Platform, PlatformConfiguration, SdkType
1✔
20

21

22
def valid_dir_path(path: str, create_if_not_exists: bool = True) -> Path:
1✔
23
    """Helper type checking and type converting method for ArgumentParser.add_argument
24
    to convert string input to pathlib.Path if the given path exists and it is a directory path.
25
    If directory does not exist, create the directory and convert string input to pathlib.Path.
26

27
    Args:
28
        path: string input path
29

30
    Returns:
31
        If path exists and is a directory, return absolute path as a pathlib.Path object.
32

33
        If path exists and is not a directory, raises argparse.ArgumentTypeError.
34

35
        If path doesn't exist, create the directory and return absolute path as a pathlib.Path
36
        object.
37
    """
38
    path = os.path.expanduser(path)
1✔
39
    dir_path = Path(path).absolute()
1✔
40
    if dir_path.exists():
1✔
41
        if dir_path.is_dir():
1✔
42
            return dir_path
1✔
43
        else:
44
            raise argparse.ArgumentTypeError(
1✔
45
                f"Expected directory path: '{dir_path}' is not a directory"
46
            )
47

48
    if create_if_not_exists:
1✔
49
        # create directory
50
        dir_path.mkdir(parents=True)
1✔
51
        return dir_path
1✔
52

53
    raise argparse.ArgumentTypeError(f"No such directory: '{dir_path}'")
1✔
54

55

56
def valid_existing_dir_path(path: str) -> Path:
1✔
57
    """Helper type checking and type converting method for ArgumentParser.add_argument
58
    to convert string input to pathlib.Path if the given path exists and it is a directory path.
59

60
    Args:
61
        path: string input path
62

63
    Returns:
64
        If path exists and is a directory, return absolute path as a pathlib.Path object.
65

66
        If path doesn't exist or it is not a directory, raises argparse.ArgumentTypeError.
67
    """
68
    return valid_dir_path(path, False)
1✔
69

70

71
def valid_existing_path(path: str) -> Path:
1✔
72
    """Helper type checking and type converting method for ArgumentParser.add_argument
73
    to convert string input to pathlib.Path if the given file/folder path exists.
74

75
    Args:
76
        path: string input path
77

78
    Returns:
79
        If path exists, return absolute path as a pathlib.Path object.
80

81
        If path doesn't exist, raises argparse.ArgumentTypeError.
82
    """
83
    path = os.path.expanduser(path)
1✔
84
    file_path = Path(path).absolute()
1✔
85
    if file_path.exists():
1✔
86
        if file_path.is_dir():
1✔
87
            if any(os.scandir(file_path)):
1✔
88
                return file_path
1✔
89
            raise argparse.ArgumentTypeError(f"Directory is empty: '{file_path}'")
1✔
90
        return file_path
1✔
91
    raise argparse.ArgumentTypeError(f"No such file/folder: '{file_path}'")
1✔
92

93

94
def valid_platforms(platforms_str: str) -> list[Platform]:
1✔
95
    """Helper type checking and type converting method for ArgumentParser.add_argument
96
    to convert platform strings to Platform enum if values are valid.
97

98
    Args:
99
        platforms_str: string comma separated platforms values
100
    Returns:
101
        If all values are valid, convert all values to Platform enum.
102

103
        Otherwise, raises argparse.ArgumentTypeError.
104
    """
105

106
    platforms = platforms_str.lower().split(",")
1✔
107
    platform_enums = []
1✔
108
    for platform in platforms:
1✔
109
        platform = platform.strip()
1✔
110
        if platform not in SDK.PLATFORMS:
1✔
111
            raise argparse.ArgumentTypeError(
1✔
112
                f"{platform} is not a valid option for --platforms."
113
            )
114
        platform_enums.append(Platform(platform))
1✔
115

116
    return platform_enums
1✔
117

118

119
def valid_platform_config(platform_config_str: str) -> PlatformConfiguration:
1✔
120
    """Helper type checking and type converting method for ArgumentParser.add_argument
121
    to convert platform configuration string to PlatformConfigurations enum if value is valid.
122

123
    Args:
124
        platform_config_str: a platforms configuration value
125
    Returns:
126
        If the value is valid, convert the value to PlatformConfigurations enum.
127

128
        Otherwise, raises argparse.ArgumentTypeError.
129
    """
130

131
    platform_config_str = platform_config_str.lower().strip()
1✔
132
    if platform_config_str not in SDK.PLATFORM_CONFIGS:
1✔
133
        raise argparse.ArgumentTypeError(
1✔
134
            f"{platform_config_str} is not a valid option for --platform-config."
135
        )
136

137
    return PlatformConfiguration(platform_config_str)
1✔
138

139

140
def valid_sdk_type(sdk_str: str) -> SdkType:
1✔
141
    """Helper type checking and type converting method for ArgumentParser.add_argument
142
    to convert sdk string to SdkType enum if value is valid.
143

144
    Args:
145
        sdk_str: sdk string
146
    Returns:
147
        If the value is valid, convert the value to SdkType enum.
148

149
        Otherwise, raises argparse.ArgumentTypeError.
150
    """
151

152
    sdk_str = sdk_str.lower().strip()
1✔
153
    if sdk_str not in SDK.SDKS:
1✔
154
        raise argparse.ArgumentTypeError(f"{sdk_str} is not a valid option for --sdk.")
1✔
155

156
    return SdkType(sdk_str)
1✔
157

158

159
def validate_host_ip(host_ip: str) -> str:
1✔
160
    """Helper type checking and type converting method for ArgumentParser.add_argument
161
    to convert check valid host:ip format.
162

163
    Args:
164
        host_ip: host ip string
165
    """
166

NEW
167
    host, ip = host_ip.split(":")
×
NEW
168
    if host == "" or ip == "":
×
NEW
169
        raise argparse.ArgumentTypeError(f"Invalid valid for --add-host: '{host_ip}'")
×
170

NEW
171
    return host_ip
×
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