11load ("@aspect_rules_py//py:defs.bzl" , "py_library" )
22load ("@bazel_skylib//rules:build_test.bzl" , "build_test" )
33load ("@cmk_requirements//:requirements.bzl" , "requirement" )
4+ load ("@rules_pkg//pkg:mappings.bzl" , "pkg_attributes" , "pkg_files" )
45load ("@rules_python//python:packaging.bzl" , "py_wheel" )
56load ("//bazel/rules:doctest.bzl" , "py_doc_test" )
7+ load ("//bazel/rules:file_from_flag.bzl" , "file_from_flag" )
68load ("//bazel/rules:package_wheel.bzl" , "package_wheel" )
79load ("//bazel/rules:py_cmk_test.bzl" , "py_cmk_test" )
810load ("//bazel/rules:py_requirements_test.bzl" , "py_requirements_test" )
11+ load ("//bazel/rules:replace_string_in_file.bzl" , "replace_string_in_file" )
912
1013exports_files ([
1114 "dev-requirements.in" ,
@@ -90,16 +93,39 @@ py_library(
9093 ],
9194)
9295
93- # Keep __main__.py in a separate target to avoid mypy errors on the standalone package.
96+ # The livedump command line tool. Not part of the cmk.livestatus_client
97+ # library or its wheel; it is shipped as bin/livedump via the package tar.
9498py_library (
95- name = "cmk-livestatus-client-main " ,
96- srcs = ["cmk/livestatus_client/__main__ .py" ],
99+ name = "livedump " ,
100+ srcs = ["livedump .py" ],
97101 imports = ["." ],
98- tags = ["no-mypy" ],
99- visibility = ["//cmk:__pkg__" ],
100102 deps = [":cmk-livestatus-client" ],
101103)
102104
105+ # Stamp the shipped livedump with the actual version, like bin/omd does.
106+ replace_string_in_file (
107+ name = "livedump_version_in" ,
108+ src = "livedump.py" ,
109+ out = "livedump_in.py" ,
110+ replace_dict = {'__version__ = "UNSET"' : '__version__ = "{CMK_VERSION}"' },
111+ )
112+
113+ file_from_flag (
114+ name = "livedump_versioned" ,
115+ src = "livedump_version_in" ,
116+ out = "livedump_bin.py" ,
117+ replace_labels = {"CMK_VERSION" : "@cmk//version" },
118+ )
119+
120+ pkg_files (
121+ name = "livedump_bin" ,
122+ srcs = [":livedump_versioned" ],
123+ attributes = pkg_attributes (
124+ mode = "0755" ,
125+ ),
126+ renames = {"livedump_bin.py" : "bin/livedump" },
127+ )
128+
103129py_doc_test (
104130 name = "doctest" ,
105131 size = "small" ,
@@ -125,7 +151,6 @@ py_wheel(
125151 visibility = ["//visibility:public" ],
126152 deps = [
127153 ":cmk-livestatus-client" ,
128- ":cmk-livestatus-client-main" ,
129154 ":cmk_livestatus_client_py_typed" ,
130155 ":livestatus-api" ,
131156 ":livestatus-connection" ,
@@ -162,6 +187,7 @@ filegroup(
162187
163188package_wheel (
164189 name = "cmk_livestatus_client_pkg_tar" ,
190+ additional_files = [":livedump_bin" ],
165191 visibility = ["//visibility:public" ],
166192 whl = "cmk-livestatus-client_whl" ,
167193)
@@ -185,6 +211,7 @@ py_requirements_test(
185211 libs = [
186212 ":cmk-livestatus-client" ,
187213 ":examples" ,
214+ ":livedump" ,
188215 ],
189216 requirements_in = "requirements.in" ,
190217)
0 commit comments