Class: Dependabot::Uv::FileUpdater::PyprojectPreparer
- Inherits:
-
Object
- Object
- Dependabot::Uv::FileUpdater::PyprojectPreparer
- Defined in:
- lib/dependabot/uv/file_updater/pyproject_preparer.rb
Instance Method Summary collapse
- #add_auth_env_vars(credentials) ⇒ Object
- #freeze_top_level_dependencies_except(dependencies_to_update) ⇒ Object
-
#initialize(pyproject_content:, lockfile: nil) ⇒ PyprojectPreparer
constructor
A new instance of PyprojectPreparer.
- #sanitize ⇒ Object
- #update_python_requirement(python_version) ⇒ Object
Constructor Details
#initialize(pyproject_content:, lockfile: nil) ⇒ PyprojectPreparer
Returns a new instance of PyprojectPreparer.
17 18 19 20 |
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 17 def initialize(pyproject_content:, lockfile: nil) @pyproject_content = pyproject_content @lockfile = lockfile end |
Instance Method Details
#add_auth_env_vars(credentials) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 52 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 |
#freeze_top_level_dependencies_except(dependencies_to_update) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 22 def freeze_top_level_dependencies_except(dependencies_to_update) return @pyproject_content unless lockfile pyproject_object = TomlRB.parse(@pyproject_content) deps_to_update_names = dependencies_to_update.map(&:name) if pyproject_object["project"]&.key?("dependencies") locked_deps = parsed_lockfile_dependencies || {} pyproject_object["project"]["dependencies"] = pyproject_object["project"]["dependencies"].map do |dep_string| freeze_dependency(dep_string, deps_to_update_names, locked_deps) end end TomlRB.dump(pyproject_object) end |
#sanitize ⇒ Object
71 72 73 74 |
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 71 def sanitize # No special sanitization needed for UV files at this point @pyproject_content end |
#update_python_requirement(python_version) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dependabot/uv/file_updater/pyproject_preparer.rb', line 40 def update_python_requirement(python_version) return @pyproject_content unless python_version pyproject_object = TomlRB.parse(@pyproject_content) if pyproject_object["project"]&.key?("requires-python") pyproject_object["project"]["requires-python"] = ">=#{python_version}" end TomlRB.dump(pyproject_object) end |