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

Adding automatic loading of .env file #339

Closed
wants to merge 7 commits into from
Closed

Adding automatic loading of .env file #339

wants to merge 7 commits into from

Conversation

MarcDufresne
Copy link
Contributor

@MarcDufresne MarcDufresne commented Jul 26, 2018

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

This is in support of #337, it doesn't include tests but I didn't find any for the run and shell command. I'll defer to your decision on if I should add tests, what kind of test, or if it can wait.

I feel like eventually a config value to change the name of the file to load instead of hardcoding .env could be nice but may not be needed now.

workdir_path = Path(os.getcwd())
env_file_path = workdir_path / ".env"
if env_file_path.is_file():
load_dotenv(env_file_path)
Copy link

@ptink ptink Jul 27, 2018

Choose a reason for hiding this comment

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

Might be overthinking it but if we did something like

read_dotenv = dotenv.get_key(env_file_path, 'POETRY_READ_DOTENV')
if read_dotenv is None or read_dotenv.lower() not in ('false', 'n', 'no', 'off', '0'):
    load_dotenv(env_file_path)

This gives users a way to turn off reading the .env file into the os.environ on a per-directory basis even if we have a global setting that turns it on?



def load_dotenv_if_exists():
workdir_path = Path(os.getcwd())
Copy link

Choose a reason for hiding this comment

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

I think it's worth adding a settings.commands.dotenv (or better named) config setting here- as you suggested it would let people set it to an alternative filename (i.e. poetry.env). setting it to empty / false could turn it off globally?

@ptink
Copy link

ptink commented Jul 29, 2018

lgtm 👍

@pkulev
Copy link
Contributor

pkulev commented Aug 27, 2018

Maybe rebase is better than merging develop? It makes history much cleaner.

$ git remote update
$ git rebase -i upstream/develop

@lorinkoz
Copy link

lorinkoz commented Jan 8, 2019

Hey, what's the status of this?

@sdispater
Copy link
Member

Closing this since I have mentioned in #337 that this is beyond the scope of Poetry

@sdispater sdispater closed this Mar 6, 2019
@flyte flyte mentioned this pull request Jun 3, 2020
1 task
Copy link

github-actions bot commented Mar 1, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants