Skip to content

Commit 8393b4e

Browse files
lpetroraJenkins
authored andcommitted
add matplotlib dependency
CMK-35581 Change-Id: Ib8866d5f598a1e1ef6a25e2bfa9ae2bf4f645995
1 parent 437ca1d commit 8393b4e

13 files changed

Lines changed: 485 additions & 1 deletion

File tree

MODULE.bazel

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,45 @@ local_path_override(
236236
# TODO: Duplicate from bazel_variables.bzl. won't be needed anymore when all omd packages are loaded via MODULE.bazel
237237
UPSTREAM_MIRROR_URL = "https://artifacts.lan.tribe29.com/repository/upstream-archives/"
238238

239+
# matplotlib's meson build vendors harfbuzz/sheenbidi/libraqm as subprojects
240+
# (system-libraqm can't be used: it needs libraqm>=0.10.4, newer than what our
241+
# build images provide). Fetch the exact pinned wrap sources here so meson can
242+
# pick them up from a local MESON_PACKAGE_CACHE_DIR instead of downloading them
243+
# itself at build time -- see omd/packages/python3-modules/build-python3-modules.bzl.
244+
http_file(
245+
name = "matplotlib_harfbuzz_src",
246+
downloaded_file_path = "harfbuzz-14.1.0.tar.xz",
247+
sha256 = "ee0eb3a1da2c5a28147f12dff55f6c7d60aeeeb29ac7ef334eabe84c8476c105",
248+
urls = [
249+
"https://github.com/harfbuzz/harfbuzz/releases/download/14.1.0/harfbuzz-14.1.0.tar.xz",
250+
"https://github.com/mesonbuild/wrapdb/releases/download/harfbuzz_14.1.0-1/harfbuzz-14.1.0.tar.xz",
251+
],
252+
)
253+
254+
http_file(
255+
name = "matplotlib_sheenbidi_src",
256+
downloaded_file_path = "sheenbidi-3.0.0.tar.gz",
257+
sha256 = "86c56014034739ba39a24c23eb00323b0bf6f737354f665786015fca842af786",
258+
url = "https://github.com/Tehreer/SheenBidi/archive/refs/tags/v3.0.0/sheenbidi-3.0.0.tar.gz",
259+
)
260+
261+
http_file(
262+
name = "matplotlib_libraqm_src",
263+
downloaded_file_path = "libraqm-0.10.5.tar.gz",
264+
sha256 = "7f3dd21b4b3bd28a36f2c911d31d91a9d69341697713923ef1aac65d56ebcafd",
265+
url = "https://github.com/HOST-Oman/libraqm/archive/v0.10.5/libraqm-0.10.5.tar.gz",
266+
)
267+
268+
# qhull is also vendored (system-qhull is NOT set): our build images don't
269+
# provide a usable libqhull_r (pkg-config/cmake can't find it), so meson would
270+
# otherwise fall back to downloading this subproject itself at build time.
271+
http_file(
272+
name = "matplotlib_qhull_src",
273+
downloaded_file_path = "qhull-8.0.2.tgz",
274+
sha256 = "8774e9a12c70b0180b95d6b0b563c5aa4bea8d5960c15e18ae3b6d2521d64f8b",
275+
url = "https://github.com/qhull/qhull/archive/v8.0.2/qhull-8.0.2.tar.gz",
276+
)
277+
239278
# Artifacts built and published by our own CI jobs, laid out like so:
240279
# <publisher>/<name>/<version>/<platform>/<arch>/<variant>/<file>
241280
CI_ARTIFACTS_URL = "https://ci-binary-artifacts-710145618630-eu-central-1-an.s3.eu-central-1.amazonaws.com/dl/"

cmk/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ py_requirements_test(
221221
"setuptools-scm",
222222
"pysmi", # used outside of cmk/ in omd/packages/net-snmp/compile_mibs.py
223223
"openapi-spec-validator", # only imported by tests
224+
"matplotlib", # CMK-35581: wired up ahead of the actual usage landing
224225
],
225226
libs = [
226227
# cloud and ultimatemt each transitively pull in ultimate -> pro -> community,

cmk/gui/graphing/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ py_library(
3939
"//packages/cmk-shared-typing:cmk_shared_typing_py",
4040
requirement("python-dateutil"),
4141
requirement("tzlocal"),
42+
requirement("matplotlib"),
4243
],
4344
)
4445

cmk/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jira
1414
lxml
1515
marshmallow
1616
marshmallow-oneofschema
17+
matplotlib
1718
meraki
1819
msal
1920
numpy

community-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,7 @@ matplotlib==3.11.1 \
28572857
--hash=sha256:f2912f647f3fbe1ccf085f91e213936f9101bead81a5e670565b1f1b3712f4fb
28582858
# via
28592859
# -c requirements.txt
2860+
# -r cmk/requirements.in
28602861
# -r tests/dev-requirements.in
28612862
# sarif-tools
28622863
mdit-py-plugins==0.6.1 \

omd/dependency_management/automatically_researched_licenses.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,7 @@
20362036
"pkg:pypi/feedparser@6.0.12": "BSD-2-Clause",
20372037
"pkg:pypi/flask@3.1.2": "BSD-3-Clause",
20382038
"pkg:pypi/flask@3.1.3": "BSD-3-Clause",
2039+
"pkg:pypi/fonttools@4.63.0": "MIT",
20392040
"pkg:pypi/frozenlist@1.8.0": "Apache-2.0",
20402041
"pkg:pypi/genson@1.3.0": "MIT",
20412042
"pkg:pypi/genson@1.4.0": "MIT",

omd/dependency_management/manually_researched_licenses.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"pkg:pypi/chardet@5.2.0": "LGPL-2.1-or-later",
6060
"pkg:pypi/clickhouse-connect@0.15.1": "Apache-2.0",
6161
"pkg:pypi/colorama@0.4.6": "BSD-3-Clause",
62+
"pkg:pypi/contourpy@1.3.3": "BSD-3-Clause",
63+
"pkg:pypi/cycler@0.12.1": "BSD-3-Clause",
6264
"pkg:pypi/defusedxml@0.7.1": "PSF-2.0",
6365
"pkg:pypi/fido2@2.2.1": "BSD-2-Clause AND MPL-2.0 AND Apache-2.0",
6466
"pkg:pypi/gitdb@4.0.12": "BSD-3-Clause",
@@ -73,12 +75,14 @@
7375
"pkg:pypi/jira@3.10.5": "BSD-2-Clause",
7476
"pkg:pypi/jsonpatch@1.33": "BSD-3-Clause",
7577
"pkg:pypi/jsonpointer@3.1.1": "BSD-3-Clause",
78+
"pkg:pypi/kiwisolver@1.5.0": "BSD-3-Clause",
7679
"pkg:pypi/kubernetes@35.0.0": "Apache-2.0",
7780
"pkg:pypi/libcst@1.9.0": "MIT AND PSF-2.0",
7881
"pkg:pypi/lz4@4.4.5": "BSD-3-Clause",
7982
"pkg:pypi/markdown-it-py@4.2.0": "MIT",
8083
"pkg:pypi/marshmallow-oneofschema@3.2.0": "MIT",
8184
"pkg:pypi/marshmallow@3.26.2": "MIT",
85+
"pkg:pypi/matplotlib@3.11.1": "PSF-2.0",
8286
"pkg:pypi/mdurl@0.1.2": "MIT",
8387
"pkg:pypi/multidict@6.7.1": "Apache-2.0",
8488
"pkg:pypi/mypy-extensions@1.1.0": "MIT",

omd/packages/python3-modules/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@ config_setting(
1616
],
1717
) for module in all_requirements]
1818

