1
- # typed: true
1
+ # typed: strong
2
2
# frozen_string_literal: true
3
3
4
4
require "toml-rb"
@@ -15,21 +15,26 @@ module Dependabot
15
15
module Uv
16
16
class FileUpdater
17
17
class PyprojectPreparer
18
+ extend T ::Sig
19
+
20
+ Credentials = T . type_alias { T ::Array [ T ::Hash [ String , String ] ] }
21
+
22
+ sig { params ( pyproject_content : String , lockfile : T . nilable ( Dependabot ::DependencyFile ) ) . void }
18
23
def initialize ( pyproject_content :, lockfile : nil )
19
24
@pyproject_content = pyproject_content
20
25
@lockfile = lockfile
21
- @lines = pyproject_content . split ( "\n " )
26
+ @lines = T . let ( pyproject_content . split ( "\n " ) , T :: Array [ String ] )
22
27
end
23
28
29
+ sig { params ( python_version : T . nilable ( String ) ) . returns ( String ) }
24
30
def update_python_requirement ( python_version )
25
31
return @pyproject_content unless python_version
26
32
27
- in_project_table = false
28
- updated_lines = @lines . map . with_index do |line , _i |
29
- if line . match? ( /^\[ project\] / )
30
- in_project_table = true
31
- line
32
- elsif in_project_table && line . match? ( /^requires-python\s *=/ )
33
+ in_project_table = T . let ( false , T ::Boolean )
34
+ updated_lines = @lines . map do |line |
35
+ in_project_table = true if line . match? ( /^\[ project\] / )
36
+
37
+ if in_project_table && line . match? ( /^requires-python\s *=/ )
33
38
"requires-python = \" >=#{ python_version } \" "
34
39
else
35
40
line
@@ -39,6 +44,7 @@ def update_python_requirement(python_version)
39
44
@pyproject_content = updated_lines . join ( "\n " )
40
45
end
41
46
47
+ sig { params ( credentials : T . nilable ( Credentials ) ) . returns ( T . nilable ( Credentials ) ) }
42
48
def add_auth_env_vars ( credentials )
43
49
return unless credentials
44
50
@@ -58,15 +64,18 @@ def add_auth_env_vars(credentials)
58
64
end
59
65
end
60
66
67
+ sig { returns ( String ) }
61
68
def sanitize
62
69
# No special sanitization needed for UV files at this point
63
70
@pyproject_content
64
71
end
65
72
66
73
private
67
74
75
+ sig { returns ( T . nilable ( Dependabot ::DependencyFile ) ) }
68
76
attr_reader :lockfile
69
77
78
+ sig { params ( url : String ) . returns ( String ) }
70
79
def sanitize_env_name ( url )
71
80
url . gsub ( %r{^https?://} , "" ) . gsub ( /[^a-zA-Z0-9]/ , "_" ) . upcase
72
81
end
0 commit comments