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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/parser.py +14 -9
  3. data/helpers/run.py +1 -1
  4. data/helpers/test/test_parse_requirements.py +17 -0
  5. data/lib/dependabot/python/dependency_grapher/requirements_layers.rb +2 -24
  6. data/lib/dependabot/python/dependency_grapher.rb +7 -3
  7. data/lib/dependabot/python/file_parser/pep_dependency.rb +4 -1
  8. data/lib/dependabot/python/file_parser/poetry_lock/record.rb +124 -0
  9. data/lib/dependabot/python/file_parser/poetry_lock.rb +73 -39
  10. data/lib/dependabot/python/file_parser/pyproject_document/pep621_mutations.rb +154 -0
  11. data/lib/dependabot/python/file_parser/pyproject_document/poetry_mutations.rb +195 -0
  12. data/lib/dependabot/python/file_parser/pyproject_document.rb +42 -0
  13. data/lib/dependabot/python/file_parser/pyproject_files_parser.rb +16 -3
  14. data/lib/dependabot/python/file_parser.rb +63 -54
  15. data/lib/dependabot/python/file_updater/poetry_file_updater/pep621_updater.rb +30 -10
  16. data/lib/dependabot/python/file_updater/poetry_file_updater.rb +56 -76
  17. data/lib/dependabot/python/file_updater/pyproject_preparer.rb +32 -197
  18. data/lib/dependabot/python/file_updater.rb +9 -5
  19. data/lib/dependabot/python/language.rb +5 -5
  20. data/lib/dependabot/python/marker_evaluator.rb +248 -0
  21. data/lib/dependabot/python/poetry_subdependency_pin.rb +112 -0
  22. data/lib/dependabot/python/requirement_references.rb +34 -0
  23. data/lib/dependabot/python/shared_file_fetcher.rb +3 -2
  24. data/lib/dependabot/python/update_checker/pip_version_resolver.rb +4 -5
  25. data/lib/dependabot/python/update_checker/poetry_version_resolver.rb +48 -51
  26. data/lib/dependabot/python/update_checker.rb +14 -1
  27. metadata +10 -5
  28. data/lib/dependabot/python/update_checker/pip_version_resolver/marker_evaluator.rb +0 -241
