Port Homebrew::Cmd::PyenvSync

This commit is contained in:
Douglas Eichelberger 2024-04-01 10:00:07 -07:00
parent 427b527335
commit 6c260db277
2 changed files with 55 additions and 49 deletions

View File

@ -1,15 +1,13 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "abstract_command"
require "formula" require "formula"
module Homebrew module Homebrew
module_function module Cmd
class PyenvSync < AbstractCommand
sig { returns(CLI::Parser) } cmd_args do
def pyenv_sync_args
Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
Create symlinks for Homebrew's installed Python versions in `~/.pyenv/versions`. Create symlinks for Homebrew's installed Python versions in `~/.pyenv/versions`.
@ -19,10 +17,9 @@ module Homebrew
named_args :none named_args :none
end end
end
sig { void } sig { override.void }
def pyenv_sync def run
pyenv_root = Pathname(ENV.fetch("HOMEBREW_PYENV_ROOT", Pathname(Dir.home)/".pyenv")) pyenv_root = Pathname(ENV.fetch("HOMEBREW_PYENV_ROOT", Pathname(Dir.home)/".pyenv"))
# Don't run multiple times at once. # Don't run multiple times at once.
@ -33,9 +30,6 @@ module Homebrew
pyenv_versions = pyenv_root/"versions" pyenv_versions = pyenv_root/"versions"
pyenv_versions.mkpath pyenv_versions.mkpath
FileUtils.touch pyenv_sync_running FileUtils.touch pyenv_sync_running
pyenv_sync_args.parse
HOMEBREW_CELLAR.glob("python{,@*}") HOMEBREW_CELLAR.glob("python{,@*}")
.flat_map(&:children) .flat_map(&:children)
.each { |path| link_pyenv_versions(path, pyenv_versions) } .each { |path| link_pyenv_versions(path, pyenv_versions) }
@ -49,6 +43,8 @@ module Homebrew
end end
end end
private
sig { params(path: Pathname, pyenv_versions: Pathname).void } sig { params(path: Pathname, pyenv_versions: Pathname).void }
def link_pyenv_versions(path, pyenv_versions) def link_pyenv_versions(path, pyenv_versions)
pyenv_versions.mkpath pyenv_versions.mkpath
@ -66,3 +62,5 @@ module Homebrew
end end
end end
end end
end
end

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
require "cmd/pyenv-sync"
require "cmd/shared_examples/args_parse"
RSpec.describe Homebrew::Cmd::PyenvSync do
it_behaves_like "parseable arguments"
end