19+
# Extra Bazel-fetched srcs some modules need on top of the common set below, e.g.
20+
# offline meson subproject sources seeded by get_extra_setup() in
21+
# build-python3-modules.bzl.
22+
_EXTRA_MODULE_SRCS = {
23+
"matplotlib": [
24+
"@matplotlib_harfbuzz_src//file",
25+
"@matplotlib_sheenbidi_src//file",
26+
"@matplotlib_libraqm_src//file",
27+
"@matplotlib_qhull_src//file",
28+
],
29+
}
30+
1931
# Third Party packages parsed from runtime-requirements.txt
2032
[build_python_module(
2133
name = module,
34+
# @python must stay last: the genrule's EXT_DEPS_PATH extraction (see
35+
# build-python3-modules.bzl) greedily matches up to the last "external" src
36+
# in $(SRCS), so any extra external srcs must be inserted before it.
2237
srcs = [
2338
"%s_requirements.txt" % module,
2439
":git_wrapper",
2540
"//:constraints.txt",
41+
] + _EXTRA_MODULE_SRCS.get(module, []) + [
2642
"@freetds",
2743
"@openssl",
2844
"@python",

omd/packages/python3-modules/build-python3-modules.bzl

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,51 @@ load("//omd/packages/Python:version.bzl", "PYTHON_MAJOR_DOT_MINOR")
55

66
def get_pip_options(module_name):
77
return {
8+
# matplotlib's meson build defaults to downloading and building its own vendored
9+
# freetype as a subproject, which requires network access at build time.
10+
# Use the system library instead, which is already provided by the build image.
11+
# qhull and libraqm are left vendored (system-qhull/system-libraqm are NOT
12+
# set): our build images don't provide a usable libqhull_r, and ship
13+
# libraqm 0.10.1, older than the >=0.10.4 matplotlib requires. Their sources
14+
# (and harfbuzz/sheenbidi) are instead seeded offline, see get_extra_setup().
15+
"matplotlib": '--config-settings=setup-args="-Dsystem-freetype=true"',
16+
817
# * avoid compiling with BLAS support - we don't need super fast numpy (yet)
918
"numpy": '--config-settings=setup-args="-Dallow-noblas=true"',
1019
# pillow in version 11.2 and above would require libavif>=1.0.0 which is per default not available on debian-12, see https://github.com/radarhere/Pillow/commit/7d50816f0a6e607b04f9bdc8af7482a29ba578e3 and as we don't need avif support, we simply disable it
1120
"pillow": "--config-settings=avif=disable",
1221
}.get(module_name, "")
1322

23+
def get_extra_setup(module_name):
24+
"""Shell snippet executed right before `pip install`.
25+
26+
Used to seed a local meson subproject package cache (MESON_PACKAGE_CACHE_DIR)
27+
so meson resolves vendored C deps from disk instead of downloading them at
28+
build time. The Bazel-fetched srcs referenced here must be added to that
29+
module's `srcs` in the calling BUILD file.
30+
"""
31+
return {
32+
"matplotlib": """
33+
# meson runs harfbuzz's gen-hb-version.py through its
34+
# "#!/usr/bin/env python3" shebang. LD_LIBRARY_PATH (see build_cmd) puts
35+
# our bundled Python's lib dir first, so a system python3 that links
36+
# libpython dynamically -- sles-16.0 does, with a colliding 3.13 soname --
37+
# loads the wrong libpython and aborts before running the script. Resolve
38+
# python3 to the interpreter LD_LIBRARY_PATH already matches.
39+
export PATH="$$(dirname "$$PYTHON_EXECUTABLE"):$$PATH"
40+
# Build in a private, guaranteed-writable/empty TMPDIR instead of the shared
41+
# host /tmp: pip/meson-python stage the harfbuzz/libraqm/etc.
42+
export TMPDIR="$$HOME/tmp_matplotlib"
43+
mkdir -p "$$TMPDIR"
44+
export MESON_PACKAGE_CACHE_DIR="$$HOME/mpl_packagecache"
45+
mkdir -p "$$MESON_PACKAGE_CACHE_DIR"
46+
cp "$(execpath @matplotlib_harfbuzz_src//file)" "$$MESON_PACKAGE_CACHE_DIR/harfbuzz-14.1.0.tar.xz"
47+
cp "$(execpath @matplotlib_sheenbidi_src//file)" "$$MESON_PACKAGE_CACHE_DIR/sheenbidi-3.0.0.tar.gz"
48+
cp "$(execpath @matplotlib_libraqm_src//file)" "$$MESON_PACKAGE_CACHE_DIR/libraqm-0.10.5.tar.gz"
49+
cp "$(execpath @matplotlib_qhull_src//file)" "$$MESON_PACKAGE_CACHE_DIR/qhull-8.0.2.tgz"
50+
""",
51+
}.get(module_name, "")
52+
1453
def create_requirements_file(name, outs):
1554
"""This macro is creating a requirements file per module.
1655
"""
@@ -31,6 +70,7 @@ def build_python_module(name, srcs, outs, requirements = "", **kwargs):
3170
openssl_dir = Label("@openssl").repo_name
3271
freetds_dir = Label("@freetds").repo_name
3372
python_dir = Label("@python").repo_name
73+
extra_setup = get_extra_setup(name)
3474
native.genrule(
3575
name = name + "_compile",
3676
srcs = srcs,
@@ -45,6 +85,7 @@ def build_python_module(name, srcs, outs, requirements = "", **kwargs):
4585
pyMajMin = PYTHON_MAJOR_DOT_MINOR,
4686
requirements = requirements,
4787
constraints = constraints,
88+
extra_setup = extra_setup,
4889
openssl_dir = openssl_dir,
4990
freetds_dir = freetds_dir,
5091
python_dir = python_dir,
@@ -54,6 +95,7 @@ def build_python_module(name, srcs, outs, requirements = "", **kwargs):
5495
pyMajMin = PYTHON_MAJOR_DOT_MINOR,
5596
requirements = requirements,
5697
constraints = constraints,
98+
extra_setup = extra_setup,
5799
openssl_dir = openssl_dir,
58100
freetds_dir = freetds_dir,
59101
python_dir = python_dir,
@@ -148,6 +190,7 @@ build_cmd = """
148190
export CFLAGS="-Wno-error=incompatible-pointer-types -ffile-prefix-map=$$HOME=."
149191
export CPPFLAGS="-I$$HOME/$$EXT_DEPS_PATH/{openssl_dir}/openssl/include -I$$HOME/$$EXT_DEPS_PATH/{freetds_dir}/freetds/include -I$$HOME/$$EXT_DEPS_PATH/{python_dir}/python/include/python{pyMajMin}/"
150192
export LDFLAGS="-L$$HOME/$$EXT_DEPS_PATH/{openssl_dir}/openssl/lib -L$$HOME/$$EXT_DEPS_PATH/{freetds_dir}/freetds/lib -L$$HOME/$$EXT_DEPS_PATH/{python_dir}/python/lib -Wl,--strip-debug"
193+
{extra_setup}
151194
{git_ssl_no_verify}\\
152195
$$PYTHON_EXECUTABLE -m pip install \\
153196
`: dont use precompiled things, build with our build env ` \\
@@ -163,7 +206,20 @@ build_cmd = """
163206
--use-feature=build-constraint \\
164207
--build-constraint="{constraints}" \\
165208
--prefix="$$HOME/$$MODULE_NAME" \\
166-
{requirements} 2>&1 | tee "$$HOME/""$$MODULE_NAME""_pip_install.stdout"
209+
{requirements} 2>&1 | tee "$$HOME/""$$MODULE_NAME""_pip_install.stdout" || true
210+
# The `|| true` above keeps `set -e` from aborting on pip's exit code before
211+
# we get a chance to inspect PIPESTATUS and dump diagnostics below.
212+
PIP_INSTALL_STATUS=$${{PIPESTATUS[0]}}
213+
if [ "$$PIP_INSTALL_STATUS" -ne 0 ]; then
214+
# pip/meson swallow the actual subprocess output on failure and only point
215+
# to a meson-log.txt buried in the (ephemeral) sandbox tmpdir -- e.g. the
216+
# harfbuzz subproject build inside matplotlib's meson-python backend just
217+
# reports "failed with status 1" with no further detail in the CI console.
218+
# Dump any such log here so the real traceback survives into the CI log.
219+
echo "pip install for $$MODULE_NAME failed (exit $$PIP_INSTALL_STATUS); dumping any meson-log.txt found under TMPDIR:"
220+
find "$$TMPDIR" -name meson-log.txt -print -exec cat {{}} \\; 2>/dev/null
221+
exit "$$PIP_INSTALL_STATUS"
222+
fi
167223
168224
tar cf $@ -C $$MODULE_NAME .
169225
"""

packages/cmk-graphing-engine/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@aspect_rules_py//py:defs.bzl", "py_library")
22
load("@bazel_skylib//rules:build_test.bzl", "build_test")
3+
load("@cmk_requirements//:requirements.bzl", "requirement")
34
load("@rules_python//python:packaging.bzl", "py_wheel")
45
load("//bazel/rules:package_wheel.bzl", "package_wheel")
56
load("//bazel/rules:py_cmk_test.bzl", "py_cmk_test")
@@ -48,6 +49,7 @@ py_cmk_test(
4849
srcs = glob(["tests/**/*.py"]),
4950
deps = [
5051
":cmk-graphing-engine",
52+
requirement("matplotlib"),
5153
],
5254
)
5355

0 commit comments

Comments
 (0)