Skip to content

Commit 4cdbfc3

Browse files
committed
Reapply "livedump: move out of cmk.livestatus_client.__main__"
This reverts commit 7e7faef. Now with fixed and bazel native version replacement. Change-Id: Ia1632a295f29a30e9564ec5973ca6ad062b1590b
1 parent 61ed97a commit 4cdbfc3

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ setversion:
106106
# IMPORTANT do not version bazelized packages here. Bazel can set the
107107
# version natively.
108108
sed -ri 's/^(VERSION[[:space:]]*:?= *).*/\1'"$(NEW_VERSION)/" defines.make
109-
sed -i 's/^__version__ = ".*"$$/__version__ = "$(NEW_VERSION)"/' packages/cmk-ccc/cmk/ccc/version.py bin/livedump
109+
sed -i 's/^__version__ = ".*"$$/__version__ = "$(NEW_VERSION)"/' packages/cmk-ccc/cmk/ccc/version.py
110110
$(MAKE) -C agents NEW_VERSION=$(NEW_VERSION) setversion
111111
sed -i 's/^ARG CMK_VERSION=.*$$/ARG CMK_VERSION="$(NEW_VERSION)"/g' docker_image/Dockerfile
112112
ifneq ($(EDITION),community)

bin/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pkg_files(
8181
":cmk-validate-config.py",
8282
":cmk-validate-plugins.py",
8383
":init-redis.py",
84-
":livedump",
8584
":message-broker-certs",
8685
":mkevent",
8786
":mkp.py",

bin/livedump

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/cmk-livestatus-client/BUILD

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
load("@aspect_rules_py//py:defs.bzl", "py_library")
22
load("@bazel_skylib//rules:build_test.bzl", "build_test")
33
load("@cmk_requirements//:requirements.bzl", "requirement")
4+
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
45
load("@rules_python//python:packaging.bzl", "py_wheel")
56
load("//bazel/rules:doctest.bzl", "py_doc_test")
7+
load("//bazel/rules:file_from_flag.bzl", "file_from_flag")
68
load("//bazel/rules:package_wheel.bzl", "package_wheel")
79
load("//bazel/rules:py_cmk_test.bzl", "py_cmk_test")
810
load("//bazel/rules:py_requirements_test.bzl", "py_requirements_test")
11+
load("//bazel/rules:replace_string_in_file.bzl", "replace_string_in_file")
912

1013
exports_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.
9498
py_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+
103129
py_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

163188
package_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
)

packages/cmk-livestatus-client/cmk/livestatus_client/__main__.py renamed to packages/cmk-livestatus-client/livedump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
from cmk.livestatus_client import SingleSiteConnection
1717

18-
# This will be substituted at 'make dist' time.
19-
__version__ = "3.0.0b1"
18+
# Substituted with the actual version at build time, see :livedump_versioned.
19+
__version__ = "UNSET"
2020

2121

2222
@dataclass(slots=True)

0 commit comments

Comments
 (0)