Skip to content

feat(config): add RLEDGER_CONFIG_DIR and deprecate RLEDGER_CONFIG. - #1795

Merged
robcohen merged 2 commits into
rustledger:mainfrom
idheepan:feature/custom-config-dir
Jul 19, 2026
Merged

robcohen merged 2 commits into
rustledger:mainfrom
idheepan:feature/custom-config-dir

Conversation

@idheepan

Copy link
Copy Markdown
Contributor

Summary

Adds RLEDGER_CONFIG_DIR, an env var that relocates the entire user config directory (both config.toml and importers.toml) to an arbitrary path, replacing the narrower RLEDGER_CONFIG (which only relocated config.toml and never affected importers.toml discovery). This closes the gap where a dotfile manager (chezmoi/home-manager) could only relocate half of rledger's config. In the future when we have more configs like report.config etc setting the directory once is cleaner. Setting RLEDGER_CONFIG now prints a deprecation warning instead of silently doing nothing. We can remove that after a few weeks to make sure no one else has adopted that feature.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (changes to docs and some alignment in markdown to make it easy to read)
  • Refactor (code change that neither fixes a bug nor adds a feature)

I have selected breaking, but it should be okay because the feature that it breaks was only added a few days back and this PR extends that and makes it future proof.

Changes

Testing

  • cargo test
  • cargo clippy passes
  • Tested manually with a beancount file
  • Added new tests for the changes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed
  • My changes don't introduce new warnings

Review Focus

  • Please review the algorithm/logic
  • Please review for beancount compatibility
  • Please review for performance
  • Please review test coverage
  • General review is fine

@idheepan
idheepan requested a review from a team as a code owner July 14, 2026 01:35
@codecov

codecov Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/extract_cmd/mod.rs 25.00% 6 Missing ⚠️
crates/rustledger/src/config.rs 95.00% 5 Missing ⚠️
crates/rustledger/src/cmd/config_cmd.rs 71.42% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen robcohen self-assigned this Jul 16, 2026

