Class: LogicaCompiler::Commands::Logica
- Defined in:
- lib/logica_compiler/commands/logica.rb
Constant Summary collapse
- DEFAULT_PYTHON =
"python3"
Instance Method Summary collapse
- #default_venv_logica_path(config) ⇒ Object
- #ensure_available!(config, allow_install:) ⇒ Object
- #install_venv_logica!(config) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from LogicaCompiler::Commands::Base
Instance Method Details
#default_venv_logica_path(config) ⇒ Object
33 34 35 |
# File 'lib/logica_compiler/commands/logica.rb', line 33 def default_venv_logica_path(config) config.root.join("tmp/logica_venv", Util.venv_bin_dir, "logica") end |
#ensure_available!(config, allow_install:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/logica_compiler/commands/logica.rb', line 14 def ensure_available!(config, allow_install:) bin = config.logica_bin.to_s if Util.path_like?(bin) return if File.executable?(bin) if allow_install && bin == default_venv_logica_path(config).to_s install_venv_logica!(config) return if File.executable?(bin) end raise LogicaError, "Logica CLI not found: #{bin.inspect}" end return if which.call(bin) raise LogicaError, "Logica CLI #{bin.inspect} not found on PATH. Run `bin/logica install` or set LOGICA_BIN." end |
#install_venv_logica!(config) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/logica_compiler/commands/logica.rb', line 37 def install_venv_logica!(config) python = env.fetch("LOGICA_PYTHON", DEFAULT_PYTHON) requirements = Pathname(env.fetch("LOGICA_REQUIREMENTS", config.requirements_path.to_s)) venv_dir = Pathname(env.fetch("LOGICA_VENV", config.root.join("tmp/logica_venv").to_s)) raise LogicaError, "#{python} not found. Install Python 3 and try again." unless which.call(python) raise LogicaError, "requirements not found: #{requirements}" unless requirements.exist? FileUtils.mkdir_p(venv_dir.parent) shell.system!(python, "-m", "venv", venv_dir.to_s) unless venv_dir.exist? stamp = venv_dir.join(".requirements.sha256") req_sha = Digest::SHA256.hexdigest(requirements.read) return if stamp.exist? && stamp.read.strip == req_sha venv_python = venv_dir.join(Util.venv_bin_dir, "python").to_s shell.system!(venv_python, "-m", "pip", "install", "--upgrade", "pip") shell.system!(venv_python, "-m", "pip", "install", "-r", requirements.to_s) stamp.write(req_sha) end |