python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

Documentation should make clear what path formats for --file are allowed

Open jkopczyn opened this issue 3 years ago • 4 comments

As best as I can determine, only absolute paths (not even permitting ~) work for the -f/--file option, which is not mentioned either in the documentation or in the output of --help. Mentioning that would be helpful.

jkopczyn avatar Nov 10 '21 20:11 jkopczyn

Yes, this is a big problem. Now I can't use this module.

Tanami avatar Nov 11 '21 02:11 Tanami

It is possible to use the os module to get the current working directory with os.getcwd(). os.path.join() can be used to go down a directory tree. Documentation on this can be found here

ethsanders avatar Nov 13 '21 17:11 ethsanders

That's not actually relevant. It doesn't matter that there's a workaround for the undocumented requirements. The problem is that the requirements are undocumented.

jkopczyn avatar Dec 13 '21 20:12 jkopczyn

I tried to reproduce the problem but couldn't: everything seems to be working well on my side. Could you provide us with more information about how trigger this issue?

dotenv --file /path/to/env/file set foo bar should work with relative and absolute paths. It should also work with paths containing ~ since this symbol should be translated by your shell (e.g. Bash) into an absolute path before it is passed to the dotenv executable.

bbc2 avatar Dec 14 '21 11:12 bbc2

I think I was able to reproduce the error! To me, it happens only when using --file=~/path/to/file:

$ dotenv --file=~/git/3rd_party/python-dotenv/test1.env get USER
Usage: dotenv get [OPTIONS] KEY
Try 'dotenv get --help' for help.

Error: Invalid value: Path "~/git/3rd_party/python-dotenv/test1.env" does not exist.

Without the ~ alias, it seems to work:

$ dotenv --file=/home/jubileu/git/3rd_party/python-dotenv/test1.env get USER
user
jubileu@DESKTOP-TPKL2CF:~/git/3rd_party/python-dotenv$ dotenv --file=test1.env get USER
user
jubileu@DESKTOP-TPKL2CF:~/git/3rd_party/python-dotenv$ dotenv --file=./test1.env get USER
user

Using different approaches to write the file argument works with ~:

$ dotenv -f ~/git/3rd_party/python-dotenv/test1.env get USER
user
$ dotenv --file ~/git/3rd_party/python-dotenv/test1.env get USER
user

duarte-pompeu avatar Oct 09 '22 12:10 duarte-pompeu

But I wondered if this is a problem with parsing from bash itself: it seems so. Here's an example where grep fails with --file=~/path/to/file:

# grep allows defining patterns from a file
$ grep --help | grep -- '--file'
 -f, --file=FILE           take PATTERNS from FILE
 -L, --files-without-match  print only names of FILEs with no selected lines
 -l, --files-with-matches  print only names of FILEs with selected lines

# let's write them into patterns.txt
$ cat patterns.txt 
user

# success: let's use them to grab 'user' from test1.env using `--file ~/path/to/file`
$ grep test1.env --file ~/git/3rd_party/python-dotenv/patterns.txt 
USER="user"

# failure: let's try using `--file=~/path/to/file`
$ grep test1.env --file=~/git/3rd_party/python-dotenv/patterns.txt 
grep: ~/git/3rd_party/python-dotenv/patterns.txt: No such file or directory

duarte-pompeu avatar Oct 09 '22 12:10 duarte-pompeu