You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
Lets allow aliases for a runopt. This will give downstream users to have multiple ways of accessing the same runopt.
1. Add a new dict to maintain alias to key values that can be used by `opt.get(name)`
2. Modify add() to accept list as well, build out the aliases list and modify the previously created dict to fill in alias to primary_key values.
3. Modify resolve() to check if a different alias is already used in cfg i.e if the "jobPriority" and "job_priority" are aliases for the same one, we don't allow for both to be present in the cfg.
4. Modify get to look at the alias to primary_key dict as well.
Differential Revision: D84157870
Returns the primary key and aliases for the given cfg_key.
1180
+
"""
1181
+
ifisinstance(cfg_key, str):
1182
+
returncfg_key, []
1183
+
1184
+
iflen(cfg_key) ==0:
1185
+
raiseValueError("cfg_key must be a non-empty list")
1186
+
primary_key=None
1187
+
aliases=list[RunOptAlias]()
1188
+
fornameincfg_key:
1189
+
ifisinstance(name, RunOptAlias):
1190
+
aliases.append(name)
1191
+
else:
1192
+
ifprimary_keyisnotNone:
1193
+
raiseValueError(
1194
+
f"cfg_key must contain a single primary key. Given more than one primary keys: {primary_key}, {name}. If one of them is an alias please use RunOptAlias type instead of str. "
1195
+
)
1196
+
primary_key=name
1197
+
ifprimary_keyisNoneorprimary_key=="":
1198
+
raiseValueError(
1199
+
"Missing cfg_key. Please provide one other than the aliases."
1200
+
)
1201
+
returnprimary_key, aliases
1202
+
1146
1203
defadd(
1147
1204
self,
1148
-
cfg_key: str,
1205
+
cfg_key: str|list[str],
1149
1206
type_: Type[CfgVal],
1150
1207
help: str,
1151
1208
default: CfgVal=None,
@@ -1156,6 +1213,7 @@ def add(
1156
1213
value (if any). If the ``default`` is not specified then this option
0 commit comments