Class: Dependabot::Uv::FileUpdater::PyprojectPreparer

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/uv/file_updater/pyproject_preparer.rb

Constant Summary collapse

Credentials =
T.type_alias { T::Array[T::Hash[String, String]] }

Instance Method Summary collapse

Constructor Details

#initialize(pyproject_content:, lockfile: nil) ⇒ PyprojectPreparer

Returns a new instance of PyprojectPreparer.



23
24
25
26
27
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 23

def initialize(pyproject_content:, lockfile: nil)
  @pyproject_content = pyproject_content
  @lockfile = lockfile
  @lines = T.let(pyproject_content.split("\n"), T::Array[String])
end

Instance Method Details

#add_auth_env_vars(credentials) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 48

def add_auth_env_vars(credentials)
  return unless credentials

  credentials.each do |credential|
    next unless credential["type"] == "python_index"

    token = credential["token"]
    index_url = credential["index-url"]

    next unless token && index_url

    # Set environment variables for uv auth
    ENV["UV_INDEX_URL_TOKEN_#{sanitize_env_name(index_url)}"] = token

    # Also set pip-style credentials for compatibility
    ENV["PIP_INDEX_URL"] ||= "https://#{token}@#{index_url.gsub(%r{^https?://}, '')}"
  end
end

#sanitizeObject



68
69
70
71
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 68

def sanitize
  # No special sanitization needed for UV files at this point
  @pyproject_content
end

#update_python_requirement(python_version) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 30

def update_python_requirement(python_version)
  return @pyproject_content unless python_version

  in_project_table = T.let(false, T::Boolean)
  updated_lines = @lines.map do |line|
    in_project_table = true if line.match?(/^\[project\]/)

    if in_project_table && line.match?(/^requires-python\s*=/)
      "requires-python = \">=#{python_version}\""
    else
      line
    end
  end

  @pyproject_content = updated_lines.join("\n")
end