Commit 52d23556 authored by Boris Glimcher's avatar Boris Glimcher Committed by Jim Harris
Browse files

python: add executable scripts and readme

see https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts



I tested build/install like:

* uv pip install python/dist/spdk-25.1rc0-py3-none-any.whl
* uv pip install python/
* make -C python install
* python -m build --sdist python/
* python -m build --wheel python/

Post installation scripts are present like this

$ find ~/.venv/ | grep spdk
~/.venv/bin/spdk-sma
~/.venv/bin/spdk-rpc
~/.venv/bin/spdk-cli

$ which spdk-sma spdk-rpc spdk-cli
~/.venv/bin/spdk-sma
~/.venv/bin/spdk-rpc
~/.venv/bin/spdk-cli

See the changelog about using new format for binaries with "-" instead of "_".

Change-Id: Ibca14ca1fabf6249964826fe9c83cce86021ea19
Signed-off-by: default avatarBoris Glimcher <Boris.Glimcher@emc.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/25938


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent fc48348e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@

## v25.05

### python

Renamed python binaries with "-" instead of "_"
spdk-rpc, spdk-sma and spdk-cli to be more platform
independent for linux/windows according to pypi and hatch suggestions

### bdev_nvme

Added controller configuration consistency check, so all controllers created with the same name will
+10 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/spdk/spdk/go/rpc)
[![Go Report Card](https://goreportcard.com/badge/github.com/spdk/spdk/go/rpc)](https://goreportcard.com/report/github.com/spdk/spdk/go/rpc)
[![PyPI Latest Release](https://img.shields.io/pypi/v/spdk.svg)](https://pypi.org/project/spdk/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/spdk.svg?label=PyPI%20downloads)](https://pypi.org/project/spdk/)

NOTE: The SPDK mailing list has moved to a new location. Please visit
[this URL](https://lists.linuxfoundation.org/mailman/listinfo/spdk) to subscribe
@@ -267,6 +269,14 @@ as a privileged user (root) unless you've done additional configuration
to grant your user permission to allocate huge pages and map devices through
vfio.

<a id="python"></a>
## Python bindings

SPDK python bindings and scripts are located in [python](./python) folder. Python code is
automatically built as part of the build process. Python package is also published
to <https://pypi.org/project/spdk/> every release for ease of consumption. For more
details, check the [README](./python/README.md).

<a id="contributing"></a>
## Contributing

+4 −17
Original line number Diff line number Diff line
@@ -50,27 +50,14 @@ spdk/version.py: $(SPDK_ROOT_DIR)/VERSION
		$(version_major) $(version_minor) \
		$(shell echo -n \"$(version_suffix)\" | sed 's/-pre/rc0/g' | tr -d -) > spdk/version.py

install: rpc spdkcli
install:
	$(Q)$(setup_cmd) $(SPDK_ROOT_DIR)/python
	rm -rf $(SPDK_ROOT_DIR)/python/spdk.egg-info

$(SPDK_ROOT_DIR)/build/bin/spdk_rpc:
	cp $(SPDK_ROOT_DIR)/scripts/rpc.py $(SPDK_ROOT_DIR)/build/bin/spdk_rpc
	chmod +x $(SPDK_ROOT_DIR)/build/bin/spdk_rpc

$(SPDK_ROOT_DIR)/build/bin/spdk_cli:
	cp $(SPDK_ROOT_DIR)/scripts/spdkcli.py $(SPDK_ROOT_DIR)/build/bin/spdk_cli
	chmod +x $(SPDK_ROOT_DIR)/build/bin/spdk_cli

rpc: $(SPDK_ROOT_DIR)/build/bin/spdk_rpc
	$(INSTALL_APP)

spdkcli: $(SPDK_ROOT_DIR)/build/bin/spdk_cli
	$(INSTALL_APP)

uninstall:
	$(Q)rm -rf $(DESTDIR)/$(pylibdir)/spdk*
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk_rpc
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk_cli
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-rpc
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-sma
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-cli

.PHONY: all clean install uninstall

python/README.md

0 → 100644
+54 −0
Original line number Diff line number Diff line
# SPDK Python Bindings and Scripts

[![PyPI Latest Release](https://img.shields.io/pypi/v/spdk.svg)](https://pypi.org/project/spdk/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/spdk.svg?label=PyPI%20downloads)](https://pypi.org/project/spdk/)

## Overview

The Storage Performance Development Kit ([SPDK](http://www.spdk.io)) provides a set of tools
and libraries for writing high performance, scalable, user-mode storage
applications. This directory contains Python bindings and scripts that facilitate interaction with SPDK components.

## Installation

Examples below are using [UV](https://docs.astral.sh/uv/getting-started/installation/).

An extremely fast Python package and project manager, written in Rust.

```shell
$ uv venv
$ source .venv/bin/activate
```

Then, you can install spdk from PyPI with:

```shell
uv pip install spdk
```

or install from source with:

```shell
git clone https://github.com/spdk/spdk.git
cd spdk
uv pip install python/
```

## Getting Started

From a shell:

```bash
spdk-rpc rpc_get_methods
```

From a Python interpreter:

```python
>>> from spdk.rpc.client import JSONRPCClient

>>> client = JSONRPCClient(server_addr, port)
>>> client.call("rpc_get_methods")
```

For more information, see <https://spdk.io/doc/jsonrpc.html>
+19 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ build-backend = "hatchling.build"
[project]
name = "spdk"
dynamic = ["version"]
readme = "README.md"
description = "Python bindings for the Storage Performance Development Kit (SPDK)"
requires-python = ">=3.8"
license = { text = "BSD-3-Clause" }
@@ -39,10 +40,16 @@ dependencies = []
"Source" = "https://github.com/spdk/spdk"
"Bug Tracker" = "https://github.com/spdk/spdk/issues"

[project.scripts]
spdk-rpc = "spdk.spdk_rpc:main"
spdk-sma = "spdk.spdk_sma:main"
spdk-cli = "spdk.spdk_cli:main"

[project.optional-dependencies]
sma = [
    "grpcio",
    "protobuf"
    "protobuf",
    "pyyaml"
]
cli = [
    "configshell_fb"
@@ -50,3 +57,14 @@ cli = [

[tool.hatch.version]
path = "spdk/version.py"

# TODO: this is not ideal, better move pyproject file to the top
[tool.hatch.build.targets.sdist.force-include]
"../scripts/rpc.py" = "../scripts/rpc.py"
"../scripts/sma.py" = "../scripts/sma.py"
"../scripts/spdkcli.py" = "../scripts/spdkcli.py"

[tool.hatch.build.targets.wheel.force-include]
"../scripts/rpc.py" = "spdk/spdk_rpc.py"
"../scripts/sma.py" = "spdk/spdk_sma.py"
"../scripts/spdkcli.py" = "spdk/spdk_cli.py"