From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDE4E4366A; Mon, 4 Dec 2023 11:25:10 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 549C241060; Mon, 4 Dec 2023 11:24:39 +0100 (CET) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by mails.dpdk.org (Postfix) with ESMTP id 5DAA040E72 for ; Mon, 4 Dec 2023 11:24:36 +0100 (CET) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40c0873cf84so13881395e9.1 for ; Mon, 04 Dec 2023 02:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1701685476; x=1702290276; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CCNc9kWJ1NNoU6JO0SvKKLXK/BM6pco6XY3SjKbCz6s=; b=jFIWKNkfC99P5v0CGsetKAwSeDRHFfkq+vUu29NHVvODQ2n313ImEvGl3SGef6oOpx IKmVooYEqCiBkGr8QA31u9ZG4Y4NO/ecN4CByaF1YvI/ooAtOLM8WVXPINbgssjeU+rA PFVxaRFePMzo5zG/WTQlg7ApGmtEfSPmNzbRuY2YgVNETitzyrQz6+mKJNGaSfwx3K0s 3Bf2Sh83uunpYzlYPjhh6ZlJfQUgeRXdMB8Zpf9Hady+Gptq6igLy9hCp52aEC4BFucv TtBO6rhRz0i0ZumxMPZkje/T6Rw9ILTkaHY2xSL8+j39tjxrLRAcIrPVHC64zl07orHW yaVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701685476; x=1702290276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CCNc9kWJ1NNoU6JO0SvKKLXK/BM6pco6XY3SjKbCz6s=; b=PVRGPMBPBqQ6+yXoyYCheu/UPFeuxSltuKunrLje5BHB65WDkHyiY28n9UbPVUx4X1 0rDlELFp9zDwUGsYp4P4sAoAmdjaEu06BQmJ4OW/msllg1oNfO/Op4V6IOhz/4YHTEDx kHdvDi6DkxQ98wRr2iRQqEYjDrg6Vg25+ckAVmhuXUyX4ZKWAxzyi4k6ZCFZnNbMgo5Y YXKRlKftNQz8MlKI71GQoeRXbhhz7oQqSiPh9Wyy3h+V9KRx3P2jn+04ders4ONRLKBO U1cWAO8i8DdZmCxau1DTXRmvM0glkk2FErOapmSkjmgXusTKfxZ7XWwWdlFyL8pTM84U +fJQ== X-Gm-Message-State: AOJu0Yz3Mf9j5KzdIvo+kj1XzKvTSemCIIutRfCCL8v9kMeejq7/HYCc RHhR02K70abl5bfGpshClM6ICA== X-Google-Smtp-Source: AGHT+IEqMUl8pYA9fdU7wlSJJ9qFJ4ZPdRMb+lWPSlpcbYc8aeJ+KT5d8WYYvXh8JmffaAmZeI4npA== X-Received: by 2002:a05:600c:3111:b0:40b:5e1e:cf3 with SMTP id g17-20020a05600c311100b0040b5e1e0cf3mr2232978wmo.46.1701685476013; Mon, 04 Dec 2023 02:24:36 -0800 (PST) Received: from jlinkes-PT-Latitude-5530.pantheon.local ([81.89.53.154]) by smtp.gmail.com with ESMTPSA id m28-20020a05600c3b1c00b0040b2b38a1fasm14255415wms.4.2023.12.04.02.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:24:35 -0800 (PST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, jspewock@iol.unh.edu, probb@iol.unh.edu, paul.szczepanek@arm.com, yoan.picchi@foss.arm.com, Luca.Vizzarro@arm.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [PATCH v9 05/21] dts: settings docstring update Date: Mon, 4 Dec 2023 11:24:13 +0100 Message-Id: <20231204102429.106709-6-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204102429.106709-1-juraj.linkes@pantheon.tech> References: <20231123151344.162812-1-juraj.linkes@pantheon.tech> <20231204102429.106709-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Format according to the Google format and PEP257, with slight deviations. Signed-off-by: Juraj Linkeš --- dts/framework/settings.py | 103 +++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/dts/framework/settings.py b/dts/framework/settings.py index 25b5dcff22..41f98e8519 100644 --- a/dts/framework/settings.py +++ b/dts/framework/settings.py @@ -3,6 +3,72 @@ # Copyright(c) 2022-2023 PANTHEON.tech s.r.o. # Copyright(c) 2022 University of New Hampshire +"""Environment variables and command line arguments parsing. + +This is a simple module utilizing the built-in argparse module to parse command line arguments, +augment them with values from environment variables and make them available across the framework. + +The command line value takes precedence, followed by the environment variable value, +followed by the default value defined in this module. + +The command line arguments along with the supported environment variables are: + +.. option:: --config-file +.. envvar:: DTS_CFG_FILE + + The path to the YAML test run configuration file. + +.. option:: --output-dir, --output +.. envvar:: DTS_OUTPUT_DIR + + The directory where DTS logs and results are saved. + +.. option:: --compile-timeout +.. envvar:: DTS_COMPILE_TIMEOUT + + The timeout for compiling DPDK. + +.. option:: -t, --timeout +.. envvar:: DTS_TIMEOUT + + The timeout for all DTS operation except for compiling DPDK. + +.. option:: -v, --verbose +.. envvar:: DTS_VERBOSE + + Set to any value to enable logging everything to the console. + +.. option:: -s, --skip-setup +.. envvar:: DTS_SKIP_SETUP + + Set to any value to skip building DPDK. + +.. option:: --tarball, --snapshot, --git-ref +.. envvar:: DTS_DPDK_TARBALL + + The path to a DPDK tarball, git commit ID, tag ID or tree ID to test. + +.. option:: --test-cases +.. envvar:: DTS_TESTCASES + + A comma-separated list of test cases to execute. Unknown test cases will be silently ignored. + +.. option:: --re-run, --re_run +.. envvar:: DTS_RERUN + + Re-run each test case this many times in case of a failure. + +The module provides one key module-level variable: + +Attributes: + SETTINGS: The module level variable storing framework-wide DTS settings. + +Typical usage example:: + + from framework.settings import SETTINGS + foo = SETTINGS.foo +""" + import argparse import os from collections.abc import Callable, Iterable, Sequence @@ -16,6 +82,23 @@ def _env_arg(env_var: str) -> Any: + """A helper method augmenting the argparse Action with environment variables. + + If the supplied environment variable is defined, then the default value + of the argument is modified. This satisfies the priority order of + command line argument > environment variable > default value. + + Arguments with no values (flags) should be defined using the const keyword argument + (True or False). When the argument is specified, it will be set to const, if not specified, + the default will be stored (possibly modified by the corresponding environment variable). + + Other arguments work the same as default argparse arguments, that is using + the default 'store' action. + + Returns: + The modified argparse.Action. + """ + class _EnvironmentArgument(argparse.Action): def __init__( self, @@ -68,14 +151,28 @@ def __call__( @dataclass(slots=True) class Settings: + """Default framework-wide user settings. + + The defaults may be modified at the start of the run. + """ + + #: config_file_path: Path = Path(__file__).parent.parent.joinpath("conf.yaml") + #: output_dir: str = "output" + #: timeout: float = 15 + #: verbose: bool = False + #: skip_setup: bool = False + #: dpdk_tarball_path: Path | str = "dpdk.tar.xz" + #: compile_timeout: float = 1200 + #: test_cases: list[str] = field(default_factory=list) + #: re_run: int = 0 @@ -166,7 +263,7 @@ def _get_parser() -> argparse.ArgumentParser: action=_env_arg("DTS_RERUN"), default=SETTINGS.re_run, type=int, - help="[DTS_RERUN] Re-run each test case the specified amount of times " + help="[DTS_RERUN] Re-run each test case the specified number of times " "if a test failure occurs", ) @@ -174,6 +271,10 @@ def _get_parser() -> argparse.ArgumentParser: def get_settings() -> Settings: + """Create new settings with inputs from the user. + + The inputs are taken from the command line and from environment variables. + """ parsed_args = _get_parser().parse_args() return Settings( config_file_path=parsed_args.config_file, -- 2.34.1