From 4b67bc6b070dd89a6dbc02a59e7617fb68de07d9 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Tue, 19 Oct 2021 12:00:09 +0200 Subject: [PATCH 1/4] Document how to set a variable's value in the class body from the command line --- docs/manpage.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/manpage.rst b/docs/manpage.rst index 5cb1a9ece4..c11aaff411 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -390,6 +390,20 @@ Options controlling ReFrame execution foo = variable(int, value=1) num_tasks = foo + .. tip:: + + In cases that you really need the variable to be set before the test is instantiated, like parameterising the test based on this variable, you can do it through an environment variable: + + .. code-block:: python + + import os + + @rfm.simple_test + class my_test(rfm.RegressionTest): + foo = variable(int, value=int(os.getenv('MYFOOVAR', 1))) + # Parameterise number of nodes + num_nodes = parameter((1 << i for i in range(0, int(foo)))) + - If the variable is set in any pipeline hook, the command line assignment will have an effect until the variable assignment in the pipeline hook is reached. The variable will be then overwritten. - The `test filtering <#test-filtering>`__ happens *after* a test is instantiated, so the only way to scope a variable assignment is to prefix it with the test class name. From cbdf9775c9469e39488ec977dfe115f7bfe1aa4a Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Wed, 20 Oct 2021 13:15:08 +0200 Subject: [PATCH 2/4] Address PR comments --- docs/manpage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/manpage.rst b/docs/manpage.rst index c11aaff411..b62aa296ee 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -392,7 +392,7 @@ Options controlling ReFrame execution .. tip:: - In cases that you really need the variable to be set before the test is instantiated, like parameterising the test based on this variable, you can do it through an environment variable: + If you use a variable's value in the definition of another variable or parameter and you need to control that variable from the command line, you should consider using an environment variable to set it, as in the following example: .. code-block:: python @@ -400,9 +400,9 @@ Options controlling ReFrame execution @rfm.simple_test class my_test(rfm.RegressionTest): - foo = variable(int, value=int(os.getenv('MYFOOVAR', 1))) + max_nodes = variable(int, value=int(os.getenv('MAX_NODES', 1))) # Parameterise number of nodes - num_nodes = parameter((1 << i for i in range(0, int(foo)))) + num_nodes = parameter((1 << i for i in range(0, int(max_nodes)))) - If the variable is set in any pipeline hook, the command line assignment will have an effect until the variable assignment in the pipeline hook is reached. The variable will be then overwritten. From 052f047ec811ea13d20a594978d482df89d863a4 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Wed, 20 Oct 2021 13:56:29 +0200 Subject: [PATCH 3/4] Update docs --- docs/manpage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manpage.rst b/docs/manpage.rst index b62aa296ee..14bb3947ad 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -392,7 +392,7 @@ Options controlling ReFrame execution .. tip:: - If you use a variable's value in the definition of another variable or parameter and you need to control that variable from the command line, you should consider using an environment variable to set it, as in the following example: + In cases where the class body expresses logic as a function of a variable, the variable's default value (i.e. the value set through the value argument) may be modified through an environment variable as follows: .. code-block:: python From 3489ea036b8216c8c5a80e7b647ec3e501fdfb70 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Mon, 25 Oct 2021 09:40:17 +0200 Subject: [PATCH 4/4] Address PR comments --- docs/manpage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manpage.rst b/docs/manpage.rst index 14bb3947ad..78b6577e98 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -392,7 +392,7 @@ Options controlling ReFrame execution .. tip:: - In cases where the class body expresses logic as a function of a variable, the variable's default value (i.e. the value set through the value argument) may be modified through an environment variable as follows: + In cases where the class body expresses logic as a function of a variable and this variable, as well as its dependent logic, need to be controlled externally, the variable's default value (i.e. the value set through the value argument) may be modified as follows through an environment variable and not through the `-S` option: .. code-block:: python