Provide an environment variable pointing to the project root
See original GitHub issueIs your feature request related to a problem? Please describe.
I’m working on a few projects that are configured using environment variables, thus I was quite happy that the .env
file for setting them exists. While this works great for most environment variables, it becomes cumbersome as soon as I need to specify a path relative to the project root. My naive approach was:
VARIABLE=${PWD}/some_directory
As long as pipenv run/shell
is run from the project root directory, this works great. But if pipenv run/shell
is run from a subdirectory of the project root, this does not work any longer, because PWD
points to the wrong directory in this case. By the way, this also spoils the joy of using pipes to go to your project directory, because the PWD
variable still points to the current directory (e.g., ~
) when the .env
file is evaluated.
Describe the solution you’d like
I’d like to have an environment variable pointing to the project directory set before the .env
file is parsed, e.g., something like PIPENV_PROJECT
, so the following assignment in .env
would work as expected irrespective of the current working directory:
VARIABLE=${PIPENV_PROJECT}/some_directory
It would certainly do no harm if this variable would be available not only for parsing the .env
file, but also for the shell or for the command started using pipenv as well.
Describe alternatives you’ve considered
The obvious alternative I found is putting absolute paths into the .env
file. But then I can’t add that file to version control, which is the main reason for me wanting to use it in the first place.
Additional context
I’m using pipenv 2018.7.1 installed via pip on a CentOS 7 machine.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top GitHub Comments
@Dylan-Brotherston While
pipenv --where
works fine in general, it is not working inside the.env
file. The.env
file is not evaluated by a shell, but by python-dotenv. Although python-dotenv allows the use of simple nested variables (like inVARIABLE=${pwd}/somedirectory
), it does not support command substitution.@rschwarzkopf, there already is a solution for this problem.
pipenv --where
will return the projects root dir. So you can useVARIABLE=$(pipenv --where)/some_directory
to get what you want.