Skip to content

Commit

Permalink
test-cycles: Get rid of explicit package list
Browse files Browse the repository at this point in the history
Automatically derive paths to scan from the namespace package in the
current venv.

Make the job use the new uv venv along the way.

Change-Id: I52547ca3ff28ebd575b579d10fbe31d3d89e37fa
  • Loading branch information
LarsMichelsen committed Dec 5, 2024
1 parent 34b508b commit 5818893
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
22 changes: 5 additions & 17 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ SCRIPTS := $(realpath ../scripts)
FIND_PYTHON_FILES := $(SCRIPTS)/find-python-files
FIND_SHELL_FILES := $(SCRIPTS)/find-shell-files
PIPENV := $(SCRIPTS)/run-pipenv
UVENV := $(SCRIPTS)/run-uvenv
PYTEST := $(PIPENV) run pytest $(PYTEST_ARGS)
CYCLES := $(PIPENV) run py_import_cycles
CYCLES := $(UVENV) py_import_cycles
PYTEST_OPTS_UNIT_SKIP_SLOW = -m "not slow"
PYTEST_OPTS_UNIT_SLOW_ONLY = -m "slow"
THREE_TO_TWO := $(PIPENV) run 3to2
Expand Down Expand Up @@ -398,27 +399,14 @@ test-shellcheck-docker:
test-cycles:
$(CYCLES) \
--packages \
$$(realpath -L ..)/cmk \
$$(realpath -L ..)/packages/cmk-agent-based/cmk \
$$(realpath -L ..)/packages/cmk-agent-receiver/cmk \
$$(realpath -L ..)/packages/cmk-ccc/cmk \
$$(realpath -L ..)/packages/cmk-crypto/cmk \
$$(realpath -L ..)/packages/cmk-events/cmk \
$$(realpath -L ..)/packages/cmk-graphing/cmk \
$$(realpath -L ..)/packages/cmk-livestatus-client/cmk \
$$(realpath -L ..)/packages/cmk-messaging/cmk \
$$(realpath -L ..)/packages/cmk-mkp-tool/cmk \
$$(realpath -L ..)/packages/cmk-rulesets/cmk \
$$(realpath -L ..)/packages/cmk-server-side-calls/cmk \
$$(realpath -L ..)/packages/cmk-werks/cmk \
$$(realpath -L ..)/packages/cmk-trace/cmk \
$$(realpath -L ..)/omd/packages/omd/omdlib \
$$($(UVENV) scripts/find_cmk_namespace_package_paths.py) \
$$(realpath -L ..)/omd/packages/omd/omdlib \
--strategy johnson \
--threshold 114 \
--verbose

test-cycles-docker:
../scripts/run-in-docker.sh make --quiet test-cycles
../scripts/run-in-docker.sh TERM=xterm make --quiet test-cycles

test-unit-omdlib:
cd .. && TZ=$(RANDOM_TZ) $(PYTEST) \
Expand Down
24 changes: 24 additions & 0 deletions tests/scripts/find_cmk_namespace_package_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

"""Find all directories that are part of the given implicit namespace package."""

import importlib
import os


def find_namespace_package_paths(namespace_name: str) -> list[str]:
try:
namespace_module = importlib.import_module(namespace_name)
except ModuleNotFoundError:
return []

if not hasattr(namespace_module, "__path__"):
return [] # not a namespace package

return [os.path.abspath(path) for path in namespace_module.__path__]


print("\n".join(find_namespace_package_paths("cmk")))

0 comments on commit 5818893

Please sign in to comment.