Skip to content

Add ctl_py, the build support for a Python management CLI - #2

Open
ChuangZiyan wants to merge 1 commit into
NVIDIA:feat/ctl-python-rewritefrom
ChuangZiyan:pr/1-build-support
Open

ChuangZiyan wants to merge 1 commit into
NVIDIA:feat/ctl-python-rewritefrom
ChuangZiyan:pr/1-build-support

Conversation

@ChuangZiyan

@ChuangZiyan ChuangZiyan commented Oct 8, 2026 •

Copy link
Copy Markdown

Summary

First step of the python3 rewrite of storage-lender-ctl. This PR only prepares the build system; nothing that is built or installed changes today.

  • Everything Python-specific lives under ctl_py/ with a pyproject.toml that declares the package, its runtime dependency on protobuf>=3.20, the pytest extra, the console_scripts entry point, and the ruff/pytest configuration. The directory is renamed to ctl/ once the C++ tool is removed.
  • BUILD_PYTHON_CTL option (default OFF). When ON, CMake selects the Python 3.10+ interpreter and verifies that the google.protobuf runtime is at least 3.20, which is what protoc 3.21 output requires (cmake/FindPython3Protobuf.cmake).
  • ctl_py/CMakeLists.txt generates wire_pb2.py and ctl_pb2.py and stages the package into the build tree; an import smoke test fails if the runtime and the generated code disagree. The package version is declared once in _version.py and checked against the CMake project version at configure time (no templates).
  • add_lender_python_test() registers a pytest run as one CTest entry with the same label conventions as add_lender_test().
  • ci/check-spdx.sh covers *.py; pre-commit runs ruff (lint + format) using the configuration in pyproject.toml.

Follow-up PRs, in order: tool skeleton + latency, quota + install, removal of the C++ ctl (with the ctl_py/ → ctl/ rename), docs.

Operational note: the self-hosted CI runner needs python3-protobuf and python3-pytest installed for the BUILD_PYTHON_CTL=ON path, and pre-commit will fetch the ruff hook on first run.

Verification

Ubuntu 24.04, python3 3.12.3, python3-protobuf 4.21.12, protoc 3.21.12, python3-pytest 7.4.4.

cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_PYTHON_CTL=ON
cmake --build build --target StorageLenderCtlPy
ctest --test-dir build -L ctl --output-on-failure       # StorageLenderCtlPyTests passed
ctest --test-dir build -LE hardware                     # 100% passed
./ci/check-spdx.sh                                      # SPDX check passed
ruff check ctl_py && ruff format --check ctl_py         # clean
pip install --no-deps --no-build-isolation --prefix=<tmp> ./ctl_py   # metadata and entry point verified

Also configured with BUILD_PYTHON_CTL=OFF (the default) to confirm no Python dependency is required and the build is unchanged. Not run: pre-commit run --all-files end to end (ruff was run directly with the pinned version).

Checklist

  • I followed CONTRIBUTING.md and the Code of Conduct.
  • I signed off every commit in this pull request (git commit --signoff).
  • I added or updated tests for behavior changes.
  • I updated affected public contracts and documentation.
  • I identified security, compatibility, packaging, and third-party-license impact.
  • Any hardware tests I ran used a deliberately provisioned NVMe controller.
  • I did not include credentials, personal information, or internal-only material.

🤖 Generated with Claude Code

@ChuangZiyan
ChuangZiyan requested a review from a team as a code owner October 8, 2026 02:54
@msharmavikram

Copy link
Copy Markdown

Thanks for your contribution!

Comment thread ci/check-spdx.sh Resolved
Comment thread cmake/AddLenderPythonTest.cmake Resolved
@hdefreitasco

Copy link
Copy Markdown
Collaborator

Maybe you have this already in mind and then the changes here would naturally transition from this, but I was expecting we could adopt the modern way of organizing python projects with a pyproject.toml. We could put it in ctl_py/ for now, until the old ctl/ can be removed and the new renamed. And then all python specific code (including dependency declarations like protobuf and pytest) would be isolated in that new directory. Is this a viable option? What you think?

@ChuangZiyan

Copy link
Copy Markdown
Author

Maybe you have this already in mind and then the changes here would naturally transition from this, but I was expecting we could adopt the modern way of organizing python projects with a pyproject.toml. We could put it in ctl_py/ for now, until the old ctl/ can be removed and the new renamed. And then all python specific code (including dependency declarations like protobuf and pytest) would be isolated in that new directory. Is this a viable option? What you think?

Yes, that works and it's cleaner. I'll move everything Python into ctl_py/ with a pyproject.toml (deps, ruff/pytest config, console_scripts entry point instead of the launcher), keep CMake only for generating the _pb2 modules, hooking pytest into CTest and installing the package, and rework PR 1 and 2 on that layout : )

Prepare a python3 rewrite of storage-lender-ctl without changing what
is built or installed today. Everything Python-specific lives under
ctl_py/ with a pyproject.toml that declares the package, its runtime
dependency on protobuf, the pytest extra, and the ruff configuration.

- BUILD_PYTHON_CTL (default OFF) selects the Python interpreter and
  verifies that the google.protobuf runtime is at least 3.20, which is
  what protoc 3.21 output requires.
- ctl_py/CMakeLists.txt generates wire_pb2.py and ctl_pb2.py and stages
  the package into the build tree; a smoke test fails when the runtime
  and the generated code disagree. The package version is declared in
  _version.py and checked against the CMake project version.
- add_lender_python_test() registers a pytest run as one CTest entry
  with the same label conventions as add_lender_test().
- The SPDX check covers *.py, and pre-commit runs ruff on Python
  sources.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Ziyan Zhuang <ziyan.zhuang@h3platform.com>
@ChuangZiyan ChuangZiyan changed the title Add build support for a Python management CLI Add ctl_py, the build support for a Python management CLI Oct 16, 2026
@ChuangZiyan

Copy link
Copy Markdown
Author

Reworked per your comments:

  • Python code now lives in ctl_py/ with a pyproject.toml
  • no .py.in templates
  • redundant find_package guards removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants