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

cmd/pyenv-sync: Create major version symlink(s) to fix pyenv support #18978

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Library/Homebrew/cmd/pyenv-sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,31 @@
patch_version = version.patch.to_i

(0..patch_version).each do |patch|
# Create folder symlinks for all patch versions to the latest patch version
# (eg. 3.11.0 -> 3.11.3).
link_path = pyenv_versions/"#{major_version}.#{minor_version}.#{patch}"

# Don't clobber existing user installations.
next if link_path.exist? && !link_path.symlink?

FileUtils.rm_f link_path
FileUtils.ln_sf path, link_path

# Create an unversioned symlinks
# This is what pyenv expects to find in ~/.pyenv/versions/___/bin'.
# Without this, `python3`, `pip3` do not exist and pyenv falls back to system Python.
# (eg. python3 -> python3.11, pip3 -> pip3.11)

executables = %w[python3 pip3 wheel3 idle3 pydoc3]
executables.each do |executable|
major_link_path = link_path/"bin/#{executable}"

Check warning on line 75 in Library/Homebrew/cmd/pyenv-sync.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/pyenv-sync.rb#L73-L75

Added lines #L73 - L75 were not covered by tests

# Don't clobber existing user installations.
next if major_link_path.exist? && !major_link_path.symlink?

FileUtils.rm_f major_link_path
FileUtils.ln_s link_path/"bin/#{executable}.#{minor_version}", major_link_path

Check warning on line 81 in Library/Homebrew/cmd/pyenv-sync.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/pyenv-sync.rb#L80-L81

Added lines #L80 - L81 were not covered by tests
end
end
end
end
Expand Down
Loading