Skip to content

feat: Add PKG_CONFIG_PATH to venv activation scripts - #2915

Closed
esafak wants to merge 4 commits into
pypa:mainfrom
esafak:feature/pkg-config-path
Closed

feat: Add PKG_CONFIG_PATH to venv activation scripts#2915
esafak wants to merge 4 commits into
pypa:mainfrom
esafak:feature/pkg-config-path

Conversation

@esafak

@esafak esafak commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@esafak

esafak commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

I'll try again

@esafak esafak closed this Aug 14, 2025
@esafak
esafak deleted the feature/pkg-config-path branch August 14, 2025 04:12
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