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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
# typed:
|
|
1
|
+
# typed: strong
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "sorbet-runtime"
|
|
5
|
-
require "toml-rb"
|
|
6
5
|
require "open3"
|
|
7
6
|
require "dependabot/dependency"
|
|
8
7
|
require "dependabot/shared_helpers"
|
|
@@ -11,23 +10,16 @@ require "dependabot/python/version"
|
|
|
11
10
|
require "dependabot/python/requirement"
|
|
12
11
|
require "dependabot/python/file_parser/python_requirement_parser"
|
|
13
12
|
require "dependabot/python/file_updater"
|
|
13
|
+
require "dependabot/python/file_parser/pyproject_document"
|
|
14
|
+
require "dependabot/python/file_parser/poetry_lock"
|
|
14
15
|
require "dependabot/python/native_helpers"
|
|
15
16
|
require "dependabot/python/name_normaliser"
|
|
16
17
|
require "dependabot/python/poetry_plugin_installer"
|
|
18
|
+
require "dependabot/python/poetry_subdependency_pin"
|
|
17
19
|
require "dependabot/package/release_cooldown_options"
|
|
18
20
|
|
|
19
21
|
module Dependabot
|
|
20
22
|
module Python
|
|
21
|
-
PoetryPyprojectHashResult = T.type_alias do
|
|
22
|
-
T.nilable(
|
|
23
|
-
T.any(
|
|
24
|
-
T::Hash[String, T.untyped],
|
|
25
|
-
String,
|
|
26
|
-
T::Array[T::Hash[String, T.untyped]]
|
|
27
|
-
)
|
|
28
|
-
)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
23
|
class FileUpdater
|
|
32
24
|
class PoetryFileUpdater
|
|
33
25
|
require_relative "pyproject_preparer"
|
|
@@ -197,7 +189,8 @@ module Dependabot
|
|
|
197
189
|
begin
|
|
198
190
|
new_lockfile = updated_lockfile_content_for(prepared_pyproject)
|
|
199
191
|
|
|
200
|
-
original_locked_python =
|
|
192
|
+
original_locked_python =
|
|
193
|
+
FileParser::PoetryLock.from_content(T.must(T.must(lockfile).content)).python_versions
|
|
201
194
|
|
|
202
195
|
new_lockfile.gsub!(/\[metadata\](?:\r?\n).*python-versions[^\r\n]+(?:\r?\n)/m) do |match|
|
|
203
196
|
# Detect the line ending style from the match (CRLF or LF)
|
|
@@ -205,11 +198,10 @@ module Dependabot
|
|
|
205
198
|
match.gsub(/(["']).*\1(?:\r?\n)\Z/, '\1' + original_locked_python + '\1' + line_ending)
|
|
206
199
|
end
|
|
207
200
|
|
|
208
|
-
tmp_hash =
|
|
209
|
-
|
|
210
|
-
correct_hash = pyproject_hash_for(updated_pyproject_content.to_s)
|
|
201
|
+
tmp_hash = FileParser::PoetryLock.from_content(new_lockfile).content_hash
|
|
202
|
+
correct_hash = pyproject_hash_for(T.must(updated_pyproject_content))
|
|
211
203
|
|
|
212
|
-
new_lockfile.gsub(tmp_hash,
|
|
204
|
+
new_lockfile.gsub(tmp_hash, correct_hash)
|
|
213
205
|
end
|
|
214
206
|
end
|
|
215
207
|
|
|
@@ -234,63 +226,63 @@ module Dependabot
|
|
|
234
226
|
|
|
235
227
|
sig { params(pyproject_content: String).returns(String) }
|
|
236
228
|
def freeze_dependencies_being_updated(pyproject_content)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
poetry_object = pyproject_object.dig("tool", "poetry")
|
|
240
|
-
|
|
241
|
-
if poetry_object
|
|
242
|
-
dependencies.each do |dep|
|
|
243
|
-
# Skip Git dependencies - they use tags/refs, not versions
|
|
244
|
-
next if git_dependency_being_updated?(dep)
|
|
229
|
+
document = FileParser::PyprojectDocument.from_content(pyproject_content)
|
|
245
230
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
end
|
|
251
|
-
end
|
|
231
|
+
if document.poetry?
|
|
232
|
+
pin_updated_poetry_dependencies(document)
|
|
233
|
+
elsif document.poetry_build_backend?
|
|
234
|
+
pin_pep621_subdependencies!(document)
|
|
252
235
|
end
|
|
253
236
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
end
|
|
237
|
+
versions = T.let({}, T::Hash[String, String])
|
|
238
|
+
dependencies.each do |dep|
|
|
239
|
+
next if git_dependency_being_updated?(dep)
|
|
258
240
|
|
|
259
|
-
|
|
260
|
-
|
|
241
|
+
version = dep.version
|
|
242
|
+
versions[NameNormaliser.normalise(dep.name)] = version if version
|
|
243
|
+
end
|
|
244
|
+
document.freeze_pep621_versions(versions)
|
|
261
245
|
|
|
262
|
-
|
|
263
|
-
def update_python_requirement(pyproject_content)
|
|
264
|
-
PyprojectPreparer.new(pyproject_content: pyproject_content)
|
|
265
|
-
.update_python_requirement(language_version_manager.python_version)
|
|
246
|
+
document.to_toml
|
|
266
247
|
end
|
|
267
248
|
|
|
268
|
-
sig { params(
|
|
269
|
-
def
|
|
270
|
-
|
|
271
|
-
|
|
249
|
+
sig { params(document: FileParser::PyprojectDocument).void }
|
|
250
|
+
def pin_updated_poetry_dependencies(document)
|
|
251
|
+
dependencies.each do |dep|
|
|
252
|
+
next if git_dependency_being_updated?(dep)
|
|
272
253
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
next unless pkg_name
|
|
254
|
+
pinned_version = exact_poetry_requirement(dep.version)
|
|
255
|
+
next unless pinned_version
|
|
276
256
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
entry["version"] = pinned_version if entry.key?("version") # skip enrichment-only entries
|
|
257
|
+
if dep.requirements.find { |r| r.file == pyproject&.name }
|
|
258
|
+
document.pin_poetry_requirement(name: dep.name, requirement: pinned_version)
|
|
280
259
|
else
|
|
281
|
-
|
|
260
|
+
document.add_poetry_dependency(
|
|
261
|
+
name: dep.name, requirement: pinned_version, production: dep.production?
|
|
262
|
+
)
|
|
282
263
|
end
|
|
283
264
|
end
|
|
284
265
|
end
|
|
285
266
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
267
|
+
# Version freezing skips dependency groups and a sub-dependency has no declaration, so without
|
|
268
|
+
# this Poetry could lock either to a newer release than the one selected.
|
|
269
|
+
sig { params(document: FileParser::PyprojectDocument).void }
|
|
270
|
+
def pin_pep621_subdependencies!(document)
|
|
271
|
+
dependencies.each do |dep|
|
|
272
|
+
next if git_dependency_being_updated?(dep)
|
|
273
|
+
next unless dep.version
|
|
290
274
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
275
|
+
PoetrySubdependencyPin.new(lockfile, dep.name).set_requirement!(document, "==#{dep.version}")
|
|
276
|
+
rescue PoetrySubdependencyPin::ScopeNotReproducible
|
|
277
|
+
# The update checker declines these; skipping keeps a direct run from promoting the package.
|
|
278
|
+
next
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
sig { params(pyproject_content: String).returns(String) }
|
|
283
|
+
def update_python_requirement(pyproject_content)
|
|
284
|
+
PyprojectPreparer.new(pyproject_content: pyproject_content)
|
|
285
|
+
.update_python_requirement(language_version_manager.python_version)
|
|
294
286
|
end
|
|
295
287
|
|
|
296
288
|
sig { params(version: T.nilable(String)).returns(T.nilable(String)) }
|
|
@@ -301,15 +293,6 @@ module Dependabot
|
|
|
301
293
|
@cooldown ? "==#{version}" : version
|
|
302
294
|
end
|
|
303
295
|
|
|
304
|
-
sig { params(poetry_object: T::Hash[String, T.untyped]).returns(T::Array[T::Hash[String, T.untyped]]) }
|
|
305
|
-
def poetry_dependency_tables(poetry_object)
|
|
306
|
-
types = Dependabot::Python::FileParser::PyprojectFilesParser::POETRY_DEPENDENCY_TYPES
|
|
307
|
-
groups = poetry_object["group"].is_a?(Hash) ? poetry_object["group"].values : []
|
|
308
|
-
candidates = types.map { |type| poetry_object[type] } +
|
|
309
|
-
groups.map { |group_spec| group_spec["dependencies"] if group_spec.is_a?(Hash) }
|
|
310
|
-
candidates.grep(Hash)
|
|
311
|
-
end
|
|
312
|
-
|
|
313
296
|
sig { params(dep: Dependabot::Dependency).returns(T::Boolean) }
|
|
314
297
|
def git_dependency_being_updated?(dep)
|
|
315
298
|
dep.requirements.any? { |r| r.source_string("type") == "git" }
|
|
@@ -355,7 +338,7 @@ module Dependabot
|
|
|
355
338
|
SharedHelpers.run_shell_command(command, fingerprint: fingerprint)
|
|
356
339
|
end
|
|
357
340
|
|
|
358
|
-
sig { params(pyproject_content:
|
|
341
|
+
sig { params(pyproject_content: String).returns(Integer) }
|
|
359
342
|
def write_temporary_dependency_files(pyproject_content)
|
|
360
343
|
dependency_files.each do |file|
|
|
361
344
|
path = file.name
|
|
@@ -377,7 +360,7 @@ module Dependabot
|
|
|
377
360
|
.add_auth_env_vars(credentials)
|
|
378
361
|
end
|
|
379
362
|
|
|
380
|
-
sig { params(pyproject_content: String).returns(
|
|
363
|
+
sig { params(pyproject_content: String).returns(String) }
|
|
381
364
|
def pyproject_hash_for(pyproject_content)
|
|
382
365
|
SharedHelpers.in_a_temporary_directory do |dir|
|
|
383
366
|
SharedHelpers.with_git_configured(credentials: credentials) do
|
|
@@ -388,7 +371,9 @@ module Dependabot
|
|
|
388
371
|
function: "get_pyproject_hash",
|
|
389
372
|
args: [T.cast(dir, Pathname).to_s]
|
|
390
373
|
)
|
|
391
|
-
|
|
374
|
+
raise TypeError, "Poetry content hash must be a string" unless result.is_a?(String)
|
|
375
|
+
|
|
376
|
+
result
|
|
392
377
|
end
|
|
393
378
|
end
|
|
394
379
|
end
|
|
@@ -431,11 +416,6 @@ module Dependabot
|
|
|
431
416
|
updated_file
|
|
432
417
|
end
|
|
433
418
|
|
|
434
|
-
sig { params(name: String).returns(String) }
|
|
435
|
-
def normalise(name)
|
|
436
|
-
NameNormaliser.normalise(name)
|
|
437
|
-
end
|
|
438
|
-
|
|
439
419
|
sig { returns(FileParser::PythonRequirementParser) }
|
|
440
420
|
def python_requirement_parser
|
|
441
421
|
@python_requirement_parser ||=
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# typed:
|
|
1
|
+
# typed: strong
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require "toml-rb"
|
|
5
4
|
require "sorbet-runtime"
|
|
6
5
|
require "dependabot/dependency"
|
|
7
6
|
require "dependabot/python/file_parser"
|
|
7
|
+
require "dependabot/python/file_parser/poetry_lock"
|
|
8
|
+
require "dependabot/python/file_parser/pyproject_document"
|
|
8
9
|
require "dependabot/python/file_updater"
|
|
9
10
|
require "dependabot/python/authed_url_builder"
|
|
10
|
-
require "dependabot/python/name_normaliser"
|
|
11
11
|
require "securerandom"
|
|
12
12
|
|
|
13
13
|
module Dependabot
|
|
@@ -16,119 +16,26 @@ module Dependabot
|
|
|
16
16
|
class PyprojectPreparer
|
|
17
17
|
extend T::Sig
|
|
18
18
|
|
|
19
|
-
# Fixed regex for extracting the name+extras prefix from a PEP 508 entry.
|
|
20
|
-
# Does not interpolate library input, avoiding polynomial backtracking.
|
|
21
|
-
PEP508_PREFIX = /\A(?<prefix>(?<name>[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?)(?:\[[^\]]*\])?)/i
|
|
22
|
-
|
|
23
|
-
# Pins a single PEP 508 dependency entry string to a specific version,
|
|
24
|
-
# preserving extras and environment markers.
|
|
25
|
-
sig { params(entry: String, version: String).returns(String) }
|
|
26
|
-
def self.pin_pep508_entry(entry, version)
|
|
27
|
-
prefix_match = entry.match(PEP508_PREFIX)
|
|
28
|
-
return entry unless prefix_match
|
|
29
|
-
|
|
30
|
-
prefix = T.must(prefix_match[:prefix])
|
|
31
|
-
rest = T.must(entry[prefix.length..])
|
|
32
|
-
|
|
33
|
-
# Skip direct references (e.g. "pkg @ git+https://...") — already pinned to a URL
|
|
34
|
-
return entry if rest.match?(/\A\s*@\s/)
|
|
35
|
-
|
|
36
|
-
# Extract the environment marker ("; ..." suffix) if present
|
|
37
|
-
marker_match = rest.match(/(\s*;.*)/)
|
|
38
|
-
marker = marker_match ? marker_match[1] : ""
|
|
39
|
-
|
|
40
|
-
"#{prefix}==#{version}#{marker}"
|
|
41
|
-
end
|
|
42
|
-
private_class_method :pin_pep508_entry
|
|
43
|
-
|
|
44
|
-
# Freezes PEP 621 dependencies in-place within a parsed pyproject object.
|
|
45
|
-
# Replaces version specifiers with ==dep.version for each matching dep.
|
|
46
|
-
# Accepts an optional block to filter which dependencies to freeze.
|
|
47
|
-
sig do
|
|
48
|
-
params(
|
|
49
|
-
pyproject_object: T::Hash[String, T.untyped],
|
|
50
|
-
deps: T::Array[Dependabot::Dependency],
|
|
51
|
-
blk: T.nilable(T.proc.params(dep: Dependabot::Dependency).returns(T::Boolean))
|
|
52
|
-
).void
|
|
53
|
-
end
|
|
54
|
-
def self.freeze_pep621_deps!(pyproject_object, deps, &blk)
|
|
55
|
-
dep_arrays = collect_pep621_dep_arrays(pyproject_object)
|
|
56
|
-
return if dep_arrays.empty?
|
|
57
|
-
|
|
58
|
-
deps.each do |dep|
|
|
59
|
-
next if blk && !yield(dep)
|
|
60
|
-
next unless dep.version
|
|
61
|
-
|
|
62
|
-
pin_pep621_dep_in_arrays!(dep_arrays, dep)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
sig { params(pyproject_object: T::Hash[String, T.untyped]).returns(T::Array[T::Array[String]]) }
|
|
67
|
-
def self.collect_pep621_dep_arrays(pyproject_object)
|
|
68
|
-
project_object = pyproject_object["project"]
|
|
69
|
-
return [] unless project_object
|
|
70
|
-
|
|
71
|
-
dep_arrays = [project_object["dependencies"]]
|
|
72
|
-
project_object["optional-dependencies"]&.each_value { |opt| dep_arrays << opt }
|
|
73
|
-
dep_arrays.compact!
|
|
74
|
-
dep_arrays.select! { |arr| arr.is_a?(Array) && arr.all?(String) }
|
|
75
|
-
dep_arrays
|
|
76
|
-
end
|
|
77
|
-
private_class_method :collect_pep621_dep_arrays
|
|
78
|
-
|
|
79
|
-
sig { params(dep_arrays: T::Array[T::Array[String]], dep: Dependabot::Dependency).void }
|
|
80
|
-
def self.pin_pep621_dep_in_arrays!(dep_arrays, dep)
|
|
81
|
-
normalised_name = NameNormaliser.normalise(dep.name)
|
|
82
|
-
dep_arrays.each do |arr|
|
|
83
|
-
arr.each_with_index do |entry, i|
|
|
84
|
-
match = entry.match(PEP508_PREFIX)
|
|
85
|
-
next unless match
|
|
86
|
-
next unless NameNormaliser.normalise(T.must(match[:name])) == normalised_name
|
|
87
|
-
|
|
88
|
-
arr[i] = pin_pep508_entry(entry, T.must(dep.version))
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
private_class_method :pin_pep621_dep_in_arrays!
|
|
93
|
-
|
|
94
19
|
sig { params(pyproject_content: String, lockfile: T.nilable(Dependabot::DependencyFile)).void }
|
|
95
20
|
def initialize(pyproject_content:, lockfile: nil)
|
|
96
21
|
@pyproject_content = pyproject_content
|
|
97
22
|
@lockfile = lockfile
|
|
98
|
-
@parsed_lockfile = T.let(nil, T.nilable(T::Hash[String, T.untyped]))
|
|
99
23
|
end
|
|
100
24
|
|
|
101
25
|
# For hosted Dependabot token will be nil since the credentials aren't present.
|
|
102
26
|
# This is for those running Dependabot themselves and for dry-run.
|
|
103
27
|
sig { params(credentials: T.nilable(T::Array[Dependabot::Credential])).void }
|
|
104
28
|
def add_auth_env_vars(credentials)
|
|
105
|
-
|
|
106
|
-
cred = credentials&.find { |c| c["index-url"] == source["url"] }
|
|
107
|
-
next unless cred
|
|
29
|
+
return if credentials.nil? || credentials.empty?
|
|
108
30
|
|
|
109
|
-
|
|
110
|
-
next unless token && token.count(":") == 1
|
|
111
|
-
|
|
112
|
-
arr = token.split(":")
|
|
113
|
-
# https://python-poetry.org/docs/configuration/#using-environment-variables
|
|
114
|
-
name = source["name"]&.upcase&.gsub(/\W/, "_")
|
|
115
|
-
ENV["POETRY_HTTP_BASIC_#{name}_USERNAME"] = arr[0]
|
|
116
|
-
ENV["POETRY_HTTP_BASIC_#{name}_PASSWORD"] = arr[1]
|
|
117
|
-
end
|
|
31
|
+
auth_environment(credentials).each { |key, value| ENV[key] = value }
|
|
118
32
|
end
|
|
119
33
|
|
|
120
34
|
sig { params(requirement: String).returns(String) }
|
|
121
35
|
def update_python_requirement(requirement)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
python_req = Python::Requirement.new(python_specification)
|
|
126
|
-
unless python_req.satisfied_by?(requirement)
|
|
127
|
-
pyproject_object["tool"]["poetry"]["dependencies"]["python"] = "~#{requirement}"
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
TomlRB.dump(pyproject_object)
|
|
36
|
+
document = FileParser::PyprojectDocument.from_content(@pyproject_content)
|
|
37
|
+
document.update_python_requirement(requirement)
|
|
38
|
+
document.to_toml
|
|
132
39
|
end
|
|
133
40
|
|
|
134
41
|
sig { returns(String) }
|
|
@@ -139,119 +46,47 @@ module Dependabot
|
|
|
139
46
|
.gsub('#{', "{")
|
|
140
47
|
end
|
|
141
48
|
|
|
142
|
-
UNSUPPORTED_SOURCE_TYPES = %w(directory file url).freeze
|
|
143
|
-
|
|
144
49
|
sig { params(dependencies: T::Array[Dependabot::Dependency]).returns(String) }
|
|
145
50
|
def freeze_top_level_dependencies_except(dependencies)
|
|
146
51
|
return pyproject_content unless lockfile
|
|
147
52
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return pyproject_content unless poetry_object
|
|
53
|
+
document = FileParser::PyprojectDocument.from_content(pyproject_content)
|
|
54
|
+
return pyproject_content unless document.poetry? || document.poetry_build_backend?
|
|
152
55
|
|
|
56
|
+
lock = FileParser::PoetryLock.from_content(T.must(T.must(lockfile).content))
|
|
153
57
|
excluded_names = dependencies.map(&:name) + ["python"]
|
|
58
|
+
document.freeze_poetry_dependencies(lock: lock, excluding: excluded_names)
|
|
59
|
+
document.freeze_locked_pep621_dependencies(lock: lock, excluding: excluded_names)
|
|
60
|
+
document.to_toml
|
|
61
|
+
end
|
|
154
62
|
|
|
155
|
-
|
|
156
|
-
next unless poetry_object[key]
|
|
157
|
-
|
|
158
|
-
poetry_object.fetch(key).each do |dep_name, _|
|
|
159
|
-
next if excluded_names.include?(normalise(dep_name))
|
|
63
|
+
private
|
|
160
64
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
65
|
+
sig { params(credentials: T::Array[Dependabot::Credential]).returns(T::Hash[String, T.nilable(String)]) }
|
|
66
|
+
def auth_environment(credentials)
|
|
67
|
+
assignments = T.let({}, T::Hash[String, T.nilable(String)])
|
|
68
|
+
FileParser::PyprojectDocument.from_content(@pyproject_content).poetry_auth_sources.each do |source|
|
|
69
|
+
url = source.url
|
|
70
|
+
cred = credentials.find { |c| c["index-url"] == url }
|
|
71
|
+
next unless cred
|
|
164
72
|
|
|
165
|
-
|
|
166
|
-
|
|
73
|
+
token = cred["token"]
|
|
74
|
+
next unless token && token.count(":") == 1
|
|
167
75
|
|
|
168
|
-
|
|
76
|
+
arr = token.split(":")
|
|
77
|
+
# https://python-poetry.org/docs/configuration/#using-environment-variables
|
|
78
|
+
name = source.name&.upcase&.gsub(/\W/, "_")
|
|
79
|
+
assignments["POETRY_HTTP_BASIC_#{name}_USERNAME"] = arr[0]
|
|
80
|
+
assignments["POETRY_HTTP_BASIC_#{name}_PASSWORD"] = arr[1]
|
|
81
|
+
end
|
|
82
|
+
assignments
|
|
169
83
|
end
|
|
170
84
|
|
|
171
|
-
private
|
|
172
|
-
|
|
173
85
|
sig { returns(String) }
|
|
174
86
|
attr_reader :pyproject_content
|
|
175
87
|
|
|
176
88
|
sig { returns(T.nilable(Dependabot::DependencyFile)) }
|
|
177
89
|
attr_reader :lockfile
|
|
178
|
-
|
|
179
|
-
sig { params(deps_hash: T::Hash[String, T.untyped], dep_name: String).void }
|
|
180
|
-
def freeze_poetry_dep!(deps_hash, dep_name)
|
|
181
|
-
details = locked_details(dep_name)
|
|
182
|
-
return unless (locked_version = details&.fetch("version"))
|
|
183
|
-
|
|
184
|
-
source_type = details.dig("source", "type")
|
|
185
|
-
return if UNSUPPORTED_SOURCE_TYPES.include?(source_type)
|
|
186
|
-
|
|
187
|
-
if source_type == "git"
|
|
188
|
-
freeze_git_dep!(deps_hash, dep_name, details)
|
|
189
|
-
elsif deps_hash[dep_name].is_a?(Hash)
|
|
190
|
-
deps_hash[dep_name]["version"] = locked_version
|
|
191
|
-
elsif !deps_hash[dep_name].is_a?(Array)
|
|
192
|
-
deps_hash[dep_name] = locked_version
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
sig { params(deps_hash: T::Hash[String, T.untyped], dep_name: String, details: T::Hash[String, T.untyped]).void }
|
|
197
|
-
def freeze_git_dep!(deps_hash, dep_name, details)
|
|
198
|
-
existing_extras = deps_hash[dep_name].is_a?(Hash) ? deps_hash[dep_name]["extras"] : nil
|
|
199
|
-
|
|
200
|
-
deps_hash[dep_name] = {
|
|
201
|
-
"git" => details.dig("source", "url"),
|
|
202
|
-
"rev" => details.dig("source", "reference")
|
|
203
|
-
}
|
|
204
|
-
subdirectory = details.dig("source", "subdirectory")
|
|
205
|
-
deps_hash[dep_name]["subdirectory"] = subdirectory if subdirectory
|
|
206
|
-
deps_hash[dep_name]["extras"] = existing_extras if existing_extras
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
sig { params(pyproject_object: T::Hash[String, T.untyped], excluded_names: T::Array[String]).void }
|
|
210
|
-
def freeze_pep621_top_level_deps!(pyproject_object, excluded_names)
|
|
211
|
-
project_object = pyproject_object["project"]
|
|
212
|
-
return unless project_object
|
|
213
|
-
|
|
214
|
-
freeze_pep621_dep_array!(project_object["dependencies"], excluded_names)
|
|
215
|
-
|
|
216
|
-
project_object["optional-dependencies"]&.each_value do |opt_deps|
|
|
217
|
-
freeze_pep621_dep_array!(opt_deps, excluded_names)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
sig { params(dep_array: T.nilable(T::Array[String]), excluded_names: T::Array[String]).void }
|
|
222
|
-
def freeze_pep621_dep_array!(dep_array, excluded_names)
|
|
223
|
-
return unless dep_array
|
|
224
|
-
|
|
225
|
-
dep_array.each_with_index do |entry, index|
|
|
226
|
-
# Extract dependency name from PEP 508 string
|
|
227
|
-
match = entry.match(/\A([a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?)/i)
|
|
228
|
-
next unless match
|
|
229
|
-
|
|
230
|
-
dep_name = normalise(T.must(match[1]))
|
|
231
|
-
next if excluded_names.include?(dep_name)
|
|
232
|
-
|
|
233
|
-
locked_details = locked_details(dep_name)
|
|
234
|
-
next unless (locked_version = locked_details&.fetch("version"))
|
|
235
|
-
|
|
236
|
-
dep_array[index] = self.class.send(:pin_pep508_entry, entry, locked_version)
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
sig { params(dep_name: String).returns(T.nilable(T::Hash[String, T.untyped])) }
|
|
241
|
-
def locked_details(dep_name)
|
|
242
|
-
parsed_lockfile.fetch("package")
|
|
243
|
-
.find { |d| d["name"] == normalise(dep_name) }
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
sig { params(name: String).returns(String) }
|
|
247
|
-
def normalise(name)
|
|
248
|
-
NameNormaliser.normalise(name)
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
sig { returns(T::Hash[String, T.untyped]) }
|
|
252
|
-
def parsed_lockfile
|
|
253
|
-
@parsed_lockfile ||= TomlRB.parse(lockfile&.content)
|
|
254
|
-
end
|
|
255
90
|
end
|
|
256
91
|
end
|
|
257
92
|
end
|
|
@@ -5,6 +5,7 @@ require "toml-rb"
|
|
|
5
5
|
require "dependabot/file_updaters"
|
|
6
6
|
require "dependabot/file_updaters/base"
|
|
7
7
|
require "dependabot/shared_helpers"
|
|
8
|
+
require "dependabot/python/file_parser/pyproject_document"
|
|
8
9
|
require "sorbet-runtime"
|
|
9
10
|
|
|
10
11
|
module Dependabot
|
|
@@ -19,18 +20,22 @@ module Dependabot
|
|
|
19
20
|
|
|
20
21
|
sig { override.returns(T::Array[DependencyFile]) }
|
|
21
22
|
def updated_dependency_files
|
|
23
|
+
resolver = resolver_type
|
|
22
24
|
updated_files =
|
|
23
|
-
case
|
|
25
|
+
case resolver
|
|
24
26
|
when :pipfile then updated_pipfile_based_files
|
|
25
27
|
when :poetry then updated_poetry_based_files
|
|
26
28
|
when :pip_compile then updated_pip_compile_based_files
|
|
27
29
|
when :requirements then updated_requirement_based_files
|
|
28
|
-
else raise "Unexpected resolver type: #{
|
|
30
|
+
else raise "Unexpected resolver type: #{resolver}"
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
if updated_files.none? ||
|
|
32
34
|
updated_files.sort_by(&:name) == dependency_files.sort_by(&:name)
|
|
33
|
-
raise
|
|
35
|
+
raise no_files_changed_error(
|
|
36
|
+
"No files have changed!",
|
|
37
|
+
{ resolver: resolver, updated_files: updated_files.map(&:name) }
|
|
38
|
+
)
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
updated_files
|
|
@@ -154,8 +159,7 @@ module Dependabot
|
|
|
154
159
|
|
|
155
160
|
return false unless poetry_lock
|
|
156
161
|
|
|
157
|
-
|
|
158
|
-
!build_backend.nil? && build_backend.start_with?("poetry.core")
|
|
162
|
+
FileParser::PyprojectDocument.from_content(T.must(pyproject&.content)).poetry_build_backend?
|
|
159
163
|
end
|
|
160
164
|
|
|
161
165
|
sig { returns(T.nilable(Dependabot::DependencyFile)) }
|
|
@@ -17,11 +17,11 @@ module Dependabot
|
|
|
17
17
|
# Note: uv ecosystem aliases this class, so updates here apply to both ecosystems.
|
|
18
18
|
PRE_INSTALLED_PYTHON_VERSIONS_RAW = %w(
|
|
19
19
|
3.15.2
|
|
20
|
-
3.14.
|
|
21
|
-
3.13.
|
|
22
|
-
3.12.
|
|
23
|
-
3.11.
|
|
24
|
-
3.10.
|
|
20
|
+
3.14.10
|
|
21
|
+
3.13.18
|
|
22
|
+
3.12.16
|
|
23
|
+
3.11.18
|
|
24
|
+
3.10.22
|
|
25
25
|
).freeze
|
|
26
26
|
|
|
27
27
|
PRE_INSTALLED_PYTHON_VERSIONS = T.let(
|