dependabot-python 0.403.0 → 0.405.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/helpers/lib/parser.py +14 -9
- data/helpers/run.py +1 -1
- data/helpers/test/test_parse_requirements.py +17 -0
- data/lib/dependabot/python/dependency_grapher/requirements_layers.rb +2 -24
- data/lib/dependabot/python/dependency_grapher.rb +7 -3
- data/lib/dependabot/python/file_parser/pep_dependency.rb +4 -1
- data/lib/dependabot/python/file_parser/poetry_lock/record.rb +124 -0
- data/lib/dependabot/python/file_parser/poetry_lock.rb +73 -39
- data/lib/dependabot/python/file_parser/pyproject_document/pep621_mutations.rb +154 -0
- data/lib/dependabot/python/file_parser/pyproject_document/poetry_mutations.rb +195 -0
- data/lib/dependabot/python/file_parser/pyproject_document.rb +42 -0
- data/lib/dependabot/python/file_parser/pyproject_files_parser.rb +16 -3
- data/lib/dependabot/python/file_parser.rb +63 -54
- data/lib/dependabot/python/file_updater/poetry_file_updater/pep621_updater.rb +30 -10
- data/lib/dependabot/python/file_updater/poetry_file_updater.rb +56 -76
- data/lib/dependabot/python/file_updater/pyproject_preparer.rb +32 -197
- data/lib/dependabot/python/file_updater.rb +9 -5
- data/lib/dependabot/python/language.rb +5 -5
- data/lib/dependabot/python/marker_evaluator.rb +248 -0
- data/lib/dependabot/python/poetry_subdependency_pin.rb +112 -0
- data/lib/dependabot/python/requirement_references.rb +34 -0
- data/lib/dependabot/python/shared_file_fetcher.rb +3 -2
- data/lib/dependabot/python/update_checker/pip_version_resolver.rb +4 -5
- data/lib/dependabot/python/update_checker/poetry_version_resolver.rb +48 -51
- data/lib/dependabot/python/update_checker.rb +14 -1
- metadata +10 -5
- data/lib/dependabot/python/update_checker/pip_version_resolver/marker_evaluator.rb +0 -241
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "dependabot/python/version"
|
|
5
|
+
|
|
6
|
+
module Dependabot
|
|
7
|
+
module Python
|
|
8
|
+
class MarkerEvaluator
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
11
|
+
# File parsers can't know the target platform, so they assume non-Python markers hold. The resolver
|
|
12
|
+
# leaves this off so it only applies constraints whose markers depend on the Python version.
|
|
13
|
+
sig { params(non_python_markers_satisfied: T::Boolean).void }
|
|
14
|
+
def initialize(non_python_markers_satisfied: false)
|
|
15
|
+
@non_python_markers_satisfied = non_python_markers_satisfied
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
sig { params(requirement_string: String).returns([T.nilable(String), T.nilable(String)]) }
|
|
19
|
+
def split_requirement_and_marker(requirement_string)
|
|
20
|
+
separator_index = T.let(nil, T.nilable(Integer))
|
|
21
|
+
in_single_quote = T.let(false, T::Boolean)
|
|
22
|
+
in_double_quote = T.let(false, T::Boolean)
|
|
23
|
+
|
|
24
|
+
requirement_string.each_char.with_index do |char, index|
|
|
25
|
+
in_single_quote, in_double_quote, quote_toggled =
|
|
26
|
+
toggle_quote_state(char, in_single_quote, in_double_quote)
|
|
27
|
+
next if quote_toggled
|
|
28
|
+
next if in_single_quote || in_double_quote
|
|
29
|
+
next unless char == ";"
|
|
30
|
+
|
|
31
|
+
separator_index = index
|
|
32
|
+
break
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return [requirement_string.strip, nil] if separator_index.nil?
|
|
36
|
+
|
|
37
|
+
requirement_part = requirement_string[0...separator_index]
|
|
38
|
+
marker_part = requirement_string[(separator_index + 1)..]
|
|
39
|
+
|
|
40
|
+
[requirement_part&.strip, marker_part&.strip]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
sig { params(marker: String, python_version: String).returns(T::Boolean) }
|
|
44
|
+
def marker_satisfied?(marker:, python_version:)
|
|
45
|
+
evaluate_marker_expression(marker, python_version)
|
|
46
|
+
rescue ArgumentError
|
|
47
|
+
# If we cannot safely parse a python marker, treat it as applicable.
|
|
48
|
+
# This avoids silently skipping transitive constraints that may break installs.
|
|
49
|
+
true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
sig { params(expression: String, python_version: String).returns(T::Boolean) }
|
|
55
|
+
def evaluate_marker_expression(expression, python_version)
|
|
56
|
+
expr = strip_wrapping_parentheses(expression.strip)
|
|
57
|
+
|
|
58
|
+
or_parts = split_top_level(expr, "or")
|
|
59
|
+
return or_parts.any? { |part| evaluate_marker_expression(part, python_version) } if or_parts.length > 1
|
|
60
|
+
|
|
61
|
+
and_parts = split_top_level(expr, "and")
|
|
62
|
+
if and_parts.length > 1
|
|
63
|
+
return and_parts.all? do |part|
|
|
64
|
+
evaluate_marker_expression(part, python_version) || !python_marker?(part)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
not_expression = strip_top_level_not(expr)
|
|
69
|
+
if not_expression
|
|
70
|
+
return @non_python_markers_satisfied unless python_marker?(not_expression)
|
|
71
|
+
|
|
72
|
+
return !evaluate_marker_expression(not_expression, python_version)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
evaluate_python_version_condition(
|
|
76
|
+
expr,
|
|
77
|
+
python_version,
|
|
78
|
+
default: python_marker?(expr) || @non_python_markers_satisfied
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
sig { params(expression: String).returns(T.nilable(String)) }
|
|
83
|
+
def strip_top_level_not(expression)
|
|
84
|
+
return nil unless expression.start_with?("not")
|
|
85
|
+
return nil unless word_at?(expression, 0, "not")
|
|
86
|
+
|
|
87
|
+
remaining = expression[3..]&.strip
|
|
88
|
+
return nil if remaining.nil? || remaining.empty?
|
|
89
|
+
|
|
90
|
+
remaining
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
sig { params(expression: String).returns(T::Boolean) }
|
|
94
|
+
def python_marker?(expression)
|
|
95
|
+
expression.match?(/\bpython(?:_full)?_version\b/)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
sig { params(expression: String).returns(String) }
|
|
99
|
+
def strip_wrapping_parentheses(expression)
|
|
100
|
+
expr = expression
|
|
101
|
+
while expr.start_with?("(") && expr.end_with?(")")
|
|
102
|
+
inner = expr[1...-1].to_s.strip
|
|
103
|
+
break unless balanced_parentheses?(inner)
|
|
104
|
+
|
|
105
|
+
expr = inner
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
expr
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
sig { params(expression: String).returns(T::Boolean) }
|
|
112
|
+
def balanced_parentheses?(expression)
|
|
113
|
+
depth = T.let(0, Integer)
|
|
114
|
+
in_single_quote = T.let(false, T::Boolean)
|
|
115
|
+
in_double_quote = T.let(false, T::Boolean)
|
|
116
|
+
|
|
117
|
+
expression.each_char do |char|
|
|
118
|
+
in_single_quote, in_double_quote, quote_toggled =
|
|
119
|
+
toggle_quote_state(char, in_single_quote, in_double_quote)
|
|
120
|
+
next if quote_toggled
|
|
121
|
+
next if in_single_quote || in_double_quote
|
|
122
|
+
|
|
123
|
+
depth += 1 if char == "("
|
|
124
|
+
depth -= 1 if char == ")"
|
|
125
|
+
return false if depth.negative?
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
depth.zero? && !in_single_quote && !in_double_quote
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
sig do
|
|
132
|
+
params(
|
|
133
|
+
char: String,
|
|
134
|
+
in_single_quote: T::Boolean,
|
|
135
|
+
in_double_quote: T::Boolean
|
|
136
|
+
).returns([T::Boolean, T::Boolean, T::Boolean])
|
|
137
|
+
end
|
|
138
|
+
def toggle_quote_state(char, in_single_quote, in_double_quote)
|
|
139
|
+
return [!in_single_quote, in_double_quote, true] if char == "'" && !in_double_quote
|
|
140
|
+
|
|
141
|
+
return [in_single_quote, !in_double_quote, true] if char == '"' && !in_single_quote
|
|
142
|
+
|
|
143
|
+
[in_single_quote, in_double_quote, false]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
sig { params(expression: String, operator: String).returns(T::Array[String]) }
|
|
147
|
+
def split_top_level(expression, operator)
|
|
148
|
+
parts = T.let([], T::Array[String])
|
|
149
|
+
token = T.let(+"", String)
|
|
150
|
+
depth = T.let(0, Integer)
|
|
151
|
+
in_single_quote = T.let(false, T::Boolean)
|
|
152
|
+
in_double_quote = T.let(false, T::Boolean)
|
|
153
|
+
i = T.let(0, Integer)
|
|
154
|
+
|
|
155
|
+
while i < expression.length
|
|
156
|
+
char = T.must(expression[i])
|
|
157
|
+
|
|
158
|
+
in_single_quote, in_double_quote, quote_toggled =
|
|
159
|
+
toggle_quote_state(char, in_single_quote, in_double_quote)
|
|
160
|
+
if quote_toggled
|
|
161
|
+
token << char
|
|
162
|
+
i += 1
|
|
163
|
+
next
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
depth = update_depth_for_unquoted_char(char, depth, in_single_quote, in_double_quote)
|
|
167
|
+
|
|
168
|
+
if depth.zero? && !in_single_quote && !in_double_quote && word_at?(expression, i, operator)
|
|
169
|
+
parts << token.strip
|
|
170
|
+
token = +""
|
|
171
|
+
i += operator.length
|
|
172
|
+
next
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
token << char
|
|
176
|
+
i += 1
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
parts << token.strip
|
|
180
|
+
parts
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
sig do
|
|
184
|
+
params(
|
|
185
|
+
char: String,
|
|
186
|
+
depth: Integer,
|
|
187
|
+
in_single_quote: T::Boolean,
|
|
188
|
+
in_double_quote: T::Boolean
|
|
189
|
+
).returns(Integer)
|
|
190
|
+
end
|
|
191
|
+
def update_depth_for_unquoted_char(char, depth, in_single_quote, in_double_quote)
|
|
192
|
+
return depth if in_single_quote || in_double_quote
|
|
193
|
+
|
|
194
|
+
depth += 1 if char == "("
|
|
195
|
+
depth -= 1 if char == ")"
|
|
196
|
+
depth
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
sig { params(expression: String, index: Integer, word: String).returns(T::Boolean) }
|
|
200
|
+
def word_at?(expression, index, word)
|
|
201
|
+
return false unless expression[index, word.length] == word
|
|
202
|
+
|
|
203
|
+
before = index.zero? ? " " : T.must(expression[index - 1])
|
|
204
|
+
after_index = index + word.length
|
|
205
|
+
after = after_index >= expression.length ? " " : T.must(expression[after_index])
|
|
206
|
+
|
|
207
|
+
word_boundary?(before) && word_boundary?(after)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
sig { params(char: String).returns(T::Boolean) }
|
|
211
|
+
def word_boundary?(char)
|
|
212
|
+
!!(char =~ /[^A-Za-z0-9_]/)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
sig do
|
|
216
|
+
params(
|
|
217
|
+
condition: T.nilable(String),
|
|
218
|
+
python_version: String,
|
|
219
|
+
default: T::Boolean
|
|
220
|
+
).returns(T::Boolean)
|
|
221
|
+
end
|
|
222
|
+
def evaluate_python_version_condition(condition, python_version, default:)
|
|
223
|
+
return default if condition.nil?
|
|
224
|
+
|
|
225
|
+
candidate = strip_wrapping_parentheses(condition.strip)
|
|
226
|
+
match = candidate.match(/\Apython(?:_full)?_version\s*(<=|>=|<|>|==|!=)\s*['\"]([^'\"]+)['\"]\z/)
|
|
227
|
+
return default unless match
|
|
228
|
+
|
|
229
|
+
operator = T.must(match[1])
|
|
230
|
+
version = T.must(match[2])
|
|
231
|
+
lhs = Dependabot::Python::Version.new(python_version)
|
|
232
|
+
rhs = Dependabot::Python::Version.new(version)
|
|
233
|
+
|
|
234
|
+
case operator
|
|
235
|
+
when "<" then lhs < rhs
|
|
236
|
+
when "<=" then lhs <= rhs
|
|
237
|
+
when ">" then lhs > rhs
|
|
238
|
+
when ">=" then lhs >= rhs
|
|
239
|
+
when "==" then lhs == rhs
|
|
240
|
+
when "!=" then lhs != rhs
|
|
241
|
+
else false
|
|
242
|
+
end
|
|
243
|
+
rescue ArgumentError
|
|
244
|
+
true
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "sorbet-runtime"
|
|
5
|
+
require "dependabot/dependency_file"
|
|
6
|
+
require "dependabot/python/file_parser/poetry_lock"
|
|
7
|
+
require "dependabot/python/file_parser/pyproject_document"
|
|
8
|
+
require "dependabot/python/name_normaliser"
|
|
9
|
+
|
|
10
|
+
module Dependabot
|
|
11
|
+
module Python
|
|
12
|
+
# Pins a sub-dependency of a PEP 621-only project in a scratch manifest. The pin keeps
|
|
13
|
+
# the package's locked markers, so Poetry records the same install conditions; an unconditional pin
|
|
14
|
+
# would promote an extra-only or platform-specific package into every install.
|
|
15
|
+
#
|
|
16
|
+
# A package locked at several versions (one per Python branch) is declined: a single pin can't
|
|
17
|
+
# satisfy every branch.
|
|
18
|
+
class PoetrySubdependencyPin
|
|
19
|
+
extend T::Sig
|
|
20
|
+
|
|
21
|
+
EXTRA_NAME = /extra\s*==\s*"([^"]+)"/
|
|
22
|
+
private_constant :EXTRA_NAME
|
|
23
|
+
|
|
24
|
+
# Raised when a pin can't reproduce the package's install conditions, so the update is declined
|
|
25
|
+
# rather than risk locking a version outside its intended scope.
|
|
26
|
+
class ScopeNotReproducible < StandardError; end
|
|
27
|
+
|
|
28
|
+
sig { params(lockfile: T.nilable(Dependabot::DependencyFile), name: String).void }
|
|
29
|
+
def initialize(lockfile, name)
|
|
30
|
+
@lockfile = lockfile
|
|
31
|
+
@name = name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Updates every declaration of the dependency in place; a sub-dependency isn't declared anywhere,
|
|
35
|
+
# so it is pinned instead to force Poetry's solver to consider the target version.
|
|
36
|
+
sig { params(document: FileParser::PyprojectDocument, requirement: String).void }
|
|
37
|
+
def set_requirement!(document, requirement)
|
|
38
|
+
return unless document.project?
|
|
39
|
+
|
|
40
|
+
ensure_single_version!
|
|
41
|
+
return if document.replace_pep621_requirement(name: @name, requirement: requirement).positive?
|
|
42
|
+
|
|
43
|
+
pin!(document, "#{@name}#{requirement}")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# A package locked at several versions has per-marker scopes that one target version can't reproduce.
|
|
47
|
+
sig { void }
|
|
48
|
+
def ensure_single_version!
|
|
49
|
+
raise ScopeNotReproducible, "#{@name} is locked at several versions" if entries.size > 1
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Adds a pin per place the package is locked (main, extras, other groups), each keeping its locked
|
|
53
|
+
# markers. Raises ScopeNotReproducible for a package locked at several versions, or an optional
|
|
54
|
+
# package with no extras in its markers.
|
|
55
|
+
sig { params(document: FileParser::PyprojectDocument, pin: String).void }
|
|
56
|
+
def pin!(document, pin)
|
|
57
|
+
return unless document.project?
|
|
58
|
+
|
|
59
|
+
main_pin, extra_pins, group_pins = pins_for(pin)
|
|
60
|
+
document.append_pep621_pins(main: main_pin, extras: extra_pins, groups: group_pins)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# Returns [main_pin, extra_pins, group_pins]. Raises ScopeNotReproducible for a package locked at
|
|
66
|
+
# several versions, or an optional package with no extras in its markers (legacy lockfile format):
|
|
67
|
+
# pinning it unconditionally would promote it into the main install.
|
|
68
|
+
sig { params(pin: String).returns([T.nilable(String), T::Hash[String, String], T::Hash[String, String]]) }
|
|
69
|
+
def pins_for(pin)
|
|
70
|
+
ensure_single_version!
|
|
71
|
+
|
|
72
|
+
entry = entries.first
|
|
73
|
+
return [pin, {}, {}] unless entry
|
|
74
|
+
|
|
75
|
+
group_pins = (entry.groups - ["main"]).to_h { |group| [group, scoped_pin(pin, entry, group)] }
|
|
76
|
+
return [nil, {}, group_pins] unless entry.groups.include?("main")
|
|
77
|
+
return [scoped_pin(pin, entry, "main"), {}, group_pins] unless entry.optional
|
|
78
|
+
|
|
79
|
+
[nil, extra_pins(pin, entry), group_pins]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
sig { params(pin: String, entry: FileParser::PoetryLock::Scope, group: String).returns(String) }
|
|
83
|
+
def scoped_pin(pin, entry, group)
|
|
84
|
+
marker = entry.markers_for(group).first
|
|
85
|
+
marker ? "#{pin}; #{marker}" : pin
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
sig { returns(T::Array[FileParser::PoetryLock::Scope]) }
|
|
89
|
+
def entries
|
|
90
|
+
@entries ||= T.let(locked_entries, T.nilable(T::Array[FileParser::PoetryLock::Scope]))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
sig { returns(T::Array[FileParser::PoetryLock::Scope]) }
|
|
94
|
+
def locked_entries
|
|
95
|
+
return [] unless @lockfile
|
|
96
|
+
|
|
97
|
+
FileParser::PoetryLock.from_content(T.must(@lockfile.content))
|
|
98
|
+
.records_for(@name) { |name| NameNormaliser.normalise(name) }
|
|
99
|
+
.map(&:scope)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
sig { params(pin: String, entry: FileParser::PoetryLock::Scope).returns(T::Hash[String, String]) }
|
|
103
|
+
def extra_pins(pin, entry)
|
|
104
|
+
marker = entry.markers_for("main").first.to_s
|
|
105
|
+
extras = marker.scan(EXTRA_NAME).flatten.uniq
|
|
106
|
+
raise ScopeNotReproducible, "#{@name} is optional but has no recorded extras" if extras.empty?
|
|
107
|
+
|
|
108
|
+
extras.to_h { |extra| [extra, "#{pin}; #{marker}"] }
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "pathname"
|
|
5
|
+
require "sorbet-runtime"
|
|
6
|
+
|
|
7
|
+
require "dependabot/dependency_file"
|
|
8
|
+
|
|
9
|
+
module Dependabot
|
|
10
|
+
module Python
|
|
11
|
+
module RequirementReferences
|
|
12
|
+
extend T::Sig
|
|
13
|
+
|
|
14
|
+
CHILD_REQUIREMENT_REGEX = /^-r\s?(?<path>.*\.(?:txt|in))/
|
|
15
|
+
CONSTRAINT_REGEX = /^-c\s?(?<path>.*\.(?:txt|in))/
|
|
16
|
+
|
|
17
|
+
# Resolves the sibling paths a requirements file references via `-r`/`-c`, returning repo-relative
|
|
18
|
+
# cleanpaths (matching fetched DependencyFile names).
|
|
19
|
+
sig { params(file: Dependabot::DependencyFile).returns(T::Array[String]) }
|
|
20
|
+
def self.paths(file)
|
|
21
|
+
content = file.content
|
|
22
|
+
return [] if content.nil?
|
|
23
|
+
|
|
24
|
+
current_dir = File.dirname(file.name)
|
|
25
|
+
referenced = content.scan(CHILD_REQUIREMENT_REGEX).flatten + content.scan(CONSTRAINT_REGEX).flatten
|
|
26
|
+
|
|
27
|
+
referenced.map do |path|
|
|
28
|
+
resolved = current_dir == "." ? path : File.join(current_dir, path)
|
|
29
|
+
Pathname.new(resolved).cleanpath.to_path
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -8,6 +8,7 @@ require "dependabot/file_fetchers"
|
|
|
8
8
|
require "dependabot/file_fetchers/base"
|
|
9
9
|
require "dependabot/python/language_version_manager"
|
|
10
10
|
require "dependabot/python/requirement_parser"
|
|
11
|
+
require "dependabot/python/requirement_references"
|
|
11
12
|
require "dependabot/python/file_parser/pyproject_files_parser"
|
|
12
13
|
require "dependabot/python/file_parser/python_requirement_parser"
|
|
13
14
|
require "dependabot/errors"
|
|
@@ -21,8 +22,8 @@ module Dependabot
|
|
|
21
22
|
|
|
22
23
|
abstract!
|
|
23
24
|
|
|
24
|
-
CHILD_REQUIREMENT_REGEX =
|
|
25
|
-
CONSTRAINT_REGEX =
|
|
25
|
+
CHILD_REQUIREMENT_REGEX = RequirementReferences::CHILD_REQUIREMENT_REGEX
|
|
26
|
+
CONSTRAINT_REGEX = RequirementReferences::CONSTRAINT_REGEX
|
|
26
27
|
DEPENDENCY_TYPES = %w(packages dev-packages).freeze
|
|
27
28
|
MAX_FILE_SIZE = 500_000
|
|
28
29
|
|
|
@@ -14,6 +14,7 @@ require "dependabot/python/update_checker"
|
|
|
14
14
|
require "dependabot/python/update_checker/latest_version_finder"
|
|
15
15
|
require "dependabot/python/file_parser/python_requirement_parser"
|
|
16
16
|
require "dependabot/python/file_parser/pyproject_document"
|
|
17
|
+
require "dependabot/python/marker_evaluator"
|
|
17
18
|
|
|
18
19
|
module Dependabot
|
|
19
20
|
module Python
|
|
@@ -24,8 +25,6 @@ module Dependabot
|
|
|
24
25
|
class PipVersionResolver
|
|
25
26
|
extend T::Sig
|
|
26
27
|
|
|
27
|
-
require_relative "pip_version_resolver/marker_evaluator"
|
|
28
|
-
|
|
29
28
|
sig do
|
|
30
29
|
params(
|
|
31
30
|
dependency: Dependabot::Dependency,
|
|
@@ -56,7 +55,7 @@ module Dependabot
|
|
|
56
55
|
@latest_version_finder = T.let(nil, T.nilable(LatestVersionFinder))
|
|
57
56
|
@python_requirement_parser = T.let(nil, T.nilable(FileParser::PythonRequirementParser))
|
|
58
57
|
@language_version_manager = T.let(nil, T.nilable(LanguageVersionManager))
|
|
59
|
-
@marker_evaluator = T.let(nil, T.nilable(MarkerEvaluator))
|
|
58
|
+
@marker_evaluator = T.let(nil, T.nilable(Dependabot::Python::MarkerEvaluator))
|
|
60
59
|
@registry_json_urls = T.let(nil, T.nilable(T::Array[String]))
|
|
61
60
|
@transitive_requirements_cache = T.let({}, T::Hash[String, T::Array[String]])
|
|
62
61
|
@transitive_requirement_available_cache = T.let({}, T::Hash[String, T::Boolean])
|
|
@@ -138,9 +137,9 @@ module Dependabot
|
|
|
138
137
|
)
|
|
139
138
|
end
|
|
140
139
|
|
|
141
|
-
sig { returns(MarkerEvaluator) }
|
|
140
|
+
sig { returns(Dependabot::Python::MarkerEvaluator) }
|
|
142
141
|
def marker_evaluator
|
|
143
|
-
@marker_evaluator ||= MarkerEvaluator.new
|
|
142
|
+
@marker_evaluator ||= Dependabot::Python::MarkerEvaluator.new
|
|
144
143
|
end
|
|
145
144
|
|
|
146
145
|
sig { params(candidate: Dependabot::Version).returns(T::Boolean) }
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
require "sorbet-runtime"
|
|
5
5
|
require "excon"
|
|
6
|
-
require "toml-rb"
|
|
7
6
|
require "open3"
|
|
8
7
|
require "uri"
|
|
9
8
|
require "dependabot/dependency"
|
|
10
9
|
require "dependabot/errors"
|
|
11
10
|
require "dependabot/shared_helpers"
|
|
12
11
|
require "dependabot/python/file_parser"
|
|
12
|
+
require "dependabot/python/file_parser/poetry_lock"
|
|
13
13
|
require "dependabot/python/file_parser/python_requirement_parser"
|
|
14
14
|
require "dependabot/python/file_updater/pyproject_preparer"
|
|
15
15
|
require "dependabot/python/update_checker"
|
|
@@ -19,6 +19,7 @@ require "dependabot/python/native_helpers"
|
|
|
19
19
|
require "dependabot/python/authed_url_builder"
|
|
20
20
|
require "dependabot/python/name_normaliser"
|
|
21
21
|
require "dependabot/python/poetry_plugin_installer"
|
|
22
|
+
require "dependabot/python/poetry_subdependency_pin"
|
|
22
23
|
|
|
23
24
|
module Dependabot
|
|
24
25
|
module Python
|
|
@@ -141,21 +142,20 @@ module Dependabot
|
|
|
141
142
|
run_poetry_update_command
|
|
142
143
|
|
|
143
144
|
updated_lockfile = File.read("poetry.lock")
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
fetch_version_from_lockfile(updated_lockfile)
|
|
146
|
+
rescue PoetrySubdependencyPin::ScopeNotReproducible
|
|
147
|
+
nil
|
|
147
148
|
rescue SharedHelpers::HelperSubprocessFailed => e
|
|
148
149
|
handle_poetry_errors(e)
|
|
149
150
|
end
|
|
150
151
|
end
|
|
151
152
|
end
|
|
152
153
|
|
|
153
|
-
sig { params(
|
|
154
|
-
def
|
|
155
|
-
version =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
&.fetch("version")
|
|
154
|
+
sig { params(content: String).returns(T.nilable(String)) }
|
|
155
|
+
def fetch_version_from_lockfile(content)
|
|
156
|
+
version = FileParser::PoetryLock.from_content(content)
|
|
157
|
+
.record_for(dependency.name) { |name| normalise(name) }
|
|
158
|
+
&.version
|
|
159
159
|
|
|
160
160
|
return version unless version.nil? && dependency.top_level?
|
|
161
161
|
|
|
@@ -247,6 +247,12 @@ module Dependabot
|
|
|
247
247
|
updated_req: nil,
|
|
248
248
|
update_pyproject: true
|
|
249
249
|
)
|
|
250
|
+
content = if update_pyproject
|
|
251
|
+
updated_pyproject_content(updated_requirement: updated_req)
|
|
252
|
+
else
|
|
253
|
+
sanitized_pyproject_content
|
|
254
|
+
end
|
|
255
|
+
|
|
250
256
|
dependency_files.each do |file|
|
|
251
257
|
path = file.name
|
|
252
258
|
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
|
@@ -257,14 +263,7 @@ module Dependabot
|
|
|
257
263
|
File.write(".python-version", language_version_manager.python_major_minor)
|
|
258
264
|
|
|
259
265
|
# Overwrite the pyproject with updated content
|
|
260
|
-
|
|
261
|
-
File.write(
|
|
262
|
-
"pyproject.toml",
|
|
263
|
-
updated_pyproject_content(updated_requirement: updated_req)
|
|
264
|
-
)
|
|
265
|
-
else
|
|
266
|
-
File.write("pyproject.toml", sanitized_pyproject_content)
|
|
267
|
-
end
|
|
266
|
+
File.write("pyproject.toml", content)
|
|
268
267
|
end
|
|
269
268
|
|
|
270
269
|
sig { void }
|
|
@@ -315,50 +314,48 @@ module Dependabot
|
|
|
315
314
|
|
|
316
315
|
sig { params(pyproject_content: String, updated_requirement: T.nilable(String)).returns(String) }
|
|
317
316
|
def set_target_dependency_req(pyproject_content, updated_requirement)
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
dependencies = poetry_object[type]
|
|
325
|
-
next unless dependencies
|
|
326
|
-
|
|
327
|
-
update_dependency_requirement(dependencies, updated_requirement)
|
|
317
|
+
unless updated_requirement
|
|
318
|
+
# Poetry's lock result for a package locked at several versions can't be read back as one version.
|
|
319
|
+
if pep621_only_poetry_project?(pyproject_content)
|
|
320
|
+
PoetrySubdependencyPin.new(poetry_lock, dependency.name).ensure_single_version!
|
|
321
|
+
end
|
|
322
|
+
return pyproject_content
|
|
328
323
|
end
|
|
329
324
|
|
|
330
|
-
|
|
331
|
-
groups.each do |group_spec|
|
|
332
|
-
update_dependency_requirement(group_spec["dependencies"], updated_requirement)
|
|
333
|
-
end
|
|
325
|
+
document = FileParser::PyprojectDocument.from_content(pyproject_content)
|
|
334
326
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
327
|
+
if document.poetry?
|
|
328
|
+
set_poetry_target_dependency_req(document, updated_requirement)
|
|
329
|
+
elsif poetry_lock && document.poetry_build_backend?
|
|
330
|
+
set_pep621_target_dependency_req(document, updated_requirement)
|
|
339
331
|
end
|
|
340
332
|
|
|
341
|
-
|
|
333
|
+
document.to_toml
|
|
342
334
|
end
|
|
343
335
|
|
|
344
|
-
sig { params(
|
|
345
|
-
def
|
|
346
|
-
|
|
336
|
+
sig { params(pyproject_content: String).returns(T::Boolean) }
|
|
337
|
+
def pep621_only_poetry_project?(pyproject_content)
|
|
338
|
+
!poetry_lock.nil? && FileParser::PyprojectDocument.from_content(pyproject_content).poetry_build_backend?
|
|
339
|
+
end
|
|
347
340
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
341
|
+
sig { params(document: FileParser::PyprojectDocument, updated_requirement: String).void }
|
|
342
|
+
def set_poetry_target_dependency_req(document, updated_requirement)
|
|
343
|
+
document.set_poetry_requirement(name: dependency.name, requirement: updated_requirement)
|
|
351
344
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
345
|
+
# If this is a sub-dependency, add the new requirement
|
|
346
|
+
return if dependency.requirements.find { |r| r.file == T.must(pyproject).name }
|
|
347
|
+
|
|
348
|
+
document.add_poetry_dependency(
|
|
349
|
+
name: dependency.name, requirement: updated_requirement, production: dependency.production?
|
|
350
|
+
)
|
|
357
351
|
end
|
|
358
352
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
353
|
+
# PEP 621 projects have no [tool.poetry] table to pin dependencies in. This file is only ever used
|
|
354
|
+
# as scratch input to run `poetry lock`, so it never reaches the real manifest.
|
|
355
|
+
sig { params(document: FileParser::PyprojectDocument, updated_requirement: String).void }
|
|
356
|
+
def set_pep621_target_dependency_req(document, updated_requirement)
|
|
357
|
+
PoetrySubdependencyPin.new(poetry_lock, dependency.name)
|
|
358
|
+
.set_requirement!(document, updated_requirement)
|
|
362
359
|
end
|
|
363
360
|
|
|
364
361
|
sig { returns(FileParser::PythonRequirementParser) }
|
|
@@ -73,6 +73,8 @@ module Dependabot
|
|
|
73
73
|
@latest_resolvable_version_with_no_unlock ||= T.let(
|
|
74
74
|
if resolver_type == :requirements
|
|
75
75
|
resolver.latest_resolvable_version_with_no_unlock
|
|
76
|
+
elsif resolver_type == :poetry
|
|
77
|
+
resolver.latest_resolvable_version(requirement: nil)
|
|
76
78
|
else
|
|
77
79
|
resolver.latest_resolvable_version(
|
|
78
80
|
requirement: current_requirement_string
|
|
@@ -84,6 +86,12 @@ module Dependabot
|
|
|
84
86
|
|
|
85
87
|
sig { override.returns(T.nilable(Gem::Version)) }
|
|
86
88
|
def lowest_security_fix_version
|
|
89
|
+
# A git dependency's version is whatever the lockfile records for that package, not a commit
|
|
90
|
+
# sha, so `existing_version_is_sha?` does not exclude it from security updates the way it does
|
|
91
|
+
# elsewhere. Its index has no bearing on the pinned ref: answering with a version from there
|
|
92
|
+
# would title the pull request with a fix the diff does not apply.
|
|
93
|
+
return nil if git_dependency?
|
|
94
|
+
|
|
87
95
|
latest_version_finder.lowest_security_fix_version
|
|
88
96
|
end
|
|
89
97
|
|
|
@@ -398,7 +406,12 @@ module Dependabot
|
|
|
398
406
|
|
|
399
407
|
sig { returns(T::Boolean) }
|
|
400
408
|
def poetry_based?
|
|
401
|
-
updating_pyproject? && pyproject_document.poetry?
|
|
409
|
+
updating_pyproject? && (pyproject_document.poetry? || locked_poetry_build_backend?)
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
sig { returns(T::Boolean) }
|
|
413
|
+
def locked_poetry_build_backend?
|
|
414
|
+
!poetry_lock.nil? && pyproject_document.poetry_build_backend?
|
|
402
415
|
end
|
|
403
416
|
|
|
404
417
|
sig { returns(T::Boolean) }
|