Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to find .env.vault #13

Merged
merged 8 commits into from
Aug 5, 2023
Merged

allow to find .env.vault #13

merged 8 commits into from
Aug 5, 2023

Conversation

nsnguyen
Copy link
Collaborator

@nsnguyen nsnguyen commented Jul 12, 2023

this allows to search for .env.vault anywhere in the app.

@nsnguyen nsnguyen requested a review from motdotla July 12, 2023 07:19
@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch 2 times, most recently from 1e5781c to 43ed0d1 Compare July 12, 2023 07:33
@@ -11,6 +11,9 @@
import dotenv.main as dotenv


DOTENV_VAULT_PATH = dotenv.find_dotenv(".env.vault")
Copy link
Member

Choose a reason for hiding this comment

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

change this to instead find the .env file and then find the .env.vault file right next to it.

That would then match user's expected behavior more closely. This is what the node lib does.

https://github.com/motdotla/dotenv/blob/master/lib/main.js#L152

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@motdotla , made a new change. It should look for .env first, and expect .env.vault to be in same directory. Else, it will scream at you

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 5e2af23 to 1a0ce86 Compare July 15, 2023 04:31
return path
path = os.path.dirname(path)
if '.env.vault' not in os.listdir(path):
raise FileNotFoundError('.env.vault is not in same directory as .env')
Copy link
Member

Choose a reason for hiding this comment

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

it shouldn't stacktrace fail.

on local development someone might be using this library and not have a .env.vault file. that's ok. it should fallback to dotenv.

this should have messaging like the dotenv lib:

https://github.com/motdotla/dotenv/blob/master/lib/main.js#L228

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@motdotla , okay it should default to .env

@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 1a0ce86 to 35f3545 Compare July 19, 2023 06:06
src/dotenv_vault/__version__.py Outdated Show resolved Hide resolved
path = os.path.dirname(path)
if '.env.vault' not in os.listdir(path):
# we fall back to .env
logger.warning("No .env.vault file found. Falling back to .env")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 48bb438 to 508d7e5 Compare July 27, 2023 06:35
Copy link
Member

@motdotla motdotla left a comment

Choose a reason for hiding this comment

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

one last change!

CHANGELOG.md Outdated

### Changed

- Allow to place .env.vault file anywhere in app [#13](https://github.com/dotenv-org/python-dotenv-vault/pull/13)
Copy link
Member

Choose a reason for hiding this comment

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

Update message to:

Look for .env.vault file at same location as .env file. Finds .env file anywhere in app (just like original python lib)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed!

@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 508d7e5 to 22c19c5 Compare July 28, 2023 07:41
CHANGELOG.md Outdated
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. See [standa

## [Unreleased](https://github.com/dotenv-org/python-dotenv-vault/compare/v0.5.1...master)

## 0.7.0
Copy link
Member

Choose a reason for hiding this comment

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

This should be a 0.6.1 patch rather than a minor upgrade.

@@ -1 +1 @@
from .main import load_dotenv
from .main import load_dotenv, load_dotenv_vault
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be exposed to the developer as a public method.

https://github.com/motdotla/dotenv/blob/master/lib/main.js#L167

usage for developer should not ever change. just load_dotenv and it is smart enough to determine to load .env.vault or .env depending if DOTENV_KEY is set or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 i removed load_dotenvv_ault

Copy link
Member

Choose a reason for hiding this comment

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

looks like it is still there?? in __int__.py ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops! Forgot to push 😎

@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 4944f86 to 5d15763 Compare August 1, 2023 04:30
@nsnguyen nsnguyen force-pushed the find-dotenv-vault-file branch from 5d15763 to 80361df Compare August 1, 2023 04:35
Copy link
Member

@motdotla motdotla left a comment

Choose a reason for hiding this comment

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

just the change in __init__.py and then this is ready to go

# we fall back to .env
logger.warning(f"You set DOTENV_KEY but you are missing a .env.vault file at {path}. Did you forget to build it?")
return f"{path}/.env"
return f"{path}/.env.vault"
Copy link
Member

Choose a reason for hiding this comment

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

looks good here 👍

CHANGELOG.md Outdated

### Changed

- Look for .env.vault file at same location as .env file. Finds .env file anywhere in app (just like original python lib) [#13](https://github.com/dotenv-org/python-dotenv-vault/pull/13)
Copy link
Member

Choose a reason for hiding this comment

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

One more nitpick. This comment should be under 0.6.1 and the one above should be under 0.6.2. Then this PR should be ready to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay, i switched this around @motdotla . It should be in correct place now

@motdotla motdotla merged commit 8d78a70 into master Aug 5, 2023
@motdotla motdotla deleted the find-dotenv-vault-file branch August 5, 2023 06:51
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