Class: LicenseFinder::Conda

Inherits:
PackageManager show all
Defined in:
lib/license_finder/package_managers/conda.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PackageManager

#active?, #command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #package_management_command, #project_root?, takes_priority_over

Constructor Details

#initialize(options = {}) ⇒ Conda

Returns a new instance of Conda.



9
10
11
12
# File 'lib/license_finder/package_managers/conda.rb', line 9

def initialize(options = {})
  @conda_bash_setup_script = options[:conda_bash_setup_script] || Pathname("#{ENV['HOME']}/miniconda3/etc/profile.d/conda.sh")
  super
end

Instance Attribute Details

#conda_bash_setup_scriptObject (readonly)

Returns the value of attribute conda_bash_setup_script.



7
8
9
# File 'lib/license_finder/package_managers/conda.rb', line 7

def conda_bash_setup_script
  @conda_bash_setup_script
end

Instance Method Details

#current_packagesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/license_finder/package_managers/conda.rb', line 30

def current_packages
  conda_list.map do |entry|
    case entry['channel']
    when 'pypi'
      # PyPI is much faster than `conda search`, use it when we can.
      PipPackage.new(entry['name'], entry['version'], PyPI.definition(entry['name'], entry['version']))
    else
      CondaPackage.new(conda_search_info(entry))
    end
  end.compact
end

#possible_package_pathsObject



42
43
44
# File 'lib/license_finder/package_managers/conda.rb', line 42

def possible_package_paths
  [project_path.join('environment.yaml'), project_path.join('environment.yml')]
end

#prepareObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/license_finder/package_managers/conda.rb', line 19

def prepare
  return if environment_exists?

  prep_cmd = prepare_command
  _stdout, stderr, status = Dir.chdir(project_path) { conda(prep_cmd) }
  return if status.success?

  log_errors stderr
  raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail
end

#prepare_commandObject

This command is not directly executable. See .conda() below.



15
16
17
# File 'lib/license_finder/package_managers/conda.rb', line 15

def prepare_command
  "conda env create -f #{detected_package_path}"
end