fix: accept a FIFO .env file in dotenv run - #723
Open
sungbin1015 wants to merge 1 commit into
Open
sungbin1015 wants to merge 1 commit into
sungbin1015 wants to merge 1 commit into
Conversation
`dotenv run` guarded the path with `os.path.isfile`, so a `.env` that is a named pipe (1Password-mounted `.env`, `<(...)` process substitution) was rejected with "does not exist", while `load_dotenv` and `dotenv list`/`get` read it. Use `_is_file_or_fifo`, as `DotEnv._get_stream` and `find_dotenv` do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
dotenv runrejects a.envpath that is a FIFO, although the library (load_dotenv,dotenv_values,find_dotenv, since #586) and thelist/getsubcommands read it fine:The same happens with a named pipe created by
mkfifoand picked up as the default./.env, which is the 1Password-mounted.envcase #586 was written for:load_dotenv()works there,dotenv run -- cmddoes not.Cause
runguards the path withos.path.isfile(file)before handing it toDotEnv.DotEnv._get_streamandfind_dotenvuse_is_file_or_fifoinstead; the guard incli.pywas not updated when FIFO support was added.Fix
Use
_is_file_or_fifoin therunguard. Missing paths and directories are still rejected with the same message. No change on Windows, where_is_file_or_fifois equivalent toos.path.isfile.Tests
tests/test_fifo_dotenv.py::test_cli_run_from_fifo(Unix only, like the existing FIFO test): fails before the change with the error above, passes after.pytest: 285 passed, 4 skipped.ruff check src tests,ruff format --check src testsandmypyfor 3.10-3.14 are clean.Related work
runpath, which Support reading .env from FIFOs (Unix) #586 did not cover.src/dotenv/main.pyfor FIFOs that are not immediately readable. It does not touchcli.py, sodotenv runwould still reject a FIFO with it applied.cli.py, but for a different problem (when the default.envpath is resolved).