Last active
November 10, 2017 22:30
-
-
Save emmanuellyautomated/5801f924423ac09f591fa3c33a9cfa74 to your computer and use it in GitHub Desktop.
If a virtualenv is activated, this will return the full path of the dependency named.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def find_venv_dependency(name): | |
if not hasattr(sys, 'real_prefix'): | |
return # venv not activated | |
venv = sys.prefix.split('/')[len(os.getcwd().split('/'))] | |
for root, dirs, files in os.walk(venv): | |
if name in dirs: | |
return f'{root}/{name}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment