Skip to content

Commit

Permalink
Handle situations where the cwd does not exist. (#446)
Browse files Browse the repository at this point in the history
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 <tanner.jc@gmail.com>
  • Loading branch information
jctanner committed Feb 23, 2023
1 parent b904a72 commit fc19a55
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/dotenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@
from .version import __version__


def enumerate_env():
"""
Return a path for the ${pwd}/.env file.
If pwd does not exist, return None.
"""
try:
cwd = os.getcwd()
except FileNotFoundError:
return None
path = os.path.join(cwd, '.env')
return path


@click.group()
@click.option('-f', '--file', default=os.path.join(os.getcwd(), '.env'),
@click.option('-f', '--file', default=enumerate_env(),
type=click.Path(file_okay=True),
help="Location of the .env file, defaults to .env file in current working directory.")
@click.option('-q', '--quote', default='always',
Expand Down

0 comments on commit fc19a55

Please sign in to comment.