@@ -0,0 +1,195 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ require "dependabot/python/file_parser/pyproject_document"
5
+ require "dependabot/python/file_parser/poetry_lock"
6
+ require "dependabot/python/name_normaliser"
7
+ require "dependabot/python/requirement"
8
+
9
+ module Dependabot
10
+ module Python
11
+ class FileParser < Dependabot::FileParsers::Base
12
+ class PyprojectDocument
13
+ class AuthSource
14
+ extend T::Sig
15
+
16
+ sig { params(data: Object).void }
17
+ def initialize(data)
18
+ @data = T.let(PyprojectValueParser.object_hash(data, "Poetry source"), PyprojectValueParser::ObjectHash)
19
+ end
20
+
21
+ sig { returns(T.nilable(String)) }
22
+ def name
23
+ PyprojectValueParser.optional_string(@data["name"], "Poetry source name")
24
+ end
25
+
26
+ sig { returns(T.nilable(String)) }
27
+ def url
28
+ PyprojectValueParser.optional_string(@data["url"], "Poetry source url")
29
+ end
30
+ end
31
+
32
+ sig { returns(String) }
33
+ def to_toml
34
+ T.cast(TomlRB.dump(@data), String)
35
+ end
36
+
37
+ sig { returns(T::Array[AuthSource]) }
38
+ def poetry_auth_sources
39
+ value = poetry_root&.[]("source")
40
+ return [] if value.nil?
41
+
42
+ PyprojectValueParser.array(value, "tool.poetry.source").map { |entry| AuthSource.new(entry) }
43
+ end
44
+
45
+ sig { params(version: String).void }
46
+ def update_python_requirement(version)
47
+ root = mutable_poetry_root
48
+ return unless root
49
+
50
+ dependencies = mutable_section(root, "dependencies", "tool.poetry.dependencies")
51
+ specification = dependencies&.[]("python")
52
+ return unless specification
53
+
54
+ constraint = PyprojectValueParser.string(specification, "tool.poetry.dependencies.python")
55
+ requirements = Requirement.requirements_array(constraint)
56
+ return if requirements.empty? || requirements.any? { |requirement| requirement.satisfied_by?(version) }
57
+
58
+ dependencies["python"] = "~#{version}"
59
+ end
60
+
61
+ sig { params(name: String, requirement: String).void }
62
+ def set_poetry_requirement(name:, requirement:)
63
+ rewrite_poetry_requirement(name, requirement, preserve_enrichment: false)
64
+ end
65
+
66
+ sig { params(name: String, requirement: String).void }
67
+ def pin_poetry_requirement(name:, requirement:)
68
+ rewrite_poetry_requirement(name, requirement, preserve_enrichment: true)
69
+ end
70
+
71
+ sig { params(name: String, requirement: String, production: T::Boolean).void }
72
+ def add_poetry_dependency(name:, requirement:, production:)
73
+ root = mutable_poetry_root
74
+ return unless root
75
+
76
+ type = production ? "dependencies" : "dev-dependencies"
77
+ table = T.must(mutable_section(root, type, "tool.poetry.#{type}", create: true))
78
+ table[name] = requirement
79
+ end
80
+
81
+ sig { params(lock: PoetryLock, excluding: T::Array[String]).void }
82
+ def freeze_poetry_dependencies(lock:, excluding:)
83
+ root = mutable_poetry_root
84
+ return unless root
85
+
86
+ PyprojectFilesParser::POETRY_DEPENDENCY_TYPES.each do |type|
87
+ next unless root[type]
88
+
89
+ table = T.must(mutable_section(root, type, "tool.poetry.#{type}"))
90
+ table.each_key do |name|
91
+ normalized = NameNormaliser.normalise(name)
92
+ next if excluding.include?(normalized)
93
+
94
+ record = lock.record_for(normalized, &:itself)
95
+ freeze_poetry_entry(table, name, record) if record
96
+ end
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ sig do
103
+ params(
104
+ parent: PyprojectValueParser::ObjectHash, key: String, context: String, create: T::Boolean
105
+ ).returns(T.nilable(PyprojectValueParser::ObjectHash))
106
+ end
107
+ def mutable_section(parent, key, context, create: false)
108
+ value = parent[key]
109
+ return if value.nil? && !create
110
+
111
+ table = value.nil? ? {} : PyprojectValueParser.object_hash(value, context)
112
+ parent[key] = table
113
+ table
114
+ end
115
+
116
+ sig { returns(T.nilable(PyprojectValueParser::ObjectHash)) }
117
+ def mutable_poetry_root
118
+ tool = mutable_section(@data, "tool", "tool")
119
+ tool && mutable_section(tool, "poetry", "tool.poetry")
120
+ end
121
+
122
+ sig do
123
+ params(_block: T.proc.params(table: PyprojectValueParser::ObjectHash).void).void
124
+ end
125
+ def each_poetry_table(&_block)
126
+ root = mutable_poetry_root
127
+ return unless root
128
+
129
+ PyprojectFilesParser::POETRY_DEPENDENCY_TYPES.each do |type|
130
+ table = mutable_section(root, type, "tool.poetry.#{type}")
131
+ yield(table) if table
132
+ end
133
+ groups = mutable_section(root, "group", "tool.poetry.group")
134
+ groups&.each_key do |name|
135
+ group = T.must(mutable_section(groups, name, "tool.poetry.group.#{name}"))
136
+ table = mutable_section(group, "dependencies", "tool.poetry.group.#{name}.dependencies")
137
+ yield(table) if table
138
+ end
139
+ end
140
+
141
+ sig { params(name: String, requirement: String, preserve_enrichment: T::Boolean).void }
142
+ def rewrite_poetry_requirement(name, requirement, preserve_enrichment:)
143
+ each_poetry_table do |table|
144
+ key = table.keys.find { |entry| NameNormaliser.normalise(entry) == name }
145
+ next unless key
146
+
147
+ value = table[key]
148
+ if value.is_a?(Hash)
149
+ entry = PyprojectValueParser.object_hash(value, "Poetry dependency #{key}")
150
+ next if preserve_enrichment && !entry.key?("version")
151
+
152
+ entry["version"] = requirement
153
+ table[key] = entry
154
+ else
155
+ table[key] = requirement
156
+ end
157
+ end
158
+ end
159
+
160
+ sig { params(table: PyprojectValueParser::ObjectHash, name: String, record: PoetryLock::Record).void }
161
+ def freeze_poetry_entry(table, name, record)
162
+ version = record.version
163
+ source_type = record.source_type
164
+ return if %w(directory file url).include?(source_type)
165
+
166
+ value = table[name]
167
+ if source_type == "git"
168
+ table[name] = frozen_git_declaration(value, name, record.git_source)
169
+ elsif value.is_a?(Hash)
170
+ entry = PyprojectValueParser.object_hash(value, "Poetry dependency #{name}")
171
+ entry["version"] = version
172
+ table[name] = entry
173
+ elsif !value.is_a?(Array)
174
+ table[name] = version
175
+ end
176
+ end
177
+
178
+ sig do
179
+ params(value: Object, name: String, source: PoetryLock::GitSource).returns(PyprojectValueParser::ObjectHash)
180
+ end
181
+ def frozen_git_declaration(value, name, source)
182
+ declaration = T.let({ "git" => source.url, "rev" => source.reference }, PyprojectValueParser::ObjectHash)
183
+ declaration["subdirectory"] = source.subdirectory if source.subdirectory
184
+ if value.is_a?(Hash)
185
+ extras = PyprojectValueParser.object_hash(value, "Poetry dependency #{name}")["extras"]
186
+ if extras
187
+ declaration["extras"] = PyprojectValueParser.string_array(extras, "Poetry dependency #{name} extras")
188
+ end
189
+ end
190
+ declaration
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -90,6 +90,9 @@ module Dependabot
90
90
  class PyprojectDocument
