]> www.infradead.org Git - users/hch/misc.git/commitdiff
tools: ynl: move python code to separate sub-directory
authorJan Stancek <jstancek@redhat.com>
Wed, 8 Jan 2025 13:56:14 +0000 (14:56 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 9 Jan 2025 20:53:27 +0000 (12:53 -0800)
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.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/a4151bad0e6984e7164d395125ce87fd2e048bf1.1736343575.git.jstancek@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
21 files changed:
Documentation/Makefile
Documentation/networking/multi-pf-netdev.rst
Documentation/networking/napi.rst
Documentation/networking/netlink_spec/readme.txt
Documentation/userspace-api/netlink/intro-specs.rst
tools/net/ynl/Makefile
tools/net/ynl/generated/Makefile
tools/net/ynl/lib/.gitignore
tools/net/ynl/lib/Makefile
tools/net/ynl/pyynl/.gitignore [new file with mode: 0644]
tools/net/ynl/pyynl/__init__.py [new file with mode: 0644]
tools/net/ynl/pyynl/cli.py [moved from tools/net/ynl/cli.py with 100% similarity]
tools/net/ynl/pyynl/ethtool.py [moved from tools/net/ynl/ethtool.py with 100% similarity]
tools/net/ynl/pyynl/lib/__init__.py [moved from tools/net/ynl/lib/__init__.py with 100% similarity]
tools/net/ynl/pyynl/lib/nlspec.py [moved from tools/net/ynl/lib/nlspec.py with 100% similarity]
tools/net/ynl/pyynl/lib/ynl.py [moved from tools/net/ynl/lib/ynl.py with 100% similarity]
tools/net/ynl/pyynl/ynl_gen_c.py [moved from tools/net/ynl/ynl-gen-c.py with 100% similarity]
tools/net/ynl/pyynl/ynl_gen_rst.py [moved from tools/net/ynl/ynl-gen-rst.py with 100% similarity]
tools/net/ynl/ynl-regen.sh
tools/testing/selftests/net/lib/py/ynl.py
tools/testing/selftests/net/ynl.mk

index fa71602ec961620a30c28a8b66ff29c18056c591..52c6c5a3efa99d43a496cc09e4430e1e023f8c87 100644 (file)
@@ -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))
index 2cd25d81aaa7a0a14de598ef2581d1adca459be8..2f5a5bb3ca9a06e55572f194901b23e1128e4144 100644 (file)
@@ -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},
index 02720dd71a769b80e725a14a6ce1eefeac02a525..6083210ab2a42ce26e47731c9e2fa92e015321ee 100644 (file)
@@ -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,
index 6763f99d216c1361827978edf1a184e78170254e..030b44aca4e6199aeeb1429334c8975a997fe92c 100644 (file)
@@ -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.
index bada89699455c84d0cceed988389578c96cfded9..a4435ae4628d4589882525932be4aece7b6f4e37 100644 (file)
@@ -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
 ----------
index d1cdf2a8f8266fbe5034efa5c0f08111c177992d..5268b91bf7ed0a9a23a6bddbcc7bd1e79979c27f 100644 (file)
@@ -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)
index 7db5240de58a2db0c79c4dca7bfb946ab9d43b47..00af721b1571baf589e9f8b738443c0fd8dea583 100644 (file)
@@ -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' \
index 296c4035dbf28c2153fdd99378920a49f6580b2f..a4383358ec72fb4d15f30791cb5265a6e06c5416 100644 (file)
@@ -1,2 +1 @@
-__pycache__/
 *.d
index 94c49cca3dca57283b6cccd8b8ca37c1694bb94b..4b2b98704ff9ba78718dec7080548a837a7448de 100644 (file)
@@ -19,7 +19,6 @@ ynl.a: $(OBJS)
 
 clean:
        rm -f *.o *.d *~
-       rm -rf __pycache__
 
 distclean: clean
        rm -f *.a
diff --git a/tools/net/ynl/pyynl/.gitignore b/tools/net/ynl/pyynl/.gitignore
new file mode 100644 (file)
index 0000000..b801cd2
--- /dev/null
@@ -0,0 +1,2 @@
+__pycache__/
+lib/__pycache__/
diff --git a/tools/net/ynl/pyynl/__init__.py b/tools/net/ynl/pyynl/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index a37304dcc88e1a83e21b95a0d6b158363c918355..81b4ecd891006853077d0f389cfb093c34ce9b5e 100755 (executable)
@@ -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=
index 076a7e8dc3ebe4810677fc1f01e791fdcd7b8e35..ad1e36baee2a165104e1181c40d25cb731ea7e5e 100644 (file)
@@ -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))
index d43afe243779712290bffe71ee2424c2bf820b05..12e7cae251be34ace887d7473974f28f2e8e2909 100644 (file)
@@ -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