Class: Dependabot::Python::FileUpdater::PipfilePreparer

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/python/file_updater/pipfile_preparer.rb

Instance Method Summary collapse

Constructor Details

#initialize(pipfile_content:) ⇒ PipfilePreparer

Returns a new instance of PipfilePreparer.



15
16
17
# File 'lib/dependabot/python/file_updater/pipfile_preparer.rb', line 15

def initialize(pipfile_content:)
  @pipfile_content = pipfile_content
end

Instance Method Details

#replace_sources(credentials) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/dependabot/python/file_updater/pipfile_preparer.rb', line 19

def replace_sources(credentials)
  pipfile_object = TomlRB.parse(pipfile_content)

  pipfile_object["source"] =
    pipfile_sources.filter_map { |h| sub_auth_url(h, credentials) } +
    config_variable_sources(credentials)

  TomlRB.dump(pipfile_object)
end

#update_python_requirement(requirement) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dependabot/python/file_updater/pipfile_preparer.rb', line 29

def update_python_requirement(requirement)
  pipfile_object = TomlRB.parse(pipfile_content)

  pipfile_object["requires"] ||= {}
  if pipfile_object.dig("requires", "python_full_version") && pipfile_object.dig("requires", "python_version")
    pipfile_object["requires"].delete("python_full_version")
  elsif pipfile_object.dig("requires", "python_full_version")
    pipfile_object["requires"].delete("python_full_version")
    pipfile_object["requires"]["python_version"] = requirement
  end
  TomlRB.dump(pipfile_object)
end

#update_ssl_requirement(parsed_file) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dependabot/python/file_updater/pipfile_preparer.rb', line 42

def update_ssl_requirement(parsed_file)
  pipfile_object = TomlRB.parse(pipfile_content)
  parsed_object = TomlRB.parse(parsed_file)

  # we parse the verify_ssl value from manifest if it exists
  verify_ssl = parsed_object["source"].map { |x| x["verify_ssl"] }.first

  # provide a default "true" value to file generator in case no value is provided in manifest file
  pipfile_object["source"].each do |key|
    key["verify_ssl"] = verify_ssl.nil? ? true : verify_ssl
  end

  TomlRB.dump(pipfile_object)
end