class Dependabot::Uv::FileUpdater::PyprojectPreparer
def add_auth_env_vars(credentials)
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
def initialize(pyproject_content:, lockfile: nil)
def initialize(pyproject_content:, lockfile: nil) @pyproject_content = pyproject_content @lockfile = lockfile @lines = T.let(pyproject_content.split("\n"), T::Array[String]) end
def sanitize
def sanitize # No special sanitization needed for UV files at this point @pyproject_content end
def sanitize_env_name(url)
def sanitize_env_name(url) url.gsub(%r{^https?://}, "").gsub(/[^a-zA-Z0-9]/, "_").upcase end
def update_python_requirement(python_version)
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