Skip to content

fix: create parent directories for nested NOTEWISE_HOME config path#120

Closed
algojogacor wants to merge 1 commit into
whoisjayd:devfrom
algojogacor:fix/nested-notewise-home-config
Closed

fix: create parent directories for nested NOTEWISE_HOME config path#120
algojogacor wants to merge 1 commit into
whoisjayd:devfrom
algojogacor:fix/nested-notewise-home-config

Conversation

@algojogacor
Copy link
Copy Markdown

@algojogacor algojogacor commented May 13, 2026

Summary

Fixes #109

When NOTEWISE_HOME points to a nested path whose parents do not exist, notewise setup fails before writing config because get_config_path() only calls mkdir(exist_ok=True) without parents=True.

Root Cause

get_config_path() in src/notewise/ui/setup_wizard.py:78 creates the state directory with config_dir.mkdir(exist_ok=True), which raises FileNotFoundError when intermediate parent directories are missing. Other state/output code paths (repository.py, logging.py, _documents.py) already use parents=True, creating an inconsistency.

Fix

Changed config_dir.mkdir(exist_ok=True) to config_dir.mkdir(parents=True, exist_ok=True), matching the existing parent-safe creation pattern used by:

  • src/notewise/storage/repository.py:40
  • src/notewise/logging.py:256
  • src/notewise/pipeline/_documents.py:119

Changes

  • src/notewise/ui/setup_wizard.py: 1 line changed (+1 -1)
  • tests/unit/ui/test_setup_wizard.py: 2 test cases added (+25 -0)

Testing

  • Nested NOTEWISE_HOME with missing parents: Directory chain created successfully, config path returned ✅
  • Existing NOTEWISE_HOME directory: No error, config path returned correctly ✅
  • All 36 existing setup_wizard tests: No regressions ✅

Summary by Sourcery

Ensure setup wizard creates configuration directories safely when NOTEWISE_HOME points to nested paths.

Bug Fixes:

  • Fix failure when NOTEWISE_HOME points to a nested path whose parent directories do not exist by creating all missing parents before writing config.

Tests:

  • Add tests verifying get_config_path creates nested NOTEWISE_HOME directories and works when the config directory already exists.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced setup wizard to properly create parent directories when initializing the configuration directory structure, ensuring the setup process works correctly for all directory path scenarios.
  • Tests

    • Added unit tests validating configuration directory creation with both existing and non-existent directory paths.

Review Change Stack

Change config_dir.mkdir(exist_ok=True) to mkdir(parents=True, exist_ok=True)
in get_config_path() so setup works when NOTEWISE_HOME points to a nested path
whose parents do not exist yet. This matches the parent-safe creation already
used in repository.py, logging.py, and _documents.py.

Fixes whoisjayd#109
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

@algojogacor is attempting to deploy a commit to the whoisjayd Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 13, 2026

Reviewer's Guide

Ensures get_config_path creates parent directories for NOTEWISE_HOME and adds tests covering nested and pre-existing NOTEWISE_HOME scenarios.

File-Level Changes

Change Details Files
Ensure config directory creation is parent-safe in setup wizard configuration path helper.
  • Update get_config_path to create NOTEWISE_HOME directory with parents=True and exist_ok=True to avoid FileNotFoundError when parent directories are missing.
src/notewise/ui/setup_wizard.py
Add tests validating config path behavior for nested and existing NOTEWISE_HOME directories.
  • Add test verifying get_config_path creates full nested NOTEWISE_HOME directory chain and returns config.env path.
  • Add test verifying get_config_path works when NOTEWISE_HOME directory already exists and still returns config.env path.
tests/unit/ui/test_setup_wizard.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added size/size:XS area:cli CLI or terminal UX area area:tests Testing and test infrastructure labels May 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 22e9c522-2f49-4144-b07e-b3168ce60fe5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the get_config_path function to use parents=True when creating the configuration directory, ensuring that nested paths are correctly initialized. Corresponding unit tests were added to verify this behavior. The reviewer noted that the current implementation of get_config_path introduces side effects by creating directories, suggesting that this logic should ideally be moved to a dedicated initialization step or save_config to avoid unintended filesystem modifications during read-only operations.

"""Get path to user config file."""
config_dir = get_state_dir()
config_dir.mkdir(exist_ok=True)
config_dir.mkdir(parents=True, exist_ok=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The get_config_path function has a side effect of creating the configuration directory on the filesystem. This is generally discouraged for a 'getter' function, especially since it is called by read-only operations like load_config and show_current_config. This can lead to unexpected directory creation even when just checking for a configuration's existence, and it can cause side effects during unit testing (e.g., creating ~/.notewise if the path is not explicitly mocked or redirected). Additionally, it results in redundant mkdir calls when load_config is used within save_config. Consider moving the mkdir logic to save_config or a dedicated initialization step.

@whoisjayd
Copy link
Copy Markdown
Owner

closing since it is automated

@whoisjayd whoisjayd closed this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli CLI or terminal UX area area:tests Testing and test infrastructure size/size:XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants