fix(hosting-cli): fail cloud config when PyYAML is missing

GA
2d ago
+79-3

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

Closes #7092.

On main, regions and vmtypes already exit 1 and write no JSON document when the request fails (#6917 / #7207). The case from the issue that is still open is reflex cloud config --json without PyYAML. hosting.generate_config logged "Please install PyYAML to use this command" and returned None. That is the same value it returns when a cloud.yml already exists, so the command printed {"generated": false, "path": null} and exited 0.

This PR makes generate_config raise click.exceptions.Exit(1) after logging that error. The command now exits 1, and with --json it writes nothing to stdout, which is how regions/vmtypes handle a failed read. The check still runs before authentication, so no token is requested.

I left the existing-cloud.yml case alone. It still returns None and exits 0 with generated: false, as test_generate_cloud_config_json_output_when_nothing_written requires.

One behaviour change: plain reflex cloud config (without --json) also exits 1 now when PyYAML is missing, where it used to exit 0. The news fragment mentions this.

News fragment: packages/reflex-hosting-cli/news/+config-missing-pyyaml.bugfix.md.

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Validation

Tests (each one makes PyYAML unimportable with mocker.patch.dict("sys.modules", {"yaml": None})):

  • tests/units/reflex_cli/v2/test_vmtypes_regions.py
    • test_generate_cloud_config_json_without_pyyaml_writes_no_document: exit 1, empty stdout, no auth call.
    • test_generate_cloud_config_without_pyyaml_exits_nonzero: exit 1, the PyYAML error is logged at ERROR, nothing printed.
  • tests/units/reflex_cli/utils/test_hosting.py
    • test_generate_config_without_pyyaml_raises: Exit(1), no auth call.
    • test_generate_config_with_existing_file_returns_none: an existing cloud.yml is left unchanged and None is returned.

On main, the three PyYAML tests fail (the command exits 0 and generate_config does not raise). With this change, uv run pytest tests/units/reflex_cli passes (804 tests). ruff check, ruff format --check, and pre-commit (pyright, ty, codespell) pass on the changed files. I did not run the full tests/units suite locally; CI will.


🤖 Opened with Superhuman, an open-source contribution agent.