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
16 changes: 16 additions & 0 deletions modelopt/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Nvidia Model Optimizer (modelopt) CLI package."""
27 changes: 27 additions & 0 deletions modelopt/cli/nv_modelopt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Nvidia Model Optimizer (modelopt) Unified CLI Tool."""


def main() -> None:
"""Program entry point for the nv-modelopt CLI."""
print(
"Nvidia Model Optimizer (modelopt) Unified CLI Tool! This is currently a placeholder. The functionality is WIP."
)


if __name__ == "__main__":
main()
Comment on lines +19 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find and read the target file
find . -name "nv_modelopt.py" -type f | head -5

Repository: NVIDIA/Model-Optimizer

Length of output: 95


🏁 Script executed:

# Check pyproject.toml for entry points
if [ -f pyproject.toml ]; then
  grep -A 10 "\[project.scripts\]" pyproject.toml
fi

Repository: NVIDIA/Model-Optimizer

Length of output: 289


🏁 Script executed:

# Search for any argparse or sys.argv usage in the cli directory
rg "argparse|sys\.argv" modelopt/cli/ --type py

Repository: NVIDIA/Model-Optimizer

Length of output: 48


🏁 Script executed:

# Read the nv_modelopt.py file to see the actual implementation
cat -n ./modelopt/cli/nv_modelopt.py

Repository: NVIDIA/Model-Optimizer

Length of output: 1247


🏁 Script executed:

# Check if there's a cli module init file
cat -n ./modelopt/cli/__init__.py 2>/dev/null || echo "No __init__.py or file not found"

Repository: NVIDIA/Model-Optimizer

Length of output: 910


Add argument parsing to reject invalid flags and provide help output.

main() is the public CLI entry point for nv-modelopt but doesn't parse sys.argv. This means nv-modelopt --help and invalid flags both silently collapse to the placeholder message, providing a poor user experience and failing to follow standard CLI conventions. Add a minimal argparse stub to parse arguments, provide proper help output, and fail fast on unknown flags.

Suggested implementation
+import argparse
+
 
-def main() -> None:
+def main() -> int:
     """Program entry point for the nv-modelopt CLI."""
+    parser = argparse.ArgumentParser(
+        prog="nv-modelopt",
+        description="NVIDIA Model Optimizer unified CLI.",
+    )
+    parser.parse_args()
     print(
         "Nvidia Model Optimizer (modelopt) Unified CLI Tool! This is currently a placeholder. The functionality is WIP."
     )
+    return 0
 
 
 if __name__ == "__main__":
-    main()
+    raise SystemExit(main())
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modelopt/cli/nv_modelopt.py` around lines 19 - 27, Replace the placeholder
print in main() with a minimal argparse-based CLI: import argparse, create
ArgumentParser(description=...), add at least a --version/--help flag (or a
dummy subcommand) so users get standard help, call parser.parse_args() (not
parse_known_args) so unknown flags raise an error and exit, and use the parsed
args to either print the placeholder message or version; update the public
main() function to perform this parsing before printing so --help and invalid
flags behave correctly.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ dev = ["nvidia-modelopt[all,dev-docs,dev-lint,dev-test]"]
[project.urls]
Homepage = "https://github.com/NVIDIA/Model-Optimizer"

[project.scripts]
nv-modelopt = "modelopt.cli.nv_modelopt:main"

[tool.setuptools.packages.find]
include = ["modelopt*"]

Expand Down
Loading