Class: Homebrew::Cmd::PyenvSync

Inherits:
AbstractCommand show all
Defined in:
cmd/pyenv-sync.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'cmd/pyenv-sync.rb', line 22

def run
  pyenv_root = Pathname(ENV.fetch("HOMEBREW_PYENV_ROOT", Pathname(Dir.home)/".pyenv"))

  # Don't run multiple times at once.
  pyenv_sync_running = pyenv_root/".pyenv_sync_running"
  return if pyenv_sync_running.exist?

  begin
    pyenv_versions = pyenv_root/"versions"
    pyenv_versions.mkpath
    FileUtils.touch pyenv_sync_running
    HOMEBREW_CELLAR.glob("python{,@*}")
                   .flat_map(&:children)
                   .each { |path| link_pyenv_versions(path, pyenv_versions) }

    pyenv_versions.children
                  .select(&:symlink?)
                  .reject(&:exist?)
                  .each { |path| FileUtils.rm_f path }
  ensure
    pyenv_sync_running.unlink if pyenv_sync_running.exist?
  end
end