91
91
  extend T::Sig
92
92
 
93
+ require_relative "pyproject_document/poetry_mutations"
94
+ require_relative "pyproject_document/pep621_mutations"
95
+
93
96
  PoetryRequirement = T.type_alias { PyprojectValueParser::PoetryRequirement }
94
97
  PoetryDependencyMap = T.type_alias { PyprojectValueParser::PoetryDependencyMap }
95
98
 
@@ -121,11 +124,24 @@ module Dependabot
121
124
  new(PyprojectValueParser.object_hash(parsed, "pyproject.toml"))
122
125
  end
123
126
 
127
+ POETRY_BUILD_BACKEND_PREFIX = "poetry.core"
128
+
124
129
  sig { returns(T::Boolean) }
125
130
  def poetry?
126
131
  !poetry_root.nil?
127
132
  end
128
133
 
134
+ # Poetry 2.0+ allows projects to declare dependencies using only PEP 621's
135
+ # [project.dependencies], with no [tool.poetry] table at all. We detect these
136
+ # projects via their declared build backend so they're still treated as Poetry
137
+ # projects (e.g. for lockfile parsing and dependency updates).
138
+ sig { returns(T::Boolean) }
139
+ def poetry_build_backend?
140
+ build_system = section(@data, "build-system", "build-system")
141
+ backend = build_system&.[]("build-backend")
142
+ backend.is_a?(String) && backend.start_with?(POETRY_BUILD_BACKEND_PREFIX)
143
+ end
144
+
129
145
  sig { returns(T::Boolean) }
130
146
  def project?
131
147
  !section(@data, "project", "project").nil?
@@ -275,6 +291,32 @@ module Dependabot
275
291
  !(keys.include?("git") && keys.include?("tag"))
276
292
  end
277
293
 
294
+ # Keys come back as the author wrote them, which is what a caller has to match the file on.
295
+ sig { returns(T::Hash[String, T::Hash[Symbol, String]]) }
296
+ def uv_git_tag_sources
297
+ tool = section(@data, "tool", "tool")
298
+ uv = tool && section(tool, "uv", "tool.uv")
299
+ sources = uv && section(uv, "sources", "tool.uv.sources")
300
+ return {} unless sources
301
+
302
+ result = T.let({}, T::Hash[String, T::Hash[Symbol, String]])
303
+ sources.each do |name, config|
304
+ next unless config.is_a?(Hash)
305
+
306
+ entry = PyprojectValueParser.object_hash(config, "tool.uv.sources.#{name}")
307
+ url = entry["git"]
308
+ ref = entry["tag"]
309
+ next unless url.is_a?(String) && ref.is_a?(String)
310
+
311
+ result[name] = { url: url, ref: ref }
312
+ end
313
+ result
314
+ rescue TypeError
315
+ # A malformed table is not this method's business either: it runs for every PEP 621
316
+ # manifest, so raising would stop every dependency in the repository being updated.
317
+ {}
318
+ end
319
+
278
320
  sig { params(key: String).returns(T::Array[String]) }
