dependabot-python 0.95.49 → 0.95.50

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a26241c6343eebe08a48ac7f3d4119d31a2bf5ba2799c8cc2363288f52de7b75
4
- data.tar.gz: d9da41c2f1408485855627c9aa84652228b5dd06cf6f01d91deeb630100b3f6f
3
+ metadata.gz: c2e710a46e701b0d88c05d30cbb7ae34d375dad71b4ded6e33bbd21bbd9dbc44
4
+ data.tar.gz: 62906919a14de657cbb323a0a4e39665596d65fa90ad3208c630dadf6fca442e
5
5
  SHA512:
6
- metadata.gz: 1b537126ac99eef30e564388ef23a3f870849616acfe23255971046f68a5a2a29e1e53ec721678eece81d3a23fe98b09d6c93c448dbc366ccef4134bd47d8b99
7
- data.tar.gz: 1777d9ae20d36b13979705fab0e3e87e4274a489a5267fc277f85916535c12c0231d9323fb3e855a613fc8aff8ff4c23809b5ce5e32c0cc5729ba11a2c729f04
6
+ metadata.gz: f3ff07889ebb4864e03a753ef6b57049786e05a57ea8758b48767a709ddfeacf6b8f806893d87ad56ae232884bfefaf5e8b6d75fec5d4def9ae5ba90e9e1f492
7
+ data.tar.gz: 3122677849c56be6c252fd1b8d95f4220226f311563b89de3c1b393b7d455feb71d3ea49f8f161424492df8d6540f2ffbe10402a745678fa53ce585b14b2e76f
@@ -7,6 +7,7 @@ require "dependabot/file_fetchers/base"
7
7
  require "dependabot/python/file_parser"
8
8
  require "dependabot/errors"
9
9
 
10
+ # rubocop:disable Metrics/ClassLength
10
11
  module Dependabot
11
12
  module Python
12
13
  class FileFetcher < Dependabot::FileFetchers::Base
@@ -141,6 +142,14 @@ module Dependabot
141
142
  raise Dependabot::DependencyFileNotParseable, pipfile.path
142
143
  end
143
144
 
145
+ def parsed_pyproject
146
+ raise "No pyproject.toml" unless pyproject
147
+
148
+ @parsed_pyproject ||= TomlRB.parse(pyproject.content)
149
+ rescue TomlRB::ParseError
150
+ raise Dependabot::DependencyFileNotParseable, pyproject.path
151
+ end
152
+
144
153
  def req_txt_and_in_files
145
154
  return @req_txt_and_in_files if @req_txt_and_in_files
146
155
 
@@ -237,6 +246,12 @@ module Dependabot
237
246
  unfetchable_files << error.file_path.gsub(%r{^/}, "")
238
247
  end
239
248
 
249
+ poetry_path_setup_file_paths.each do |path|
250
+ path_setup_files += fetch_path_setup_file(path, allow_pyproject: true)
251
+ rescue Dependabot::DependencyFileNotFound => error
252
+ unfetchable_files << error.file_path.gsub(%r{^/}, "")
253
+ end
254
+
240
255
  if unfetchable_files.any?
241
256
  raise Dependabot::PathDependenciesNotReachable, unfetchable_files
242
257
  end
@@ -244,7 +259,7 @@ module Dependabot
244
259
  path_setup_files
245
260
  end
246
261
 
247
- def fetch_path_setup_file(path)
262
+ def fetch_path_setup_file(path, allow_pyproject: false)
248
263
  path_setup_files = []
249
264
 
250
265
  unless path.end_with?(".tar.gz", ".zip")
@@ -252,22 +267,38 @@ module Dependabot
252
267
  end
253
268
  return [] if path == "setup.py" && setup_file
254
269
 
255
- path_setup_files << fetch_file_from_host(path, fetch_submodules: true).
256
- tap { |f| f.support_file = true }
270
+ path_setup_files <<
271
+ begin
272
+ fetch_file_from_host(
273
+ path,
274
+ fetch_submodules: true
275
+ ).tap { |f| f.support_file = true }
276
+ rescue Dependabot::DependencyFileNotFound
277
+ raise unless allow_pyproject
278
+
279
+ fetch_file_from_host(
280
+ path.gsub("setup.py", "pyproject.toml"),
281
+ fetch_submodules: true
282
+ ).tap { |f| f.support_file = true }
283
+ end
257
284
 
258
285
  return path_setup_files unless path.end_with?(".py")
259
286
 
287
+ path_setup_files + cfg_files_for_setup_py(path)
288
+ end
289
+
290
+ def cfg_files_for_setup_py(path)
291
+ cfg_path = path.gsub(/\.py$/, ".cfg")
292
+
260
293
  begin
261
- cfg_path = path.gsub(/\.py$/, ".cfg")
262
- path_setup_files <<
294
+ [
263
295
  fetch_file_from_host(cfg_path, fetch_submodules: true).
264
- tap { |f| f.support_file = true }
296
+ tap { |f| f.support_file = true }
297
+ ]
265
298
  rescue Dependabot::DependencyFileNotFound
266
299
  # Ignore lack of a setup.cfg
267
- nil
300
+ []
268
301
  end
269
-
270
- path_setup_files
271
302
  end
272
303
 
273
304
  def requirements_file?(file)
@@ -337,9 +368,26 @@ module Dependabot
337
368
 
338
369
  paths
339
370
  end
