question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide an environment variable pointing to the project root

See original GitHub issue
Is 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rschwarzkopfcommented, Sep 13, 2018

@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 in VARIABLE=${pwd}/somedirectory), it does not support command substitution.

1reaction
Dylan-Brotherstoncommented, Sep 10, 2018

@rschwarzkopf, there already is a solution for this problem. pipenv --where will return the projects root dir. So you can use VARIABLE=$(pipenv --where)/some_directory to get what you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Project specific root path environment variable?
To solve this issue I am thinking to use relative paths to the project's absolute root path.
Read more >
How do I set persistent environment variables for root?
Like the process you define your own environment variable, for example by editing '~/.bashrc', you can define root's environment variable by editing '/root/....
Read more >
Why configure environment variables per project - Eric J. Ma
To configure environment variables for your project, a recommended practice is to create a .env file in your project's root directory, which stores...
Read more >
Add content root - is it possible to use env vars in paths?
PyCharm), you can define a path variable pointing to the root of th repo. Then the content root will be stored relative to...
Read more >
What are PATH and other environment variables, and how ...
Any file in /etc/paths.d — commonly used by installers to make the executable files they provide available from the shell without touching ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found