Full/simplified dwave create flows.
(config_file, profile, ask_full=False, auto_token=False, project=None)
| 261 | raise CLIError(f"Error writing to configuration file: {e!r}", code=2) |
| 262 | |
| 263 | def _config_create(config_file, profile, ask_full=False, auto_token=False, project=None): |
| 264 | """Full/simplified dwave create flows.""" |
| 265 | |
| 266 | if ask_full: |
| 267 | # try using existing file/env/kwarg=cli config for metadata api access, |
| 268 | # but fall back to Regions defaults |
| 269 | try: |
| 270 | raw_config = load_config(config_file=config_file, profile=profile) |
| 271 | except: |
| 272 | raw_config = {} |
| 273 | |
| 274 | regions = get_regions(config=raw_config) |
| 275 | region_choices = [r.code for r in regions] |
| 276 | prompts = dict( |
| 277 | region=dict(prompt="Solver API region", choices=region_choices), |
| 278 | endpoint=dict(prompt="Solver API endpoint URL (overwrites 'region')"), |
| 279 | token=dict(prompt="Solver API token"), |
| 280 | client=dict(prompt="Client class", choices='base qpu sw hybrid'.split()), |
| 281 | solver=dict(prompt="Solver")) |
| 282 | |
| 283 | else: |
| 284 | prompts = dict( |
| 285 | token=dict(prompt="Solver API token")) |
| 286 | |
| 287 | click.echo("Using the simplified configuration flow.\n" |
| 288 | "Try 'dwave config create --full' for more options.\n") |
| 289 | |
| 290 | # resolve config file path |
| 291 | ask_to_confirm_config_path = not config_file |
| 292 | if not config_file: |
| 293 | config_file = get_configfile_path() |
| 294 | if not config_file: |
| 295 | config_file = get_default_configfile_path() |
| 296 | |
| 297 | config_file_exists = os.path.exists(config_file) |
| 298 | verb = "Updating existing" if config_file_exists else "Creating new" |
| 299 | click.echo(f"{verb} configuration file: {config_file}") |
| 300 | |
| 301 | if ask_full and ask_to_confirm_config_path: |
| 302 | config_file = default_text_input("Confirm configuration file path", config_file) |
| 303 | config_file = os.path.expanduser(config_file) |
| 304 | |
| 305 | config = _load_config(config_file) |
| 306 | default_section = config.default_section |
| 307 | |
| 308 | # resolve profile |
| 309 | if not profile: |
| 310 | existing = config.sections() |
| 311 | if default_section in config: # not included in sections |
| 312 | existing.insert(0, default_section) |
| 313 | if config_file_exists: |
| 314 | click.echo(f"Available profiles: {', '.join(existing)}") |
| 315 | default_profile = next(iter(existing)) |
| 316 | |
| 317 | if ask_full: |
| 318 | _note = " (select existing or create new)" if config_file_exists else "" |
| 319 | profile = default_text_input(f"Profile{_note}", default_profile) |
| 320 | else: |
no test coverage detected