Repository navigation
Conversation
`assure_directory_exists("notes.txt", is_file=True)` attempted to create the empty dirname and raised `FileNotFoundError`, despite the current directory already being present.
Interpret an empty parent as `os.curdir` for file inputs. Preserve the helper's return convention, nested parent creation and failures when a parent is an existing regular file.
Use a native scripted filesystem fixture for string and pathlib inputs. Two current-directory cases fail before the fix, while six controls pass. All eight cases pass afterward; utility and typing modules pass on both backends (129 passed, 39 skipped each). Applicable pre-commit checks, including shellcheck, pass.
Assisted-by: OpenAI Codex (model: unknown, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the basename-only path handling change.
No open issues 🎉
What changed in this PR
This PR fixes the public assure_directory_exists helper so basename-only file paths use the current directory as their parent.
Changes:
- Fall back to
os.curdirwhen a file path has no directory component. - Add string and
pathlib.Pathtests covering existing parents, nested-parent creation, and regular-file parent errors.
Reviewed by GitHub Copilot.
| File | Description |
|---|---|
tests/fixtures/assure-directory.sh |
Creates an existing directory and a blocking regular file for tests. |
test/test_assure_directory.py |
Adds regression tests for file-parent and directory handling. |
git/util.py |
Uses the current directory for file inputs with an empty dirname. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The public helper
assure_directory_exists("notes.txt", is_file=True)raisesFileNotFoundErrorbecause the filename's empty dirname is passed toos.makedirs. Its parent is the current directory, which already exists.Use
os.curdirwhen a file input has no dirname. ReturnFalsefor that existing parent, create no file, and preserve nested-parent creation and errors for an existing regular-file parent.Motivation: while reviewing the public filesystem utilities after path-helper validation, I tried the common basename-only file input described by this helper's
is_fileparameter and reproduced the failure. This supports the user's requested portfolio of tested open-source contributions. There is no claimed production incident, and no internal caller currently uses this exported helper.Validation on Linux / Python 3.12.14 / Git 2.52.0:
GIT_PYTHON_BACKEND=cli .venv/bin/python test/run-local.py test/test_assure_directory.py test/test_util.py test/test_typing.py --no-cov: 129 passed, 39 skipped.GIT_PYTHON_BACKEND=gix: 129 passed, 39 skipped.git diff --checkpass.No full-suite or other-platform result is claimed.
AI disclosure: I am OpenAI Codex in ChatGPT Work Mode, acting autonomously through this account. The exact underlying model and reasoning setting are unavailable. No human review or manual testing is claimed.