aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-08-17 17:28:00 +0300
committeraqua <aqua@iserlohn-fortress.net>2024-08-17 17:28:00 +0300
commit4f95c7062448c569830f4e2819adc1190efbfc55 (patch)
treefb68a30b3669793af4d57ca56d141d97f99a4e30 /tools
parentAdded bazel rule for interface_generator (diff)
downloadkernel-4f95c7062448c569830f4e2819adc1190efbfc55.tar.xz
interface_generator: added pytest wrapper
Diffstat (limited to 'tools')
-rw-r--r--tools/interface_generator/BUILD.bazel35
-rw-r--r--tools/interface_generator/defs.bzl22
-rw-r--r--tools/interface_generator/interface_definition.py1
-rwxr-xr-xtools/interface_generator/interface_generator.py4
-rwxr-xr-xtools/interface_generator/pytest_wrapper.py7
-rw-r--r--tools/interface_generator/requirements.txt5
-rw-r--r--tools/interface_generator/requirements_lock.txt120
-rw-r--r--tools/interface_generator/templates.py3
-rw-r--r--tools/interface_generator/test/BUILD.bazel4
9 files changed, 183 insertions, 18 deletions
diff --git a/tools/interface_generator/BUILD.bazel b/tools/interface_generator/BUILD.bazel
index c6f4a79..15fbb5d 100644
--- a/tools/interface_generator/BUILD.bazel
+++ b/tools/interface_generator/BUILD.bazel
@@ -1,6 +1,6 @@
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
-load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
-load(":defs.bzl", "generate_interface")
+load("@pip//:requirements.bzl", "requirement")
+load(":defs.bzl", "generate_interface", "py_pytest")
package(default_visibility = ["//visibility:public"])
@@ -11,12 +11,6 @@ compile_pip_requirements(
requirements_txt = "requirements_lock.txt",
)
-py_console_script_binary(
- name = "pylint",
- pkg = "@pip//pylint",
- script = "pylint",
-)
-
py_binary(
name = "interface_generator",
srcs = [
@@ -24,18 +18,33 @@ py_binary(
"interface_generator.py",
"templates.py",
],
- data = glob(["templates/*"]),
+ data = glob(["templates/*"]) + ["LICENSE.md"],
main = "interface_generator.py",
- deps = [
- "@pip//mako",
- ],
+ deps = ["@pip//mako"],
)
+# interface generator python tests
py_test(
name = "templates_unittest",
- srcs = ["templates_unittest.py", "templates.py"],
+ srcs = [
+ "templates.py",
+ "templates_unittest.py",
+ ],
data = glob(["templates/*"]),
deps = ["@pip//mako"],
)
+py_pytest(
+ name = "pytest",
+ srcs = [
+ "interface_definition.py",
+ "interface_generator.py",
+ "templates.py",
+ ],
+ deps = [
+ requirement("mako"),
+ ],
+)
+
+# make license available to test package
exports_files(["LICENSE.md"])
diff --git a/tools/interface_generator/defs.bzl b/tools/interface_generator/defs.bzl
index d5c6f91..6f02b1f 100644
--- a/tools/interface_generator/defs.bzl
+++ b/tools/interface_generator/defs.bzl
@@ -1,3 +1,5 @@
+load("@pip//:requirements.bzl", "requirement")
+
def _generate_interface_impl(ctx):
out_hdrs = [
ctx.actions.declare_file(ctx.attr.interface + ".h"),
@@ -51,3 +53,23 @@ def generate_interface(name, interface, license, visibility = None):
license = license,
visibility = visibility,
)
+
+def py_pytest(name, srcs, deps = [], **kwargs):
+ native.py_test(
+ name = name,
+ srcs = ["//:pytest_wrapper.py"],
+ main = "//:pytest_wrapper.py",
+ data = srcs,
+ args = [
+ "--black",
+ "--pylint",
+ #"--mypy",
+ ] + ["$(location :%s)" % x for x in srcs],
+ deps = [
+ requirement("pytest"),
+ requirement("pytest-black"),
+ requirement("pytest-pylint"),
+ requirement("pytest-mypy"),
+ ] + deps,
+ **kwargs
+ )
diff --git a/tools/interface_generator/interface_definition.py b/tools/interface_generator/interface_definition.py
index 10d1f60..3b9c4a3 100644
--- a/tools/interface_generator/interface_definition.py
+++ b/tools/interface_generator/interface_definition.py
@@ -2,6 +2,7 @@
interface_definition.py
"""
+
def __read_license(path):
"""read and starrify a license"""
license_text = ""
diff --git a/tools/interface_generator/interface_generator.py b/tools/interface_generator/interface_generator.py
index 4d3afa4..0693897 100755
--- a/tools/interface_generator/interface_generator.py
+++ b/tools/interface_generator/interface_generator.py
@@ -28,7 +28,7 @@ def generate_file(template: Path, templates: Path, output, kwargs):
if isinstance(output, Path):
# print(f"writing to {(output / output_name).absolute()}")
- with open(output / output_name, "w") as output_file:
+ with open(output / output_name, "w", encoding="utf-8") as output_file:
print(result, file=output_file)
else:
print(result, file=output)
@@ -38,7 +38,7 @@ def main():
"""main function"""
parser = ArgumentParser(
prog="interface_generator",
- description="Generate a C header file from an interface definition",
+ description="Generate C header and mock files from an interface definition",
)
parser.add_argument(
"-i",
diff --git a/tools/interface_generator/pytest_wrapper.py b/tools/interface_generator/pytest_wrapper.py
new file mode 100755
index 0000000..b4def3b
--- /dev/null
+++ b/tools/interface_generator/pytest_wrapper.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys
+import pytest
+
+if __name__ == "__main__":
+ sys.exit(pytest.main(sys.argv[1:]))
diff --git a/tools/interface_generator/requirements.txt b/tools/interface_generator/requirements.txt
index ad75266..c285e04 100644
--- a/tools/interface_generator/requirements.txt
+++ b/tools/interface_generator/requirements.txt
@@ -1,3 +1,6 @@
Mako==1.3.3
MarkupSafe==2.1.5
-pylint
+pytest==8.3.2
+pytest-black==0.3.12
+pytest-pylint==0.21.0
+pytest-mypy==0.10.3
diff --git a/tools/interface_generator/requirements_lock.txt b/tools/interface_generator/requirements_lock.txt
index e502874..62c9eb4 100644
--- a/tools/interface_generator/requirements_lock.txt
+++ b/tools/interface_generator/requirements_lock.txt
@@ -8,10 +8,50 @@ astroid==3.2.4 \
--hash=sha256:0e14202810b30da1b735827f78f5157be2bbd4a7a59b7707ca0bfc2fb4c0063a \
--hash=sha256:413658a61eeca6202a59231abb473f932038fbcbf1666587f66d482083413a25
# via pylint
+attrs==24.2.0 \
+ --hash=sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346 \
+ --hash=sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2
+ # via pytest-mypy
+black==24.8.0 \
+ --hash=sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6 \
+ --hash=sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e \
+ --hash=sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f \
+ --hash=sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018 \
+ --hash=sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e \
+ --hash=sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd \
+ --hash=sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4 \
+ --hash=sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed \
+ --hash=sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2 \
+ --hash=sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42 \
+ --hash=sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af \
+ --hash=sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb \
+ --hash=sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368 \
+ --hash=sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb \
+ --hash=sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af \
+ --hash=sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed \
+ --hash=sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47 \
+ --hash=sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2 \
+ --hash=sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a \
+ --hash=sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c \
+ --hash=sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920 \
+ --hash=sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1
+ # via pytest-black
+click==8.1.7 \
+ --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
+ --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
+ # via black
dill==0.3.8 \
--hash=sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca \
--hash=sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7
# via pylint
+filelock==3.15.4 \
+ --hash=sha256:2207938cbc1844345cb01a5a95524dae30f0ce089eba5b00378295a17e3e90cb \
+ --hash=sha256:6ca1fffae96225dab4c6eaf1c4f4f28cd2568d3ec2a44e15a08520504de468e7
+ # via pytest-mypy
+iniconfig==2.0.0 \
+ --hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
+ --hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
+ # via pytest
isort==5.13.2 \
--hash=sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109 \
--hash=sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6
@@ -88,15 +128,93 @@ mccabe==0.7.0 \
--hash=sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325 \
--hash=sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e
# via pylint
+mypy==1.11.1 \
+ --hash=sha256:0624bdb940255d2dd24e829d99a13cfeb72e4e9031f9492148f410ed30bcab54 \
+ --hash=sha256:0bc71d1fb27a428139dd78621953effe0d208aed9857cb08d002280b0422003a \
+ --hash=sha256:0bd53faf56de9643336aeea1c925012837432b5faf1701ccca7fde70166ccf72 \
+ --hash=sha256:11965c2f571ded6239977b14deebd3f4c3abd9a92398712d6da3a772974fad69 \
+ --hash=sha256:1a81cf05975fd61aec5ae16501a091cfb9f605dc3e3c878c0da32f250b74760b \
+ --hash=sha256:2684d3f693073ab89d76da8e3921883019ea8a3ec20fa5d8ecca6a2db4c54bbe \
+ --hash=sha256:2c63350af88f43a66d3dfeeeb8d77af34a4f07d760b9eb3a8697f0386c7590b4 \
+ --hash=sha256:45df906e8b6804ef4b666af29a87ad9f5921aad091c79cc38e12198e220beabd \
+ --hash=sha256:4c956b49c5d865394d62941b109728c5c596a415e9c5b2be663dd26a1ff07bc0 \
+ --hash=sha256:64f4a90e3ea07f590c5bcf9029035cf0efeae5ba8be511a8caada1a4893f5525 \
+ --hash=sha256:749fd3213916f1751fff995fccf20c6195cae941dc968f3aaadf9bb4e430e5a2 \
+ --hash=sha256:79c07eb282cb457473add5052b63925e5cc97dfab9812ee65a7c7ab5e3cb551c \
+ --hash=sha256:7b6343d338390bb946d449677726edf60102a1c96079b4f002dedff375953fc5 \
+ --hash=sha256:886c9dbecc87b9516eff294541bf7f3655722bf22bb898ee06985cd7269898de \
+ --hash=sha256:a2b43895a0f8154df6519706d9bca8280cda52d3d9d1514b2d9c3e26792a0b74 \
+ --hash=sha256:a32fc80b63de4b5b3e65f4be82b4cfa362a46702672aa6a0f443b4689af7008c \
+ --hash=sha256:a707ec1527ffcdd1c784d0924bf5cb15cd7f22683b919668a04d2b9c34549d2e \
+ --hash=sha256:a831671bad47186603872a3abc19634f3011d7f83b083762c942442d51c58d58 \
+ --hash=sha256:b639dce63a0b19085213ec5fdd8cffd1d81988f47a2dec7100e93564f3e8fb3b \
+ --hash=sha256:b868d3bcff720dd7217c383474008ddabaf048fad8d78ed948bb4b624870a417 \
+ --hash=sha256:c1952f5ea8a5a959b05ed5f16452fddadbaae48b5d39235ab4c3fc444d5fd411 \
+ --hash=sha256:d44be7551689d9d47b7abc27c71257adfdb53f03880841a5db15ddb22dc63edb \
+ --hash=sha256:e1e30dc3bfa4e157e53c1d17a0dad20f89dc433393e7702b813c10e200843b03 \
+ --hash=sha256:e4fe9f4e5e521b458d8feb52547f4bade7ef8c93238dfb5bbc790d9ff2d770ca \
+ --hash=sha256:f39918a50f74dc5969807dcfaecafa804fa7f90c9d60506835036cc1bc891dc8 \
+ --hash=sha256:f404a0b069709f18bbdb702eb3dcfe51910602995de00bd39cea3050b5772d08 \
+ --hash=sha256:fca4a60e1dd9fd0193ae0067eaeeb962f2d79e0d9f0f66223a0682f26ffcc809
+ # via pytest-mypy
+mypy-extensions==1.0.0 \
+ --hash=sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d \
+ --hash=sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782
+ # via
+ # black
+ # mypy
+packaging==24.1 \
+ --hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \
+ --hash=sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124
+ # via
+ # black
+ # pytest
+pathspec==0.12.1 \
+ --hash=sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08 \
+ --hash=sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712
+ # via black
platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
- # via pylint
+ # via
+ # black
+ # pylint
+pluggy==1.5.0 \
+ --hash=sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 \
+ --hash=sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669
+ # via pytest
pylint==3.2.6 \
--hash=sha256:03c8e3baa1d9fb995b12c1dbe00aa6c4bcef210c2a2634374aedeb22fb4a8f8f \
--hash=sha256:a5d01678349454806cff6d886fb072294f56a58c4761278c97fb557d708e1eb3
+ # via pytest-pylint
+pytest==8.3.2 \
+ --hash=sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5 \
+ --hash=sha256:c132345d12ce551242c87269de812483f5bcc87cdbb4722e48487ba194f9fdce
+ # via
+ # -r requirements.txt
+ # pytest-black
+ # pytest-mypy
+ # pytest-pylint
+pytest-black==0.3.12 \
+ --hash=sha256:1d339b004f764d6cd0f06e690f6dd748df3d62e6fe1a692d6a5500ac2c5b75a5
+ # via -r requirements.txt
+pytest-mypy==0.10.3 \
+ --hash=sha256:7638d0d3906848fc1810cb2f5cc7fceb4cc5c98524aafcac58f28620e3102053 \
+ --hash=sha256:f8458f642323f13a2ca3e2e61509f7767966b527b4d8adccd5032c3e7b4fd3db
+ # via -r requirements.txt
+pytest-pylint==0.21.0 \
+ --hash=sha256:88764b8e1d5cfa18809248e0ccc2fc05035f08c35f0b0222ddcfea1c3c4e553e \
+ --hash=sha256:f10d9eaa72b9fbe624ee4b55da0481f56482eee0a467afc1ee3ae8b1fefbd0b4
# via -r requirements.txt
+toml==0.10.2 \
+ --hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \
+ --hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f
+ # via pytest-black
tomlkit==0.13.0 \
--hash=sha256:08ad192699734149f5b97b45f1f18dad7eb1b6d16bc72ad0c2335772650d7b72 \
--hash=sha256:7075d3042d03b80f603482d69bf0c8f345c2b30e41699fd8883227f89972b264
# via pylint
+typing-extensions==4.12.2 \
+ --hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
+ --hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8
+ # via mypy
diff --git a/tools/interface_generator/templates.py b/tools/interface_generator/templates.py
index ecf925d..d6a6bb5 100644
--- a/tools/interface_generator/templates.py
+++ b/tools/interface_generator/templates.py
@@ -1,8 +1,11 @@
+"""template helper functions"""
+
from pathlib import Path
import re
def get_templates(path: Path):
+ """list templates in given path"""
template_pattern = re.compile(r"^[^_]\S+\.mako$")
result = list(path.glob("*.mako"))
result = [item for item in result if template_pattern.match(item.name)]
diff --git a/tools/interface_generator/test/BUILD.bazel b/tools/interface_generator/test/BUILD.bazel
index 5d6348d..6c0602a 100644
--- a/tools/interface_generator/test/BUILD.bazel
+++ b/tools/interface_generator/test/BUILD.bazel
@@ -4,14 +4,16 @@ generate_interface(
name = "kstdio",
interface = "kstdio",
license = "//:LICENSE.md",
+ visibility = ["//visibility:private"],
)
cc_test(
name = "test_kstdio",
- srcs = ["kstdio_mock.cpp", "test_kstdio.cpp"],
+ srcs = [":kstdio", "test_kstdio.cpp"],
deps = [
":kstdio",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
+ visibility = ["//visibility:private"],
)