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

Add PKG_CONFIG_PATH to variables set by venv activate #2637

Open
cptlobster opened this issue Sep 5, 2023 · 1 comment
Open

Add PKG_CONFIG_PATH to variables set by venv activate #2637

cptlobster opened this issue Sep 5, 2023 · 1 comment

Comments

@cptlobster
Copy link

cptlobster commented Sep 5, 2023

What's the problem this feature will solve?

pkg-config doesn't recognize packages that are installed in a virtual environment

Describe the solution you'd like

A solution was proposed 5 years ago in #1159 which was closed for being stale. The changes proposed here (for Bash, I'm unfamiliar with any other shells so I can't attest to how those would be configured):

diff --git a/virtualenv_embedded/activate.sh b/virtualenv_embedded/activate.sh
index 477b7ec..1a93da9 100644
--- a/virtualenv_embedded/activate.sh
+++ b/virtualenv_embedded/activate.sh
@@ -16,6 +16,11 @@ deactivate () {
         export PYTHONHOME
         unset _OLD_VIRTUAL_PYTHONHOME
     fi
+    if ! [ -z "${_OLD_PKG_CONFIG_PATH+_}" ]; then
+        PKG_CONFIG_PATH="$_OLD_PKG_CONFIG_PATH"
+        export PKG_CONFIG_PATH
+        unset _OLD_PKG_CONFIG_PATH
+    fi

     # This should detect bash and zsh, which have a hash command that must
     # be called to get it to forget past commands.  Without forgetting
@@ -47,6 +52,10 @@ _OLD_VIRTUAL_PATH="$PATH"
 PATH="$VIRTUAL_ENV/__BIN_NAME__:$PATH"
 export PATH

+_OLD_PKG_CONFIG_PATH="${PKG_CONFIG_PATH}"
+PKG_CONFIG_PATH="${VIRTUAL_ENV}/lib/pkgconfig:${PKG_CONFIG_PATH}"
+export PKG_CONFIG_PATH
+
 # unset PYTHONHOME if set
 if ! [ -z "${PYTHONHOME+_}" ] ; then
     _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"

This would work for libraries that use pkg-config for build/install (so far the only example I have is python-efl, possibly also Qt per this thread)

Alternative Solutions

I've tried adding the proposed modifications to {VIRTUALENV}/bin/activate myself, it seems to function as intended.

Additional context

@gaborbernat
Copy link
Contributor

PR welcome. Must include support for all supported shells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@gaborbernat @cptlobster and others