Skip to content

Accept quoted file paths in the IPython dotenv magic - #732

Open
FanWu-ai wants to merge 1 commit into
theskumar:mainfrom
FanWu-ai:fix/ipython-quoted-paths
Open

FanWu-ai wants to merge 1 commit into
theskumar:mainfrom
FanWu-ai:fix/ipython-quoted-paths

Conversation

@FanWu-ai

Copy link
Copy Markdown

Summary

IPython's POSIX argument parser preserves the quote characters used to group a filename. As a result, %dotenv "my project/app.env" reports cannot find .env file even when the file exists.

On non-Windows platforms, remove a matching pair of outer single or double quotes before looking up the file. This also lets quoted absolute and ~/ paths reach the existing path-resolution behavior. Backslashes and internal apostrophes are preserved. Windows keeps its existing native argument parsing, including literal apostrophes in filenames.

Tests

  • Integration cases load real relative, absolute, and home-directory paths containing spaces, with both POSIX quote styles and -o. Native Windows still exercises double quotes; unsupported single-quote grouping is expected to raise UsageError without changing the environment.
  • Additional cases cover Windows-style backslashes, internal apostrophes, and an actual filename with literal outer apostrophes. Three simulated Windows post-parser cases verify filenames are preserved unchanged.
  • Ten added regression cases fail against the original source; five added compatibility controls pass before and after the change.
  • Full clean baseline: 288 passed. Final full suite: 303 passed, zero skipped, on Linux/Python 3.12.14. Native Windows execution is left to hosted CI and is not claimed passed.
  • Tox lint (Ruff lint/format and mypy Python targets 3.10 through 3.14), manifest, coverage report, pinned pre-commit hooks, strict MkDocs build, isolated sdist/wheel build, and git diff --check all passed.

AI assistance: prepared and tested with OpenAI Codex, including independent automated review. No human review or hosted CI pass is claimed.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 14, 2026 22:57

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI-assisted POSIX validation at 5632cdc51a81 using Python 3.12.14 and IPython 9.17.1: I invoked the real magic against files whose paths contain spaces, an internal apostrophe, a literal backslash, and literal outer apostrophes. I also checked -- "-o.env" so an option-like filename reaches path resolution without being treated as a flag. All seven calls loaded the expected value.

The literal-backslash case is a useful regression guard for this approach: removing only the matching outer quotes preserves the filename rather than applying an additional shell-style unescape pass. I did not execute native Windows behavior; that remains outside these checks.

This branch has not been deployed

No deployments
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