279
321
  def workspace_globs(key)
280
322
  tool = section(@data, "tool", "tool")
@@ -207,7 +207,19 @@ module Dependabot
207
207
 
208
208
  sig { returns(T::Boolean) }
209
209
  def using_poetry?
210
- pyproject_document.poetry?
210
+ pyproject_document.poetry? || locked_poetry_build_backend?
211
+ end
212
+
213
+ # A declared Poetry build backend alone isn't proof the project is actively Poetry-managed;
214
+ # require a committed lockfile as evidence it's really locked by Poetry.
215
+ sig { returns(T::Boolean) }
216
+ def locked_poetry_build_backend?
217
+ pyproject_document.poetry_build_backend? && !lockfile.nil?
218
+ end
219
+
220
+ sig { returns(T::Boolean) }
221
+ def locked_pep621_only_poetry?
222
+ !pyproject_document.poetry? && locked_poetry_build_backend?
211
223
  end
212
224
 
213
225
  sig { returns(T::Boolean) }
@@ -233,8 +245,9 @@ module Dependabot
233
245
  sig { params(dep: PepDependency).returns(T::Boolean) }
234
246
  def skip_pep621_dep?(dep)
235
247
  # If a requirement has a `<` or `<=` marker then updating it is
236
- # probably blocked. Ignore it.
237
- return true if dep.markers&.include?("<")
248
+ # probably blocked. Ignore it, unless Poetry has locked it: skipping would
249
+ # re-surface it from the lockfile as a requirement-less sub-dependency.
250
+ return true if dep.markers&.include?("<") && !locked_pep621_only_poetry?
238
251
 
239
252
  # If no requirement, don't add it
240
253
  requirement = dep.requirement
@@ -15,6 +15,8 @@ require "dependabot/python/name_normaliser"
15
15
  require "dependabot/python/pip_compile_file_matcher"
16
16
  require "dependabot/python/language_version_manager"
17
17
  require "dependabot/python/package_manager"
18
+ require "dependabot/python/marker_evaluator"
19
+ require "dependabot/python/requirement_references"
18
20
 
19
21
  module Dependabot
20
22
  module Python
@@ -292,14 +294,16 @@ module Dependabot
292
294
  sig { returns(DependencySet) }
293
295
  def requirement_dependencies
294
296
  dependencies = DependencySet.new
295
- parsed_requirement_files.each do |dep|
296
- # If a requirement has a `<`, `<=` or '==' marker then updating it is
297
- # probably blocked. Ignore it.
298
- next if blocking_marker?(dep)
297
+ # If a requirement has a `<`, `<=` or '==' marker then updating it is
298
+ # probably blocked. Ignore it.
299
+ unblocked = parsed_requirement_files.reject { |dep| blocking_marker?(dep) }
300
+ entries, constraints = split_constraints(unblocked)
301
+ pins = constraint_pins(constraints)
299
302
 
303
+ entries.each do |dep|
300
304
  name = dep.name
301
305
  file = dep.file
302
- version = dep.version
306
+ version = dep.version || pins[NameNormaliser.normalise(name)]
303
307
  original_file = get_original_file(file)
304
308
 
305
309
  requirements =
@@ -328,6 +332,51 @@ module Dependabot
328
332
  dependencies
329
333
  end
330
334
 
