Skip to content

Conversation

@esafak
Copy link
Contributor

@esafak esafak commented Jul 31, 2025

  • Make fs_supports_symlink perform a real symlink creation check on all platforms
  • Add a test case for environments without symlink support and --copies flag
  • Handle missing keys in sysconfig_path to prevent KeyError

Fixes #2786

  • 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

* Make `fs_supports_symlink` perform a real symlink creation check on all platforms
* Add a test case for environments without symlink support and `--copies` flag
* Handle missing keys in `sysconfig_path` to prevent `KeyError`

Fixes pypa#2786
@gaborbernat gaborbernat enabled auto-merge (squash) July 31, 2025 16:01
Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you have macos brew to fix 🤔

@gaborbernat gaborbernat marked this pull request as draft July 31, 2025 16:24
auto-merge was automatically disabled July 31, 2025 16:24

Pull request was converted to draft

google-labs-jules bot and others added 10 commits July 31, 2025 16:36
This commit addresses two main issues:
1.  A bug where creating a virtual environment on a filesystem without symlink support would fail because the check was not robust enough.
2.  A confusing error message when no creation method (symlink or copy) is available.

Summary of changes:
- Modified `fs_supports_symlink` in `src/virtualenv/info.py` to perform a real symlink creation check on all platforms, not just Windows. This ensures that `virtualenv` correctly detects filesystems that do not support symlinks and can fall back to copies.
- Improved the error message in `src/virtualenv/create/via_global_ref/api.py` to be more informative when no creation method is available, showing the reason for each method's failure.
- Added two new tests to `tests/unit/create/test_creator.py`:
    - `test_fallback_to_copies_if_symlink_unsupported`: Verifies that `virtualenv` successfully falls back to using copies when symlinks are not supported on a system that allows copying.
    - `test_fail_gracefully_if_no_method_supported`: Verifies that `virtualenv` raises a detailed `RuntimeError` on systems where both symlinks and copies are disabled.
- Fixed an unrelated bug in `src/virtualenv/discovery/py_info.py` that caused a `KeyError: 'headers'` during test collection in environments without Python development headers.
- Fixed several linter issues.

The changes have been validated by running a focused set of tests, which all passed.
* Mock `is_macos_brew` to return `False` to test the generic fallback case.
* This allows testing the fallback to copies when symlinks are unsupported.
*   Refine test for symlink fallback when copy is unsupported.
*   Ensure the `is_macos_brew` check is correctly applied.
*   Update the error message for brew-related copy failures.
*   Add a skip condition for brew python on macOS to avoid testing unsupported copy scenarios.
@gaborbernat gaborbernat marked this pull request as ready for review July 31, 2025 17:48
@gaborbernat gaborbernat enabled auto-merge (squash) July 31, 2025 17:48
@gaborbernat gaborbernat merged commit 5c6ef7b into pypa:main Jul 31, 2025
42 checks passed
@esafak esafak deleted the fix-symlink-check-and-headers-bug branch July 31, 2025 17:54
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.

creating a virtual environment on a filesystem without symlink-support fails even with --copies

2 participants