Skip to content

Commit

Permalink
Merge pull request #7 from qua-platform/temporary_quam_setup
Browse files Browse the repository at this point in the history
Allow quam.state_path to be added to config through CLI
  • Loading branch information
nulinspiratie authored Jan 22, 2025
2 parents 0344553 + 0c28a61 commit 216b4cb
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions qualibrate_config/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from qualibrate_config.models.qualibrate import QualibrateTopLevelConfig
from qualibrate_config.models.storage_type import StorageType
from qualibrate_config.qulibrate_types import RawConfigType
from qualibrate_config.validation import (
InvalidQualibrateConfigVersion,
qualibrate_version_validator,
Expand Down Expand Up @@ -109,7 +110,7 @@
)
@click.option(
"--storage-location",
type=click.Path(file_okay=False, dir_okay=True),
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
default=get_user_storage(),
show_default=True,
help=(
Expand All @@ -118,19 +119,27 @@
)
@click.option(
"--calibration-library-resolver",
"--runner-calibration-library-resolver",
type=str,
default="qualibrate.QualibrationLibrary",
show_default=True,
cls=DeprecatedOption,
deprecated=("--runner-calibration-library-resolver",),
preferred="--calibration-library-resolver",
help=(
"String contains python path to the class that represents qualibration "
"library."
),
)
@click.option(
"--calibration-library-folder",
type=click.Path(file_okay=False, dir_okay=True),
"--runner-calibration-library-resolver",
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
default=QUALIBRATE_PATH / "calibrations",
show_default=True,
cls=DeprecatedOption,
deprecated=("--runner-calibration-library-resolver",),
preferred="--calibration-library-folder",
help="Path to the folder contains calibration nodes and graphs.",
)
@click.option(
Expand Down Expand Up @@ -178,11 +187,21 @@
)
@click.option(
"--app-static-site-files",
type=click.Path(file_okay=False, dir_okay=True),
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
default=get_qapp_static_file_path(),
show_default=True,
help="Path to the frontend build static files.",
)
@click.option(
"--quam-state-path",
"--active-machine-path",
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
cls=DeprecatedOption,
required=False,
deprecated=("--active-machine-path",),
preferred="--quam-state-path",
help="Path to the quam state.",
)
@click.option("--check-generator", is_flag=True, hidden=True)
@click.pass_context
def config_command(
Expand All @@ -201,6 +220,7 @@ def config_command(
runner_timeout: float,
spawn_app: bool,
app_static_site_files: Path,
quam_state_path: Optional[Path],
check_generator: bool,
) -> None:
common_config, config_file = get_config_file_content(config_path)
Expand All @@ -225,6 +245,7 @@ def config_command(
qs = QualibrateTopLevelConfig({QUALIBRATE_CONFIG_KEY: qualibrate_config})
qs.qualibrate.storage.location.mkdir(parents=True, exist_ok=True)
try:
_temporary_fill_quam_state_path(common_config, quam_state_path)
write_config(
config_file,
common_config,
Expand All @@ -239,5 +260,20 @@ def config_command(
raise


def _temporary_fill_quam_state_path(
common_config: RawConfigType, state_path: Optional[Path]
) -> RawConfigType:
quam = common_config.get("quam", {})
active_machine = common_config.get("active_machine", {})
new_state_path = (
state_path or quam.get("state_path") or active_machine.get("path")
)
if new_state_path is None:
return common_config
quam["state_path"] = str(new_state_path)
common_config.update({"quam": quam})
return common_config


if __name__ == "__main__":
config_command([], standalone_mode=False)

0 comments on commit 216b4cb

Please sign in to comment.