335
+ # Without roots every requirements file is parsed as its own manifest, so `-c` entries are kept as
336
+ # requirements of the constraints file. From roots, they follow pip and only pin versions.
337
+ sig do
338
+ params(parsed: T::Array[PepDependency])
339
+ .returns([T::Array[PepDependency], T::Array[PepDependency]])
340
+ end
341
+ def split_constraints(parsed)
342
+ return [parsed, []] unless requirement_roots
343
+
344
+ parsed.partition { |dep| !dep.constraint }
345
+ end
346
+
347
+ sig { params(constraints: T::Array[PepDependency]).returns(T::Hash[String, String]) }
348
+ def constraint_pins(constraints)
349
+ constraints.each_with_object({}) do |dep, pins|
350
+ version = dep.version
351
+ pins[NameNormaliser.normalise(dep.name)] ||= version if version
352
+ end
353
+ end
354
+
355
+ # Updates need every file parsed as a manifest so they can update pins in constraints files, so parsing
356
+ # from roots is opt-in. A root is any requirements file not pulled in by another via `-r`/`-c`, as pip
357
+ # would only read those through the reference. A reference loop leaves files no root reaches; parse
358
+ # everything so pip reports it.
359
+ sig { returns(T.nilable(T::Array[String])) }
360
+ def requirement_roots
361
+ return unless options[:requirement_roots]
362
+
363
+ references = requirement_files.to_h do |file|
364
+ [Pathname.new(file.name).cleanpath.to_path, RequirementReferences.paths(file)]
365
+ end
366
+ roots = references.keys - references.values.flatten
367
+ # A root pip-compile input may constrain itself to its own output, which is still installed directly.
368
+ roots |= roots.filter_map { |name| name.sub(/\.in\z/, ".txt") if name.end_with?(".in") } & references.keys
369
+ roots if reaches_every_file?(roots, references)
370
+ end
371
+
372
+ sig { params(roots: T::Array[String], references: T::Hash[String, T::Array[String]]).returns(T::Boolean) }
373
+ def reaches_every_file?(roots, references)
374
+ reached = T.let(Set.new(roots), T::Set[String])
375
+ queue = roots.dup
376
+ references.fetch(T.must(queue.shift), []).each { |path| queue << path if reached.add?(path) } until queue.empty?
377
+ references.keys.all? { |name| reached.include?(name) }
378
+ end
379
+
331
380
  sig { params(name: T.nilable(String), version: T.nilable(String)).returns(T::Boolean) }
332
381
  def old_pyyaml?(name, version)
333
382
  major_version = version&.split(".")&.first
@@ -351,8 +400,8 @@ module Dependabot
351
400
 
352
401
  version = python_raw_version
353
402
 
354
- if marker.include?("python_version")
355
- !marker_satisfied?(marker, version)
403
+ if marker.match?(/\bpython(?:_full)?_version\b/)
404
+ !marker_evaluator.marker_satisfied?(marker: marker, python_version: version)
356
405
  else
357
406
  return true if marker.include?("<")
358
407
  return false if marker.include?(">")
@@ -361,52 +410,12 @@ module Dependabot
361
410
  end
362
411
  end
363
412
 
364
- sig { params(marker: String, python_version: T.any(String, Integer, Gem::Version)).returns(T::Boolean) }
365
- def marker_satisfied?(marker, python_version)
366
- conditions = marker.split(/\s+(and|or)\s+/)
367
-
368
- # Explicitly define the type of result as T::Boolean
369
- result = T.let(evaluate_condition(T.must(conditions.shift), python_version), T::Boolean)
370
-
371
- until conditions.empty?
372
- operator = conditions.shift
373
- next_condition = T.must(conditions.shift)
374
- next_result = evaluate_condition(next_condition, python_version)
375
-
376
- result = if operator == "and"
377
- result && next_result
378
- else
379
- result || next_result
380
- end
381
- end
382
-
383
- result
384
- end
385
-
386
- sig do
387
- params(
388
- condition: String,
389
- python_version: T.any(String, Integer, Gem::Version)
390
- ).returns(T::Boolean)
391
- end
392
- def evaluate_condition(condition, python_version)
393
- operator, version = condition.match(/([<>=!]=?)\s*"?([\d.]+)"?/)&.captures
394
- return false unless version
395
-
396
- case operator
397
- when "<"
398
- Dependabot::Python::Version.new(python_version) < Dependabot::Python::Version.new(version)
399
- when "<="
400
- Dependabot::Python::Version.new(python_version) <= Dependabot::Python::Version.new(version)
401
- when ">"
402
- Dependabot::Python::Version.new(python_version) > Dependabot::Python::Version.new(version)
403
- when ">="
404
- Dependabot::Python::Version.new(python_version) >= Dependabot::Python::Version.new(version)
405
- when "=="
406
- Dependabot::Python::Version.new(python_version) == Dependabot::Python::Version.new(version)
407
- else
408
- false
409
- end
413
+ sig { returns(MarkerEvaluator) }
414
+ def marker_evaluator
415
+ @marker_evaluator ||= T.let(
416
+ MarkerEvaluator.new(non_python_markers_satisfied: true),
417
+ T.nilable(MarkerEvaluator)
418
+ )
410
419
  end
411
420
 
412
421
  sig { returns(DependencySet) }
@@ -426,7 +435,7 @@ module Dependabot
426
435
  result = SharedHelpers.run_helper_subprocess(
427
436
  command: "pyenv exec python3 #{NativeHelpers.python_helper_path}",
428
437
  function: "parse_requirements",
429
- args: [Dir.pwd]
438
+ args: [Dir.pwd, requirement_roots].compact
430
439
  )
431
440
 
432
441
  requirements = PepDependency.from_requirements_helper_result(result)
@@ -101,10 +101,9 @@ module Dependabot
101
101
  ).returns(T.nilable(String))
102
102
  end
103
103
  def replace_with_source_requirement(content, source_req, new_r, old_r)
104
- match = content.match(declaration_regex(source_req))
105
- return unless match
104
+ declaration = find_declaration(content, declaration_regex(source_req))
105
+ return unless declaration
106
106
 
107
- declaration = T.must(match[:declaration])
108
107
  new_req_str = rewrite_pep508_requirement(
109
108
  source_req,
110
109
  T.must(old_r.requirement_string),
@@ -128,23 +127,44 @@ module Dependabot
128
127
  old_req = T.must(old_r.requirement_string)
129
128
  new_req = T.must(new_r.requirement_string)
130
129
 
131
- match = content.match(normalized_declaration_regex(old_req))
132
- return unless match
133
-
134
- declaration = T.must(match[:declaration])
135
- return unless declaration.include?(old_req)
130
+ declaration = find_declaration(content, normalized_declaration_regex(old_req))
131
+ return unless declaration&.include?(old_req)
136
132
 
137
133
  content.sub(declaration, declaration.sub(old_req, new_req))
138
134
  end
139
135
 
136
+ # The regexes stop after the requirement. The closing quote and any environment marker are
137
+ # checked here, since matching an unbounded marker in the regex itself can backtrack badly.
138
+ sig { params(content: String, prefix_regex: Regexp).returns(T.nilable(String)) }
139
+ def find_declaration(content, prefix_regex)
140
+ position = 0
141
+ while (match = content.match(prefix_regex, position))
142
+ finish = declaration_end(content, match.end(0))
143
+ return content[match.begin(0)...finish] if finish
144
+
145
+ position = match.begin(0) + 1
146
+ end
147
+ end
148
+
149
+ sig { params(content: String, start: Integer).returns(T.nilable(Integer)) }
150
+ def declaration_end(content, start)
151
+ tail = content[start..].to_s
152
+ quote = tail.index(/["']/)
153
+ return unless quote
154
+
155
+ trailing = tail[0, quote].to_s
156
+ start + quote + 1 if trailing.empty? || trailing.lstrip.start_with?(";")
157
+ end
158
+
140
159
  sig { params(old_req: String).returns(Regexp) }
141
160
  def declaration_regex(old_req)
142
- /(?<declaration>["']#{escape}\s*#{extras_pattern}\s*#{Regexp.escape(old_req)}["'])/mi
161
+ spacing = extras_pattern.empty? ? "\\s*" : "\\s*#{extras_pattern}\\s*"
162
+ /["']#{escape}#{spacing}#{Regexp.escape(old_req)}/mi
143
163
  end
144
164
 
145
165
  sig { params(old_req: String).returns(Regexp) }
146
166
  def normalized_declaration_regex(old_req)
147
- /(?<declaration>["']#{escape}#{extras_pattern}#{Regexp.escape(old_req)}["'])/mi
167
+ /["']#{escape}#{extras_pattern}#{Regexp.escape(old_req)}/mi
148
168
  end
149
169
 
150
170
  sig { returns(String) }