|
28 | 28 | from .transport import Transport, TransportTimeouts |
29 | 29 |
|
30 | 30 |
|
| 31 | +def add_unspecified_options(options: dict, server_project_options: list) -> dict: |
| 32 | + """Adds default value of project template options that are not specified by user.""" |
| 33 | + if not options: |
| 34 | + options = dict() |
| 35 | + for option in server_project_options: |
| 36 | + name = option["name"] |
| 37 | + if name not in options.keys(): |
| 38 | + options[name] = option["default"] |
| 39 | + return options |
| 40 | + |
| 41 | + |
31 | 42 | class ProjectTransport(Transport): |
32 | 43 | """A Transport implementation that uses the Project API client.""" |
33 | 44 |
|
@@ -69,10 +80,10 @@ def from_directory(cls, project_dir: Union[pathlib.Path, str], options: dict): |
69 | 80 |
|
70 | 81 | def __init__(self, api_client, options): |
71 | 82 | self._api_client = api_client |
72 | | - self._options = options |
73 | 83 | self._info = self._api_client.server_info_query(__version__) |
74 | 84 | if self._info["is_template"]: |
75 | 85 | raise TemplateProjectError() |
| 86 | + self._options = add_unspecified_options(options, self._info["project_options"]) |
76 | 87 |
|
77 | 88 | def build(self): |
78 | 89 | self._api_client.build(self._options) |
@@ -121,19 +132,10 @@ def _check_project_options(self, options: dict): |
121 | 132 | Here is a list of available options:{list(available_options)}.""" |
122 | 133 | ) |
123 | 134 |
|
124 | | - def _add_unspecified_options(self, options: dict): |
125 | | - """Adds default value of project options that are not specified by user.""" |
126 | | - if not options: |
127 | | - options = dict() |
128 | | - for option in self._info["project_options"]: |
129 | | - name = option["name"] |
130 | | - if name not in options.keys(): |
131 | | - options[name] = option["default"] |
132 | | - |
133 | 135 | def generate_project_from_mlf(self, model_library_format_path, project_dir, options: dict): |
134 | 136 | """Generate a project from MLF file.""" |
135 | 137 | self._check_project_options(options) |
136 | | - self._add_unspecified_options(options) |
| 138 | + options = add_unspecified_options(options, self._info["project_options"]) |
137 | 139 |
|
138 | 140 | self._api_client.generate_project( |
139 | 141 | model_library_format_path=str(model_library_format_path), |
|
0 commit comments