Class: Legion::CLI::Doctor::PythonEnvCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/cli/doctor/python_env_check.rb

Instance Method Summary collapse

Instance Method Details

#fixObject



61
62
63
# File 'lib/legion/cli/doctor/python_env_check.rb', line 61

def fix
  system('legionio', 'setup', 'python', '--rebuild')
end

#nameObject



11
12
13
# File 'lib/legion/cli/doctor/python_env_check.rb', line 11

def name
  'Python env'
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/cli/doctor/python_env_check.rb', line 15

def run
  return skip_result('python3 not found') unless Legion::Python.find_system_python3
  unless Legion::Python.venv_exists?
    return warn_result(
      'Python venv missing',
      'Run: legionio setup python',
      auto_fixable: true
    )
  end

  unless Legion::Python.venv_pip_exists?
    return warn_result(
      'pip not found in venv — venv may be corrupt',
      'Run: legionio setup python --rebuild',
      auto_fixable: true
    )
  end

  unless Legion::Python.venv_python_exists?
    return warn_result(
      'python3 not found in venv — venv may be corrupt',
      'Run: legionio setup python --rebuild',
      auto_fixable: true
    )
  end

  missing = missing_packages
  if missing.any?
    return warn_result(
      "Missing packages: #{missing.join(', ')}",
      'Run: legionio setup python',
      auto_fixable: true
    )
  end

  pass_result(venv_summary)
rescue StandardError => e
  Legion::Logging.error("PythonEnvCheck#run: #{e.message}") if defined?(Legion::Logging)
  Result.new(
    name:         name,
    status:       :fail,
    message:      "Python env check error: #{e.message}",
    prescription: 'Run: legionio setup python'
  )
end