Skip to content

zulip: Abstract exit_gracefully_if_zulip_config_is_missing helper. - #943

Open
NaniToka wants to merge 1 commit into
zulip:mainfrom
NaniToka:cli-zuliprc-config-696
Open

NaniToka wants to merge 1 commit into
zulip:mainfrom
NaniToka:cli-zuliprc-config-696

Conversation

@NaniToka

@NaniToka NaniToka commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #696.

Overview

Abstracts exit_gracefully_if_zulip_config_is_missing and zulip_env_vars_are_present from zulip_bots into the core zulip library (zulip/__init__.py), making the config checking mechanism reusable across tools (such as zulip-cli in a follow-up step).

Summary of Changes

  1. Core Library: Added zulip_env_vars_are_present() and exit_gracefully_if_zulip_config_is_missing() to zulip/__init__.py. Included an allow_default_config parameter (defaulting to True for general tools, while zulip_bots passes False to preserve its existing explicit-config behavior).
  2. Backwards Compatibility: Updated zulip_bots.lib.zulip_env_vars_are_present to delegate to zulip.
  3. Bot Runner: Updated zulip_bots.run.exit_gracefully_if_zulip_config_is_missing to delegate to zulip.
  4. Unit Tests: Added test coverage in zulip/tests/test_config.py covering environment variable detection and graceful exit behavior.

Verification

  • pytest zulip/tests/ zulip_bots/zulip_bots/tests/ passed (29 passed).
  • ./tools/lint-commits passed cleanly.

@rht

rht commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR @NaniToka .
There are too many changes soldered into 1 commit. Needs to be separate atomic commits.
Haven't been on chat.zulip.org for a while, so can't tell what the AI contribution review policy is. For a starter, I'd do only point 1 (abstracting out the exit_gracefully_if_zulip_config_is_missing and reusing it) in for the whole PR.

@NaniToka
NaniToka force-pushed the cli-zuliprc-config-696 branch from 6d2ce9e to 1c9e7c6 Compare November 12, 2026 15:41
@NaniToka NaniToka changed the title zulip-cli: Support custom config path and abstract config validation. zulip: Abstract exit_gracefully_if_zulip_config_is_missing helper. Nov 12, 2026
@NaniToka

Copy link
Copy Markdown
Author

Thanks for the review and guidance, @rht! That makes complete sense.

I have scoped this PR down strictly to point 1 as suggested:

  1. Reverted all the zulip-cli modifications and deferred them to a separate follow-up PR once this core abstraction lands.
  2. Kept only the abstraction of zulip_env_vars_are_present() and exit_gracefully_if_zulip_config_is_missing() into zulip/__init__.py, with zulip_bots delegating to it.
  3. Added unit tests in zulip/tests/test_config.py.
  4. Structured into a clean, single atomic commit matching Gitlint rules (./tools/lint-commits).

All 29 tests pass locally across zulip/tests and zulip_bots/zulip_bots/tests.

Previously, `exit_gracefully_if_zulip_config_is_missing` and
`zulip_env_vars_are_present` were defined only inside `zulip_bots`.
Other tools (such as `zulip-cli` and custom scripts) could not reuse
this validation logic without code duplication.

This commit:
- Moves `zulip_env_vars_are_present` and
  `exit_gracefully_if_zulip_config_is_missing` to the core `zulip`
  module (`zulip/__init__.py`).
- Supports an optional `allow_default_config` parameter (defaulting to
  `True` for general tools, while `zulip_bots` passes `False` to maintain
  its existing explicit configuration semantics).
- Retains `zulip_bots.lib.zulip_env_vars_are_present` as a delegation
  wrapper for backwards compatibility.
- Updates `zulip_bots.run.exit_gracefully_if_zulip_config_is_missing` to
  delegate to `zulip`.
- Adds unit tests in `zulip/tests/test_config.py` for both functions.

Fixes zulip#696.
@NaniToka
NaniToka force-pushed the cli-zuliprc-config-696 branch from 1c9e7c6 to 2c755a4 Compare November 12, 2026 15:50
@rht

rht commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@NaniToka

Copy link
Copy Markdown
Author

Hi @rht, thank you for sharing the discussion, and I completely respect and understand your perspective regarding reviewer bandwidth and effort.

To respect your time, I made sure this revised commit is strictly focused on the single abstraction (exit_gracefully_if_zulip_config_is_missing) and its corresponding unit tests as you requested, with all extra CLI changes removed. Every line and test has been manually verified locally.

Please feel free to review it whenever you have time, with zero rush. I really appreciate your guidance and feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zulip-cli: Replace harcoded zuliprc path with the one used in zulip_bots/run.py

3 participants