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 a way to consistently run scripts that require project root relative paths

See original GitHub issue

Is your feature request related to a problem? Please describe. The pipenv run is really handy. But it requires a good deal of work to actually make it work for situations where your current directory is not the same as where the Pipenv file is located.

Just for something like using it as a shorthand for running your python application that requires setting the PYTHONPATH environment variable. It it is tricky to figure out what to actually set it to. And while it can be made easier by wrapping it in a shell script. Informing Pipenv where said script is located also becomes tricky

Describe the solution you’d like The most simple solution I can think of would be having en environment variable (say, PIPENV_PROJECT_ROOT). And could be used in places like the scripts section of Pipfile. And in scripts run from it.

Describe alternatives you’ve considered For my problem it would also have been nice with a way to have Pipenv update the PYTHONPATH environment variable to include a path relative to the project root. But just having the project root in the environment would likely solve more use cases

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
laktakcommented, Aug 2, 2019

With pipenv-shebang you can run your script by inserting the shebang

#!/usr/bin/env pipenv-shebang

or you could run it with pipenv-shebang PATH/SCRIPT directly.

3reactions
uranusjrcommented, Aug 24, 2018

This is probably simpler

pushd /path/to/tool
PYTHON="$(pipenv --venv)/bin/python"
popd
"$PYTHON" "/path/to/tool/tool.py"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple trick to work with relative paths in Python | by Mike Huls
The trick is to define a variable that calculate the absolute path to our root in a file and then import this variable...
Read more >
Project root based relative paths for NodeJS modules
I know I can resolve the path of any external module using require.resolve() and I though I could do something like path.dirname(path.dirname( ...
Read more >
escaping relative path require hell in Node.js - Corey Cleary
require () wrapper​​ - to ensure this. So code with relative paths becomes: const add = requireWrapper('helpers/operations/add'); add(2, 3); Rather than something ...
Read more >
How to use Relative Paths in Run/Debug Configurations?
1) Define the location of the Mocha tool relative to the working directory. This is important when using different mocha versions and -- ......
Read more >
Relative and absolute paths, in the file system and on the web ...
For the browser, this path is perfectly absolute, starting from the root of the web-server. Whereas for the script it's only a part...
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