Skip to content

Commit 66aea74

Browse files
committed
feat(robotcode): add Path to allowed GLOBALS in config expressions
1 parent 1277322 commit 66aea74

File tree

1 file changed

+18
-1
lines changed
  • packages/robot/src/robotcode/robot/config

1 file changed

+18
-1
lines changed

packages/robot/src/robotcode/robot/config/model.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import fnmatch
55
import os
6+
import pathlib
67
import platform
78
import re
89
from dataclasses import dataclass
@@ -106,6 +107,7 @@ def __init__(self, expression: str, message: str):
106107
"time": datetime.time,
107108
"timedelta": datetime.timedelta,
108109
"timezone": datetime.timezone,
110+
"Path": pathlib.Path,
109111
}
110112

111113

@@ -115,14 +117,27 @@ class Expression:
115117

116118
expr: str = field(
117119
description="""\
118-
Condition to evaluate. This must be a Python "eval" expression.
120+
Expression to evaluate. This must be a Python "eval" expression.
119121
For security reasons, only certain expressions and functions are allowed.
120122
121123
Examples:
122124
```toml
123125
expr = "re.match(r'^\\d+$', environ.get('TEST_VAR', ''))"
124126
expr = "platform.system() == 'Linux'"
127+
expr = "Path.cwd() / 'app'"
125128
```
129+
130+
Allowed global names (the name and the corresponding python module/name):
131+
132+
- `environ` -> os.environ
133+
- `re` -> re
134+
- `platform` -> platform
135+
- `datetime` -> datetime.datetime
136+
- `date` -> datetime.date
137+
- `time` -> datetime.time
138+
- `timedelta` -> datetime.timedelta
139+
- `timezone` -> datetime.timezone
140+
- `Path` -> pathlib.Path
126141
""",
127142
no_default=True,
128143
)
@@ -159,6 +174,8 @@ class Condition:
159174
if = "re.match(r'^\\d+$', environ.get('TEST_VAR', ''))"
160175
if = "platform.system() == 'Linux'"
161176
```
177+
178+
see also `expr` for allowed global names.
162179
""",
163180
alias="if",
164181
no_default=True,

0 commit comments

Comments
 (0)