Skip to content

Commit

Permalink
fix(controller): support multiple value (#3131)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing authored Jan 19, 2024
1 parent e60e6ea commit 02078ce
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/starwhale/base/client/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ class OptionField(SwBaseModel):
type: OptionType
required: bool
multiple: bool
value: Optional[str] = None
value: Optional[Dict[str, Any]] = None
help: Optional[str] = None
hidden: bool
default: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion console/src/api/server/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ export interface IOptionField {
type: IOptionType
required: boolean
multiple: boolean
value?: string
value?: object
help?: string
hidden: boolean
default?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static class OptionField {
/**
* used for server side only
*/
private String value;
private Object value;

private String help;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -86,14 +87,18 @@ public Map<String, String> getContainerEnvs() {
cmdArgs.append(
stepSpec.getArguments().values().stream()
.flatMap(options -> options.values().stream())
.filter(optionField -> StringUtils.hasText(optionField.getValue()))
.filter(optionField -> Objects.nonNull(optionField.getValue()))
.map(optionField -> {
if (optionField.isFlag()) {
return Boolean.parseBoolean(optionField.getValue())
return (boolean) optionField.getValue()
? "--" + optionField.getName() : "";
} else {
return "--" + optionField.getName() + " " + optionField.getValue();
} else if (optionField.isMultiple()
&& optionField.getValue() instanceof List) {
return ((List<?>) optionField.getValue()).stream()
.map(value -> "--" + optionField.getName() + " " + value)
.collect(Collectors.joining(" "));
}
return "--" + optionField.getName() + " " + optionField.getValue();
}).collect(Collectors.joining(" "))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class SwCliModelHandlerContainerSpecificationTest {
put("SW_RUN_HANDLER", null);
put("SW_DEV_TOKEN", null);
put("SW_DEV_PORT", "8000");
put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --a 11");
put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --patch 1 --patch 2 --a 11");
put("SW_CONDA_CONFIG", "channels:\n"
+ " - defaults\n"
+ "show_channel_urls: true\n"
Expand Down Expand Up @@ -139,7 +139,7 @@ public class SwCliModelHandlerContainerSpecificationTest {
put("SW_PYPI_RETRIES", "1");
put("SW_PYPI_TIMEOUT", "2");
put("SW_RUN_HANDLER", null);
put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --a 11");
put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --patch 1 --patch 2 --a 11");
put("SW_CONDA_CONFIG", "channels:\n"
+ " - defaults\n"
+ "show_channel_urls: true\n"
Expand Down Expand Up @@ -284,13 +284,16 @@ private Task mockTask(boolean devMode) throws JsonProcessingException {
+ " opts:\n"
+ " - --reshape\n"
+ " required: false\n"
+ " patch:\n" // this will not be used
+ " patch:\n"
+ " default: 16\n"
+ " help: batch size\n"
+ " hidden: false\n"
+ " is_flag: false\n"
+ " multiple: false\n"
+ " multiple: true\n"
+ " name: patch\n"
+ " value:\n"
+ " - 1\n"
+ " - 2\n"
+ " opts:\n"
+ " - --patch\n"
+ " required: false",
Expand Down

0 comments on commit 02078ce

Please sign in to comment.