33import datetime
44import fnmatch
55import os
6+ import pathlib
67import platform
78import re
89from 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