Skip to content

feat: Add PKG_CONFIG_PATH to venv activation scripts #2915

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

esafak
Copy link
Contributor

@esafak esafak commented Jul 31, 2025

This change adds support for pkg-config to virtualenv by adding the virtual environment's lib/pkgconfig directory to the PKG_CONFIG_PATH environment variable upon activation.

This is done for all supported shells:

  • Bash (activate.sh)
  • Batch (activate.bat, deactivate.bat)
  • C Shell (activate.csh)
  • Fish (activate.fish)
  • Nushell (activate.nu)
  • PowerShell (activate.ps1)
  • Python (activate_this.py)

The implementation follows the style of the existing activation scripts for each shell, saving the original PKG_CONFIG_PATH on activation and restoring it on deactivation.

Unit tests for each shell's activation have been updated to verify that PKG_CONFIG_PATH is set and unset correctly.

Fixes #2637

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

This change adds support for `pkg-config` to virtualenv by adding the virtual environment's `lib/pkgconfig` directory to the `PKG_CONFIG_PATH` environment variable upon activation.

This is done for all supported shells:
- Bash (`activate.sh`)
- Batch (`activate.bat`, `deactivate.bat`)
- C Shell (`activate.csh`)
- Fish (`activate.fish`)
- Nushell (`activate.nu`)
- PowerShell (`activate.ps1`)
- Python (`activate_this.py`)

The implementation follows the style of the existing activation scripts for each shell, saving the original `PKG_CONFIG_PATH` on activation and restoring it on deactivation.

Unit tests for each shell's activation have been updated to verify that `PKG_CONFIG_PATH` is set and unset correctly.

Fixes pypa#2637
gaborbernat
gaborbernat previously approved these changes Jul 31, 2025
@gaborbernat gaborbernat enabled auto-merge (squash) July 31, 2025 16:23
The activation scripts for bash and fish did not correctly handle the
`PKG_CONFIG_PATH` environment variable when it was initially unset.
This caused the variable to be set to an empty string after
deactivation, instead of being unset.

This commit fixes the activation scripts to correctly save and restore
the `PKG_CONFIG_PATH`, and adds tests to verify the behavior.
auto-merge was automatically disabled July 31, 2025 17:42

Head branch was pushed to by a user without write access

@gaborbernat gaborbernat marked this pull request as draft July 31, 2025 17:46
The activation scripts for bash, fish, nushell, and powershell did not
correctly handle the `PKG_CONFIG_PATH` environment variable when it was
initially unset. This caused the variable to be set to an empty string
after deactivation, instead of being unset.

This commit fixes the activation scripts to correctly save and restore
the `PKG_CONFIG_PATH`, and adds tests to verify the behavior. This
ensures that the environment is restored to its original state after
deactivation.
The activation scripts for bash, fish, nushell, powershell, and batch
did not correctly handle the `PKG_CONFIG_PATH` environment variable when
it was initially unset. This caused the variable to be set to an empty
string after deactivation, instead of being unset.

This commit fixes the activation scripts to correctly save and restore
the `PKG_CONFIG_PATH`, and adds tests to verify the behavior. This
ensures that the environment is restored to its original state after
deactivation.
@esafak esafak closed this Aug 1, 2025
@esafak esafak deleted the feature/pkg-config-path branch August 1, 2025 01:29
@esafak esafak restored the feature/pkg-config-path branch August 1, 2025 01:29
@esafak esafak reopened this Aug 1, 2025
@gaborbernat
Copy link
Contributor

Marked this as a draft for now 🚧—let’s get the CI sorted, and then feel free to mark it ready for review! 😊

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

Successfully merging this pull request may close these issues.

Add PKG_CONFIG_PATH to variables set by venv activate
2 participants