Class: Dependabot::Python::FileUpdater::RequirementReplacer
- Inherits:
-
Object
- Object
- Dependabot::Python::FileUpdater::RequirementReplacer
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/python/file_updater/requirement_replacer.rb
Constant Summary collapse
- PACKAGE_NOT_FOUND_ERROR =
"PackageNotFoundError"- CERTIFICATE_VERIFY_FAILED =
/CERTIFICATE_VERIFY_FAILED/
Instance Method Summary collapse
-
#initialize(content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil) ⇒ RequirementReplacer
constructor
A new instance of RequirementReplacer.
- #requirement_error_handler(error) ⇒ Object
- #updated_content ⇒ Object
Constructor Details
#initialize(content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil) ⇒ RequirementReplacer
Returns a new instance of RequirementReplacer.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 32 def initialize( content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil ) @content = T.let(content, String) @dependency_name = T.let(normalise(dependency_name), String) @old_requirement = T.let(old_requirement, T.nilable(String)) @new_requirement = T.let(new_requirement, T.nilable(String)) @new_hash_version = T.let(new_hash_version, T.nilable(String)) @index_urls = T.let(index_urls, T.nilable(T::Array[T.nilable(String)])) end |
Instance Method Details
#requirement_error_handler(error) ⇒ Object
249 250 251 252 253 254 255 256 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 249 def requirement_error_handler(error) Dependabot.logger.warn(error.) return unless error..match?(CERTIFICATE_VERIFY_FAILED) msg = "Error resolving dependency." raise DependencyFileNotResolvable, msg end |
#updated_content ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 49 def updated_content updated_content = content.gsub(original_declaration_replacement_regex) do |mtch| # If the "declaration" is setting an option (e.g., no-binary) # ignore it, since it isn't actually a declaration next mtch if Regexp.last_match&.pre_match&.match?(/--.*\z/) updated_dependency_declaration_string end raise "Expected content to change!" if old_requirement != new_requirement && content == updated_content updated_content end |