tools: ynl: add install target
Subsystems (5)
v4 cover tools: ynl: add install target
This series adds an install target for ynl. The python code is moved to a subdirectory, so it can be used as a package with flat layout, as well as directly from the tree.
To try the install as a non-root user you can run:
$ mkdir /tmp/myroot $ make DESTDIR=/tmp/myroot install
$ PATH="/tmp/myroot/usr/bin:$PATH" PYTHONPATH="$(ls -1d /tmp/myroot/usr/lib/python*/site-packages)" ynl --help
Proposed install layout is described in last patch.
Changes in v4:
- 1/4 tools: ynl: move python code to separate sub-directory no code changes, added Reviewed-by tag from v3
- 2/4 tools: ynl: add initial pyproject.toml for packaging no longer installs ynl-gen-c and ynl-gen-rst updated commit message
- 3/4 tools: ynl: add install target for generated content fixed mix of tabs and spaces in Makefile factored out SPECS_DIR so the path is not repeated fixed TOOL2->TOOL_RST
moved clear of .rst to distclean
- 4/4 tools: ynl: add main install target
no code changes, added Reviewed-by tags from v3
Changes in v3:
- dropped symlinks
- added install-headers install-rsts install-specs to PHONY target in generated/Makefile
- install headers from lib and generated directories to /usr/include/ynl
Changes in v2:
- squashed 1st and 2nd patch together
- added symlinks for original user-facing scripts for backwards compatibility
- updated also Documentation and selftests references
(tested Doc build and selftests ping.py test)
Jan Stancek (4):
tools: ynl: move python code to separate sub-directory
tools: ynl: add initial pyproject.toml for packaging
tools: ynl: add install target for generated content
tools: ynl: add main install target
Documentation/Makefile | 2 +-
Documentation/networking/multi-pf-netdev.rst | 4 +-
Documentation/networking/napi.rst | 4 +-
.../networking/netlink_spec/readme.txt | 2 +-
.../userspace-api/netlink/intro-specs.rst | 8 +--
tools/net/ynl/Makefile | 29 ++++++++++-
tools/net/ynl/generated/.gitignore | 1 +
tools/net/ynl/generated/Makefile | 51 ++++++++++++++++---
tools/net/ynl/lib/.gitignore | 1 -
tools/net/ynl/lib/Makefile | 1 -
tools/net/ynl/pyproject.toml | 24 +++++++++
tools/net/ynl/pyynl/.gitignore | 2 +
tools/net/ynl/pyynl/__init__.py | 0
tools/net/ynl/{ => pyynl}/cli.py | 0
tools/net/ynl/{ => pyynl}/ethtool.py | 0
tools/net/ynl/{ => pyynl}/lib/__init__.py | 0
tools/net/ynl/{ => pyynl}/lib/nlspec.py | 0
tools/net/ynl/{ => pyynl}/lib/ynl.py | 0
.../ynl/{ynl-gen-c.py => pyynl/ynl_gen_c.py} | 0
.../{ynl-gen-rst.py => pyynl/ynl_gen_rst.py} | 0
tools/net/ynl/ynl-regen.sh | 2 +-
tools/testing/selftests/net/lib/py/ynl.py | 4 +-
tools/testing/selftests/net/ynl.mk | 3 +-
23 files changed, 113 insertions(+), 25 deletions(-)
create mode 100644 tools/net/ynl/pyproject.toml
create mode 100644 tools/net/ynl/pyynl/.gitignore
create mode 100644 tools/net/ynl/pyynl/__init__.py
rename tools/net/ynl/{ => pyynl}/cli.py (100%)
rename tools/net/ynl/{ => pyynl}/ethtool.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/__init__.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/nlspec.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/ynl.py (100%)
rename tools/net/ynl/{ynl-gen-c.py => pyynl/ynl_gen_c.py} (100%)
rename tools/net/ynl/{ynl-gen-rst.py => pyynl/ynl_gen_rst.py} (100%)Signature · 1 line
2.43.0
PATCH v4 1/4 tools: ynl: move python code to separate sub-directory
Move python code to a separate directory so it can be packaged as a python module. Updates existing references in selftests and docs.
Also rename ynl-gen-[c|rst] to ynl_gen_[c|rst], avoid dashes as these prevent easy imports for entrypoints.
---
Documentation/Makefile | 2 +-
Documentation/networking/multi-pf-netdev.rst | 4 ++--
Documentation/networking/napi.rst | 4 ++--
Documentation/networking/netlink_spec/readme.txt | 2 +-
Documentation/userspace-api/netlink/intro-specs.rst | 8 ++++----
tools/net/ynl/Makefile | 2 ++
tools/net/ynl/generated/Makefile | 2 +-
tools/net/ynl/lib/.gitignore | 1 -
tools/net/ynl/lib/Makefile | 1 -
tools/net/ynl/pyynl/.gitignore | 2 ++
tools/net/ynl/pyynl/__init__.py | 0
tools/net/ynl/{ => pyynl}/cli.py | 0
tools/net/ynl/{ => pyynl}/ethtool.py | 0
tools/net/ynl/{ => pyynl}/lib/__init__.py | 0
tools/net/ynl/{ => pyynl}/lib/nlspec.py | 0
tools/net/ynl/{ => pyynl}/lib/ynl.py | 0
tools/net/ynl/{ynl-gen-c.py => pyynl/ynl_gen_c.py} | 0
tools/net/ynl/{ynl-gen-rst.py => pyynl/ynl_gen_rst.py} | 0
tools/net/ynl/ynl-regen.sh | 2 +-
tools/testing/selftests/net/lib/py/ynl.py | 4 ++--
tools/testing/selftests/net/ynl.mk | 3 ++-
21 files changed, 20 insertions(+), 17 deletions(-)
create mode 100644 tools/net/ynl/pyynl/.gitignore
create mode 100644 tools/net/ynl/pyynl/__init__.py
rename tools/net/ynl/{ => pyynl}/cli.py (100%)
rename tools/net/ynl/{ => pyynl}/ethtool.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/__init__.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/nlspec.py (100%)
rename tools/net/ynl/{ => pyynl}/lib/ynl.py (100%)
rename tools/net/ynl/{ynl-gen-c.py => pyynl/ynl_gen_c.py} (100%)
rename tools/net/ynl/{ynl-gen-rst.py => pyynl/ynl_gen_rst.py} (100%)Documentation/Makefile +1 -1
@@ -104,7 +104,7 @@ quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4) YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs -YNL_TOOL:=$(srctree)/tools/net/ynl/ynl-gen-rst.py +YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml)) YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))
Documentation/networking/multi-pf-netdev.rst +2 -2
@@ -89,7 +89,7 @@ Observability ============= The relation between PF, irq, napi, and queue can be observed via netlink spec:: - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}' + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}' [{'id': 0, 'ifindex': 13, 'napi-id': 539, 'type': 'rx'}, {'id': 1, 'ifindex': 13, 'napi-id': 540, 'type': 'rx'}, {'id': 2, 'ifindex': 13, 'napi-id': 541, 'type': 'rx'},
@@ -101,7 +101,7 @@ The relation between PF, irq, napi, and queue can be observed via netlink spec:: {'id': 3, 'ifindex': 13, 'napi-id': 542, 'type': 'tx'}, {'id': 4, 'ifindex': 13, 'napi-id': 543, 'type': 'tx'}] - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}' + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}' [{'id': 543, 'ifindex': 13, 'irq': 42}, {'id': 542, 'ifindex': 13, 'irq': 41}, {'id': 541, 'ifindex': 13, 'irq': 40},
Documentation/networking/napi.rst +2 -2
@@ -199,13 +199,13 @@ parameters mentioned above use hyphens instead of underscores: Per-NAPI configuration can be done programmatically in a user application or by using a script included in the kernel source tree: -``tools/net/ynl/cli.py``. +``tools/net/ynl/pyynl/cli.py``. For example, using the script: .. code-block:: bash - $ kernel-source/tools/net/ynl/cli.py \ + $ kernel-source/tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --do napi-set \ --json='{"id": 345,
Documentation/networking/netlink_spec/readme.txt +1 -1
@@ -1,4 +1,4 @@ SPDX-License-Identifier: GPL-2.0 This file is populated during the build of the documentation (htmldocs) by the -tools/net/ynl/ynl-gen-rst.py script. +tools/net/ynl/pyynl/ynl_gen_rst.py script.
Documentation/userspace-api/netlink/intro-specs.rst +4 -4
@@ -15,7 +15,7 @@ developing Netlink related code. The tool is implemented in Python and can use a YAML specification to issue Netlink requests to the kernel. Only Generic Netlink is supported. -The tool is located at ``tools/net/ynl/cli.py``. It accepts +The tool is located at ``tools/net/ynl/pyynl/cli.py``. It accepts a handul of arguments, the most important ones are: - ``--spec`` - point to the spec file
@@ -27,7 +27,7 @@ YAML specs can be found under ``Documentation/netlink/specs/``. Example use:: - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \ + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \ --do rings-get \ --json '{"header":{"dev-index": 18}}' {'header': {'dev-index': 18, 'dev-name': 'eni1np1'},
@@ -75,7 +75,7 @@ the two marker lines like above to a file, add that file to git, and run the regeneration tool. Grep the tree for ``YNL-GEN`` to see other examples. -The code generation itself is performed by ``tools/net/ynl/ynl-gen-c.py`` +The code generation itself is performed by ``tools/net/ynl/pyynl/ynl_gen_c.py`` but it takes a few arguments so calling it directly for each file quickly becomes tedious.
@@ -84,7 +84,7 @@ YNL lib ``tools/net/ynl/lib/`` contains an implementation of a C library (based on libmnl) which integrates with code generated by -``tools/net/ynl/ynl-gen-c.py`` to create easy to use netlink wrappers. +``tools/net/ynl/pyynl/ynl_gen_c.py`` to create easy to use netlink wrappers. YNL basics ----------
tools/net/ynl/Makefile +2 -0
@@ -21,5 +21,7 @@ clean distclean: fi \ done rm -f libynl.a + rm -rf pyynl/__pycache__ + rm -rf pyynl/lib/__pycache__ .PHONY: all clean distclean $(SUBDIRS)
tools/net/ynl/generated/Makefile +1 -1
@@ -12,7 +12,7 @@ include ../Makefile.deps YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \ --exclude-op stats-get -TOOL:=../ynl-gen-c.py +TOOL:=../pyynl/ynl_gen_c.py GENS_PATHS=$(shell grep -nrI --files-without-match \ 'protocol: netlink' \
tools/net/ynl/lib/.gitignore +0 -1
@@ -1,2 +1 @@ -__pycache__/ *.d
tools/net/ynl/lib/Makefile +0 -1
@@ -19,7 +19,6 @@ ynl.a: $(OBJS) clean: rm -f *.o *.d *~ - rm -rf __pycache__ distclean: clean rm -f *.a
tools/net/ynl/pyynl/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +__pycache__/ +lib/__pycache__/
tools/net/ynl/pyynl/__init__.py new file +0 -0
tools/net/ynl/pyynl/cli.py renamed from tools/net/ynl/cli.py +0 -0
tools/net/ynl/pyynl/ethtool.py renamed from tools/net/ynl/ethtool.py +0 -0
tools/net/ynl/pyynl/lib/__init__.py renamed from tools/net/ynl/lib/__init__.py +0 -0
tools/net/ynl/pyynl/lib/nlspec.py renamed from tools/net/ynl/lib/nlspec.py +0 -0
tools/net/ynl/pyynl/lib/ynl.py renamed from tools/net/ynl/lib/ynl.py +0 -0
tools/net/ynl/pyynl/ynl_gen_c.py renamed from tools/net/ynl/ynl-gen-c.py +0 -0
tools/net/ynl/pyynl/ynl_gen_rst.py renamed from tools/net/ynl/ynl-gen-rst.py +0 -0
tools/net/ynl/ynl-regen.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause -TOOL=$(dirname $(realpath $0))/ynl-gen-c.py +TOOL=$(dirname $(realpath $0))/pyynl/ynl_gen_c.py force= search=
tools/testing/selftests/net/lib/py/ynl.py +2 -2
@@ -13,14 +13,14 @@ try: SPEC_PATH = KSFT_DIR / "net/lib/specs" sys.path.append(tools_full_path.as_posix()) - from net.lib.ynl.lib import YnlFamily, NlError + from net.lib.ynl.pyynl.lib import YnlFamily, NlError else: # Running in tree tools_full_path = KSRC / "tools" SPEC_PATH = KSRC / "Documentation/netlink/specs" sys.path.append(tools_full_path.as_posix()) - from net.ynl.lib import YnlFamily, NlError + from net.ynl.pyynl.lib import YnlFamily, NlError except ModuleNotFoundError as e: ksft_pr("Failed importing `ynl` library from kernel sources") ksft_pr(str(e))
tools/testing/selftests/net/ynl.mk +2 -1
@@ -31,7 +31,8 @@ $(OUTPUT)/libynl.a: $(YNL_SPECS) $(OUTPUT)/.libynl-$(YNL_GENS_HASH).sig $(Q)cp $(top_srcdir)/tools/net/ynl/libynl.a $(OUTPUT)/libynl.a EXTRA_CLEAN += \ - $(top_srcdir)/tools/net/ynl/lib/__pycache__ \ + $(top_srcdir)/tools/net/ynl/pyynl/__pycache__ \ + $(top_srcdir)/tools/net/ynl/pyynl/lib/__pycache__ \ $(top_srcdir)/tools/net/ynl/lib/*.[ado] \ $(OUTPUT)/.libynl-*.sig \ $(OUTPUT)/libynl.a
Signature · 1 line
2.43.0
PATCH v4 2/4 tools: ynl: add initial pyproject.toml for packaging
In reply to Jan StancekAdd pyproject.toml and define authors, dependencies and user-facing scripts. This will be used later by pip to install python code.
--- tools/net/ynl/pyproject.toml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/net/ynl/pyproject.toml
tools/net/ynl/pyproject.toml new file +24 -0
@@ -0,0 +1,24 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "pyynl" +authors = [ + {name = "Donald Hunter", email = "[email protected]"}, + {name = "Jakub Kicinski", email = "[email protected]"}, +] +description = "yaml netlink (ynl)" +version = "0.0.1" +requires-python = ">=3.9" +dependencies = [ + "pyyaml==6.*", + "jsonschema==4.*" +] + +[tool.setuptools.packages.find] +include = ["pyynl", "pyynl.lib"] + +[project.scripts] +ynl = "pyynl.cli:main" +ynl-ethtool = "pyynl.ethtool:main"
Signature · 1 line
2.43.0
PATCH v4 3/4 tools: ynl: add install target for generated content
In reply to Jan StancekGenerate docs using ynl_gen_rst and add install target for headers, specs and generates rst files.
Factor out SPECS_DIR since it's repeated many times.
--- tools/net/ynl/generated/.gitignore | 1 + tools/net/ynl/generated/Makefile | 49 +++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-)
tools/net/ynl/generated/.gitignore +1 -0
@@ -1,2 +1,3 @@ *-user.c *-user.h +*.rst
tools/net/ynl/generated/Makefile +42 -7
88 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 4/4 tools: ynl: add main install target
In reply to Jan StancekThis will install C library, specs, rsts and pyynl. The initial structure is:
$ mkdir /tmp/myroot $ make DESTDIR=/tmp/myroot install
/usr
/usr/lib64
/usr/lib64/libynl.a
/usr/lib/python3.XX/site-packages/pyynl/*
/usr/lib/python3.XX/site-packages/pyynl-0.0.1.dist-info/*
/usr/bin
/usr/bin/ynl
/usr/bin/ynl-ethtool
/usr/include/ynl/*.h
/usr/share
/usr/share/doc
/usr/share/doc/ynl
/usr/share/doc/ynl/*.rst
/usr/share/ynl
/usr/share/ynl/genetlink-c.yaml
/usr/share/ynl/genetlink-legacy.yaml
/usr/share/ynl/genetlink.yaml
/usr/share/ynl/netlink-raw.yaml
/usr/share/ynl/specs
/usr/share/ynl/specs/devlink.yaml
/usr/share/ynl/specs/dpll.yaml
/usr/share/ynl/specs/ethtool.yaml
/usr/share/ynl/specs/fou.yaml
/usr/share/ynl/specs/handshake.yaml
/usr/share/ynl/specs/mptcp_pm.yaml
/usr/share/ynl/specs/netdev.yaml
/usr/share/ynl/specs/net_shaper.yaml
/usr/share/ynl/specs/nfsd.yaml
/usr/share/ynl/specs/nftables.yaml
/usr/share/ynl/specs/nlctrl.yaml
/usr/share/ynl/specs/ovs_datapath.yaml
/usr/share/ynl/specs/ovs_flow.yaml
/usr/share/ynl/specs/ovs_vport.yaml
/usr/share/ynl/specs/rt_addr.yaml
/usr/share/ynl/specs/rt_link.yaml
/usr/share/ynl/specs/rt_neigh.yaml
/usr/share/ynl/specs/rt_route.yaml
/usr/share/ynl/specs/rt_rule.yaml
/usr/share/ynl/specs/tcp_metrics.yaml
/usr/share/ynl/specs/tc.yaml
/usr/share/ynl/specs/team.yaml--- tools/net/ynl/Makefile | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
tools/net/ynl/Makefile +26 -1
@@ -1,5 +1,17 @@ # SPDX-License-Identifier: GPL-2.0 +include ../../scripts/Makefile.arch + +INSTALL ?= install +prefix ?= /usr +ifeq ($(LP64), 1) + libdir_relative = lib64 +else + libdir_relative = lib +endif +libdir ?= $(prefix)/$(libdir_relative) +includedir ?= $(prefix)/include + SUBDIRS = lib generated samples all: $(SUBDIRS) libynl.a
@@ -23,5 +35,18 @@ clean distclean: rm -f libynl.a rm -rf pyynl/__pycache__ rm -rf pyynl/lib/__pycache__ + rm -rf pyynl.egg-info + rm -rf build + +install: libynl.a lib/*.h + @echo -e "\tINSTALL libynl.a" + @$(INSTALL) -d $(DESTDIR)$(libdir) + @$(INSTALL) -m 0644 libynl.a $(DESTDIR)$(libdir)/libynl.a + @echo -e "\tINSTALL libynl headers" + @$(INSTALL) -d $(DESTDIR)$(includedir)/ynl + @$(INSTALL) -m 0644 lib/*.h $(DESTDIR)$(includedir)/ynl/ + @echo -e "\tINSTALL pyynl" + @pip install --prefix=$(DESTDIR)$(prefix) . + @make -C generated install -.PHONY: all clean distclean $(SUBDIRS) +.PHONY: all clean distclean install $(SUBDIRS)
Signature · 1 line
2.43.0
Re: [PATCH v4 2/4] tools: ynl: add initial pyproject.toml for packaging
In reply to Jan StancekQuoted 5 lines · Jan Stancek
Add pyproject.toml and define authors, dependencies and user-facing scripts. This will be used later by pip to install python code.
Signed-off-by Jan Stancek <[email protected]>
The ynl-ethtool script is broken when installed because it hard-codes spec and schema paths to in-tree locations. I'd be happy to fix that in a followup patch, since I have a schema lookup patch in progress.
Quoted 35 lines
--- tools/net/ynl/pyproject.toml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/net/ynl/pyproject.tomltools/net/ynl/pyproject.toml new file +24
-0@@ -0,0 +1,24 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "pyynl" +authors = [ + {name = "Donald Hunter", email = "[email protected]"}, + {name = "Jakub Kicinski", email = "[email protected]"}, +] +description = "yaml netlink (ynl)" +version = "0.0.1" +requires-python = ">=3.9" +dependencies = [ + "pyyaml==6.*", + "jsonschema==4.*" +] + +[tool.setuptools.packages.find] +include = ["pyynl", "pyynl.lib"] + +[project.scripts] +ynl = "pyynl.cli:main" +ynl-ethtool = "pyynl.ethtool:main"
Re: [PATCH v4 3/4] tools: ynl: add install target for generated content
In reply to Jan StancekQuoted 6 lines · Jan Stancek
Generate docs using
ynl_gen_rstand add install target for headers, specs and generates rst files.Factor out
SPECS_DIRsince it's repeated many times.Signed-off-by Jan Stancek <[email protected]>
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 8 Jan 2025 14:56:13 +0100 you wrote:
This series adds an install target for ynl. The python code is moved to a subdirectory, so it can be used as a package with flat layout, as well as directly from the tree.
To try the install as a non-root user you can run:
$ mkdir /tmp/myroot $ make DESTDIR=/tmp/myroot install[...]
Here is the summary with links:
- [v4,1/4] tools: ynl: move python code to separate sub-directory
https://git.kernel.org/netdev/net-next/c/ab88c2b3739a - [v4,2/4] tools: ynl: add initial pyproject.toml for packaging https://git.kernel.org/netdev/net-next/c/a12afefa2eab - [v4,3/4] tools: ynl: add install target for generated content https://git.kernel.org/netdev/net-next/c/1b038af9f752 - [v4,4/4] tools: ynl: add main install target https://git.kernel.org/netdev/net-next/c/e5ad1d98234a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html