@robcohen robcohen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — the direction is right (#1616's actual ask was always "relocate my config directory", and the file-level RLEDGER_CONFIG only got half of it), and the test discipline here is exemplary: pure *_with_override helpers for unit coverage, subprocess tests that set env on Command instead of set_var (exactly this repo's hermeticity rule), a wiring test that would catch a typo'd env-var name, the PROGRAMDATA shielding, and the macOS XDG interplay handled and documented. Genuinely nice work.

One premise needs correcting before this can merge, plus red CI:

1. RLEDGER_CONFIG is not "a few days old" — it has shipped in five releases

RLEDGER_CONFIG landed in #1650 on 2026-06-30 and is in v0.17.0 through v0.21.0, including Homebrew builds. And its target audience (chezmoi/home-manager users, per #1616) is exactly the crowd that bakes env vars into dotfile templates and updates them rarely. Making it inert with only a stderr warning silently breaks their config resolution — the warning helps interactive users, but dotfile-managed shells often never surface stderr from a status bar/cron invocation.

Suggested shape (small change to user_config_file_with_override): keep honoring it during the deprecation window —

  1. RLEDGER_CONFIG_DIR set → wins (dir override, both files).
  2. else RLEDGER_CONFIG set → still honored for config.toml only (its historical scope), with the deprecation warning you already wrote.
  3. else native + macOS XDG fallback, as in this PR.

If both are set, warn and state that RLEDGER_CONFIG_DIR won. Then the removal "after a few weeks" becomes a release-notes item instead of a silent break. (Deprecation policy nit: weeks-not-releases is hard for downstream packagers — I'd say "removed in the release after next".)

2. CI is red — three checks

  • Clippy (×2, both in the new code): map(<f>).unwrap_or_else(<g>) → map_or_else (in importers_config_not_found_message), and a this could be a const fn. cargo clippy --all-features --all-targets -- -D warnings locally will show both.
  • validate-docs: the vitepress build fails on this branch (build error in the docs job) — likely a dead link/anchor in the docs edits; cd website && npm run build reproduces.

Smaller notes (non-blocking)

  • warn_if_rledger_config_set fires on every Config::load() — right call for a deprecation, but with the honor-during-window approach above, only warn when the var is actually used (or superseded), so RLEDGER_CONFIG_DIR adopters don't get a stale warning about a var they've already migrated off.
  • Heads-up on a benign conflict: open PR #1786 touches extract_cmd around find_importers_config — whichever lands second needs a trivial rebase.
  • expand_os_path's lossy fallback for non-UTF-8 paths is a reasonable trade and the comment says why — good.

Happy to re-review quickly once the deprecation window + CI are sorted.

@robcohen

Copy link
Copy Markdown
Member

Update after maintainer review: the hard break of RLEDGER_CONFIG is accepted — one override mechanism is cleaner than two interacting ones, and the inert-plus-warning approach stands. Deprecation-window request withdrawn (review dismissed).

Design-wise this is the right end state: verified that the override reaches every rledger config-dir consumer on main (config.toml and importers.toml — both routed). The only dirs::config_dir() sites left are the query REPL's history/init files, which live under …/beanquery/ — beanquery's app directory, shared with the Python tool deliberately. Leaving them out of RLEDGER_CONFIG_DIR is correct; please add a one-line doc comment on get_history_path/get_init_path (crates/rustledger/src/cmd/query/interactive.rs) saying the exclusion is deliberate, so the next config-relocation pass doesn't "fix" it.

What remains before merge is mechanical:

  1. Clippy (×2 in the new code): map(<f>).unwrap_or_else(<g>) → map_or_else in importers_config_not_found_message, plus a could be a const fn. cargo clippy --all-features --all-targets -- -D warnings shows both.
  2. validate-docs: the vitepress build fails on this branch — cd website && npm run build reproduces.

Happy to merge promptly once CI is green.

@robcohen
robcohen dismissed their stale review July 16, 2026 03:33

Maintainer decision: the RLEDGER_CONFIG hard break is accepted — the deprecation-window request is withdrawn. Remaining asks are in the follow-up comment.

@robcohen

Copy link
Copy Markdown
Member

Dug into the CI failures — three findings, one of them cryptic enough to save you the decoding:

  1. Clippy (2 errors in the new code):

    • extract_cmd/mod.rs:334: map(...).unwrap_or_else(...) → clippy's suggested map_or_else form.
    • config.rs:779 resolve_user_config_path: missing_const_for_fn — on non-macOS the body reduces to returning native, so clippy wants const fn, but it can't be const on macOS (the XDG fallback). Suggest #[allow(clippy::missing_const_for_fn)] with a one-line comment saying why, rather than a cfg-split.
  2. build failing is downstream only — it's the aggregator gate and Clippy is in its needs; it goes green when Clippy does.

  3. validate-docs — the markdown "alignment" is the culprit. The reformat changed the first line of docs/commands/extract.md from a ______________ thematic-break rule to ---. A --- as the first line of a file opens YAML frontmatter in vitepress, which then chokes trying to parse ## title: … as YAML — that's the "end of the stream or a document separator is expected at line 11" error. Restore the underscore-style rule (or drop the leading break entirely) in extract.md — and check the same first-line pattern in the other three touched docs files (config.md, configuration.md, importing.md), which have the same shape on main.

The branch base is fine (July 13, post-lockfile-fix main) — no rebase needed.

Maintainer push to unblock rustledger#1795:

- clippy: `map_or_else` in importers_config_not_found_message; allow
  `missing_const_for_fn` on resolve_user_config_path (can't be const on
  macOS — the XDG fallback queries the filesystem), with a why-comment.
- validate-docs: restore the `____`-style thematic rule on the first line
  of extract.md and configuration.md. The reformat had changed it to
  `---`, which VitePress reads as a YAML frontmatter opener and then
  chokes on the `## title:` heading. Verified the real `npx vitepress
  build docs` now succeeds.
- Add deprecated_rledger_config_is_inert_and_warns: a subprocess test
  pinning the core breaking-change behavior — RLEDGER_CONFIG's config is
  NOT loaded and the deprecation warning is printed. Nothing tested this
  before, so a refactor could have silently re-enabled the old var.
- Document that the beanquery REPL history/init paths live under the
  shared `.../beanquery/` dir and are deliberately outside
  RLEDGER_CONFIG_DIR, so a future relocation pass doesn't move them.
@robcohen

Copy link
Copy Markdown
Member

Pushed ba110763 to green up CI and cover the deprecation (maintainer edit access — hope that's welcome; revert freely if you'd rather own these):

  • clippy ×2: map_or_else in importers_config_not_found_message; #[allow(clippy::missing_const_for_fn)] on resolve_user_config_path (it can't be const on macOS — the XDG fallback hits the filesystem), with a why-comment.
  • validate-docs: restored the ____-style rule on the first line of extract.md and configuration.md (the reformat had turned it into ---, which VitePress reads as a YAML frontmatter opener and then chokes on the ## title: line). I reproduced the real npx vitepress build docs against the website repo's config — it passes now.
  • New test deprecated_rledger_config_is_inert_and_warns: the breaking-change behavior (RLEDGER_CONFIG inert + warns) had no coverage, so a future refactor could have silently re-enabled it. Subprocess test asserts its config does not load and the warning prints.
  • Documented that the beanquery REPL history/init paths under .../beanquery/ are deliberately outside RLEDGER_CONFIG_DIR (per the earlier review note).

Design LGTM — unifying the override under one dir is the right end state and I confirmed both config.toml and importers.toml route through it.

Two minor, non-blocking notes for a follow-up (left as-is):

  1. The deprecation warning prints twice for config show (Config::load() runs twice); a OnceLock guard would dedupe it.
  2. EnvironmentConfig.profile is loaded but never applied in apply_env_config (profile is consumed in rledger.rs); its only effect here is flipping has_source(), so setting RLEDGER_PROFILE alone now records a ConfigSource::Environment whose values weren't merged. Cosmetic.

CI should re-run on the new commit.

@robcohen
robcohen merged commit c0bace8 into rustledger:main Jul 19, 2026
40 checks passed
@idheepan
idheepan deleted the feature/custom-config-dir branch November 22, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants