Skip to content

Commit fc19a55

Browse files
authored
Handle situations where the cwd does not exist. (#446)
This is seen in some situations with dynaconf where the system under test starts from a src code directory that got moved around or deleted during operation. Signed-off-by: James Tanner <[email protected]>
1 parent b904a72 commit fc19a55

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/dotenv/cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@
1717
from .version import __version__
1818

1919

20+
def enumerate_env():
21+
"""
22+
Return a path for the ${pwd}/.env file.
23+
24+
If pwd does not exist, return None.
25+
"""
26+
try:
27+
cwd = os.getcwd()
28+
except FileNotFoundError:
29+
return None
30+
path = os.path.join(cwd, '.env')
31+
return path
32+
33+
2034
@click.group()
21-
@click.option('-f', '--file', default=os.path.join(os.getcwd(), '.env'),
35+
@click.option('-f', '--file', default=enumerate_env(),
2236
type=click.Path(file_okay=True),
2337
help="Location of the .env file, defaults to .env file in current working directory.")
2438
@click.option('-q', '--quote', default='always',

0 commit comments

Comments
 (0)