-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Refactor virtualenv bin/
/ Scripts/
path resolution using sysconfig
mechanism
#6373
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
pipenv/utils/virtualenv.py:16
- Consider adding tests for the new virtualenv_scripts_dir function to ensure that script path resolution works correctly across different environments.
PYINFO_CURRENT = PythonInfo.current_system()
@ByteB4rb1e please |
Oh, that's unfortunate. My bad, I didn't check the requirements and just assumed I've tested A quick workaround that comes to mind would be:
So I will see how the internals of that work and compare it to how EDIT: The "workaround" might actually be the most pragmatic and sensible approach as the underlying mechanism is not a public API and I can see a few pitfalls mocking it. |
Reutilizing the mechanism of sysconfig install (path) schemes for determining the path of the scripts/ directory. This allows for determining the scripts/ path without requiring logic dependent on platform identifiers and mitigates issues when being executed from within Cygwin/MinGW environments, as they provide a POSIX(-ish) interface therefore resulting in non-native Windows environment behavior. Fixes: #5978
bin/
/ Scripts/
Path Resolution Using Virtualenv Mechanismbin/
/ Scripts/
path resolution using sysconfig
mechanism
@ByteB4rb1e Would be great if we can get a new test to cover this. Also everything else looked good--please add a news fragment too when you get a chance. |
@matteius, will do! It'll probably have to wait for a couple of days though as I have to take a brief detour. I'm currently setting up another proposal for refactoring the test suite to work locally without the |
0017-sysconfig-treat-MINGW-builds-as-POSIX-builds.patch is the MSYS2 specific patch of CPython's sysconfig I aim to have test coverage for, as this is the strongest deviation from conventional CPython distributions. The patch is indeed a little quirky, but doesn't provoke any unintended behavior for what we're achieving with this refactoring, as we're utilizing a higher-level facility. Actually quite the opposite: The refactoring ensures, that the logic stays intact, even for other unconventional CPython builds that may not exist yet. Just stumbled upon this to figure out what's best to mock... Sadly though, there was a patch introduced which requires special handling in the test case. I've filed a bug report and am hopeful that this can be resolved soon! I will now add parameterization for other platform combinations, then lint, then add the news fragment, as requested by @matteius. |
looks like the tests are failing for a variety of reasons depending on platform and version. |
Ok, wow... I didn't expect it to be this construed. What I'm taking from this is, while the It would be possible to define separate test cases for each platform and just ignore non-applicable ones, but that doesn't sit quite right with me as this wouldn't address testing any future deviations by distributors. EDIT: Ok, half the test failures in regards to I think I will push through with this, trying to analyze the deviations and make the test case work as I intended. It will take some time though as I first have to identify the distributions in use by the CI test and come up with a faster testing setup for debugging. Bear with me, please. I'm hoping to get it done before the next release. |
We have this pattern with |
You're right. I got carried away. I'm just trying to grasp the history of how this issue arose in the first place. But this is the wrong circumstance to do that. Mocking private API functions is a testament to that. Pardon... I'll create the news fragment now and then make sure the changes actually fixed the original problem. |
957934e
to
9c02027
Compare
Test that path are correctly returned on each platform. Added a skipif conditional to correctly execute the test cases with MSYS2 MinGW CPython as well.
I've tested all interactive commands manually, they're working fine. In addition, fixed another fault during the uninstall routine, and fixed the faulty path in the Windows test case. All is seemingly working now. Don't know though why ruff didn't trigger locally...
|
bin/
/ Scripts/
path resolution using sysconfig
mechanismbin/
/ Scripts/
path resolution using sysconfig
mechanism
This fix resolves a faulty path on MSYS2 MinGW CPython, where the bin/ segment is missing altogether. This is required by the uninstall routine. It also simplifies the lookup on all other platforms. As far as I comprehended, the condition in line 255 would never be met, as the joinpath('python') in line 254 guarantees that py will never become a false-equivalent value, since its definition is in the else statement, hence catches the unmatched condition in line 251. I've also inverted the condition of checking for self._python, so that an intermediate assignment to `py` is no longer required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors virtualenv path resolution using sysconfig to dynamically determine the scripts directory (either bin/ or Scripts/) and improves cross-platform compatibility. Key changes include introducing the virtualenv_scripts_dir function, updating tests to cover both Windows and POSIX environments, and refactoring usages in routines and project properties.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/unit/test_utils.py | Added new test cases for asserting expected platform-based path results. |
pipenv/utils/virtualenv.py | Introduced virtualenv_scripts_dir to determine the scripts directory. |
pipenv/routines/shell.py | Updated shell invocation to use virtualenv_scripts_dir for constructing paths. |
pipenv/project.py | Refactored virtualenv existence check and Finder path resolution. |
pipenv/environment.py | Updated python property to derive path using virtualenv_scripts_dir. |
Files not reviewed (1)
- news/6737.bugfix.rst: Language not supported
Comments suppressed due to low confidence (1)
pipenv/utils/virtualenv.py:17
- [nitpick] Consider renaming the parameter 'b' to 'base_path' for improved readability and clarity.
def virtualenv_scripts_dir(b):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your hard work on this change!
This pull request refactors the logic for determining the venv's
scripts/
. orbin/
directory location by leveragingsysconfig
’s built-in mechanism for retrieving the complete global install directory path of scripts and retrieving its basename. This removes any platform-dependent logic and does not require an additional dependency.Changes:
These changes mitigate execution inconsistencies in non-native Windows environments and improve portability across platforms.
Fixes: #5978