371
+
372
+ def poetry_path_setup_file_paths
373
+ return [] unless pyproject
374
+
375
+ paths = []
376
+ %w(dependencies dev-dependencies).each do |dep_type|
377
+ next unless parsed_pyproject.dig("tool", "poetry", dep_type)
378
+
379
+ parsed_pyproject.dig("tool", "poetry", dep_type).each do |_, req|
380
+ next unless req.is_a?(Hash) && req["path"]
381
+
382
+ paths << req["path"]
383
+ end
384
+ end
385
+
386
+ paths
387
+ end
340
388
  end
341
389
  end
342
390
  end
391
+ # rubocop:enable Metrics/ClassLength
343
392
 
344
- Dependabot::FileFetchers.
345
- register("pip", Dependabot::Python::FileFetcher)
393
+ Dependabot::FileFetchers.register("pip", Dependabot::Python::FileFetcher)
@@ -98,18 +98,21 @@ module Dependabot
98
98
  end
99
99
 
100
100
  def prepared_pyproject
101
- content = updated_pyproject_content
102
- content = sanitize(content)
103
- content = freeze_other_dependencies(content)
104
- content = freeze_dependencies_being_updated(content)
105
- content = add_private_sources(content)
106
- content
101
+ @prepared_pyproject ||=
102
+ begin
103
+ content = updated_pyproject_content
104
+ content = sanitize(content)
105
+ content = freeze_other_dependencies(content)
106
+ content = freeze_dependencies_being_updated(content)
107
+ content = add_private_sources(content)
108
+ content
109
+ end
107
110
  end
108
111
 
109
112
  def freeze_other_dependencies(pyproject_content)
110
113
  PyprojectPreparer.
111
- new(pyproject_content: pyproject_content).
112
- freeze_top_level_dependencies_except(dependencies, lockfile)
114
+ new(pyproject_content: pyproject_content, lockfile: lockfile).
115
+ freeze_top_level_dependencies_except(dependencies)
113
116
  end
114
117
 
115
118
  def freeze_dependencies_being_updated(pyproject_content)
@@ -9,8 +9,9 @@ module Dependabot
9
9
  module Python
10
10
  class FileUpdater
11
11
  class PyprojectPreparer
12
- def initialize(pyproject_content:)
12
+ def initialize(pyproject_content:, lockfile: nil)
13
13
  @pyproject_content = pyproject_content
14
+ @lockfile = lockfile
14
15
  end
15
16
 
16
17
  def replace_sources(credentials)
@@ -31,7 +32,7 @@ module Dependabot
31
32
  end
32
33
 
33
34
  # rubocop:disable Metrics/PerceivedComplexity
34
- def freeze_top_level_dependencies_except(dependencies, lockfile)
35
+ def freeze_top_level_dependencies_except(dependencies)
35
36
  return pyproject_content unless lockfile
36
37
 
37
38
  pyproject_object = TomlRB.parse(pyproject_content)
@@ -44,7 +45,7 @@ module Dependabot
44
45
  poetry_object.fetch(key).each do |dep_name, _|
45
46
  next if excluded_names.include?(normalise(dep_name))
46
47
 
47
- locked_details = locked_details(dep_name, lockfile)
48
+ locked_details = locked_details(dep_name)
48
49
 
49
50
  next unless (locked_version = locked_details&.fetch("version"))
50
51
 
@@ -67,11 +68,9 @@ module Dependabot
67
68
 
68
69
  private
69
70
 
70
- attr_reader :pyproject_content
71
-
72
- def locked_details(dep_name, lockfile)
73
- parsed_lockfile = TomlRB.parse(lockfile.content)
71
+ attr_reader :pyproject_content, :lockfile
74
72
 
73
+ def locked_details(dep_name)
75
74
  parsed_lockfile.fetch("package").
76
75
  find { |d| d["name"] == normalise(dep_name) }
77
76
  end
@@ -99,6 +98,10 @@ module Dependabot
99
98
  select { |cred| cred["type"] == "python_index" }.
100
99
  map { |cred| { "url" => cred["index-url"] } }
101
100
  end
101
+
102
+ def parsed_lockfile
103
+ @parsed_lockfile ||= TomlRB.parse(lockfile.content)
104
+ end
102
105
  end
103
106
  end
104
107
  end
@@ -164,11 +164,14 @@ module Dependabot
164
164
  end
165
165
 
166
166
  def updated_pyproject_content
167
- content = pyproject.content
168
- content = sanitize_pyproject_content(content)
169
- content = freeze_other_dependencies(content)
170
- content = unlock_target_dependency(content) if unlock_requirement?
171
- content
167
+ @updated_pyproject_content ||=
168
+ begin
169
+ content = pyproject.content
170
+ content = sanitize_pyproject_content(content)
171
+ content = freeze_other_dependencies(content)
172
+ content = unlock_target_dependency(content) if unlock_requirement?
173
+ content
174
+ end
172
175
  end
173
176
 
174
177
  def sanitized_pyproject_content
@@ -185,8 +188,8 @@ module Dependabot
185
188
 
186
189
  def freeze_other_dependencies(pyproject_content)
187
190
  Python::FileUpdater::PyprojectPreparer.
188
- new(pyproject_content: pyproject_content).
189
- freeze_top_level_dependencies_except([dependency], lockfile)
191
+ new(pyproject_content: pyproject_content, lockfile: lockfile).
192
+ freeze_top_level_dependencies_except([dependency])
190
193
  end
191
194
 
192
195
  def unlock_target_dependency(pyproject_content)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-python
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.95.49
4
+ version: 0.95.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.95.49
19
+ version: 0.95.50
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.95.49
26
+ version: 0.95.50
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement