dependabot-core 0.76.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6408 -0
- data/LICENSE +37 -0
- data/README.md +115 -0
- data/helpers/elixir/bin/check_update.exs +92 -0
- data/helpers/elixir/bin/do_update.exs +39 -0
- data/helpers/elixir/bin/parse_deps.exs +103 -0
- data/helpers/elixir/bin/run.exs +76 -0
- data/helpers/elixir/mix.exs +21 -0
- data/helpers/elixir/mix.lock +3 -0
- data/helpers/go/Makefile +9 -0
- data/helpers/go/go.mod +9 -0
- data/helpers/go/go.sum +5 -0
- data/helpers/go/importresolver/main.go +34 -0
- data/helpers/go/main.go +77 -0
- data/helpers/go/updatechecker/main.go +107 -0
- data/helpers/go/updater/go.mod +3 -0
- data/helpers/go/updater/go.sum +2 -0
- data/helpers/go/updater/helpers.go +57 -0
- data/helpers/go/updater/main.go +48 -0
- data/helpers/npm/.agignore +1 -0
- data/helpers/npm/.envrc +2 -0
- data/helpers/npm/.eslintrc +14 -0
- data/helpers/npm/.nvimrc +7 -0
- data/helpers/npm/bin/run.js +34 -0
- data/helpers/npm/lib/helpers.js +25 -0
- data/helpers/npm/lib/peer-dependency-checker.js +102 -0
- data/helpers/npm/lib/subdependency-updater.js +48 -0
- data/helpers/npm/lib/updater.js +95 -0
- data/helpers/npm/package.json +17 -0
- data/helpers/npm/test/fixtures/npm-left-pad.json +1 -0
- data/helpers/npm/test/fixtures/updater/original/package-lock.json +16 -0
- data/helpers/npm/test/fixtures/updater/original/package.json +9 -0
- data/helpers/npm/test/fixtures/updater/updated/package-lock.json +16 -0
- data/helpers/npm/test/helpers.js +7 -0
- data/helpers/npm/test/updater.test.js +50 -0
- data/helpers/npm/yarn.lock +6120 -0
- data/helpers/php/.php_cs +34 -0
- data/helpers/php/bin/run.php +57 -0
- data/helpers/php/composer.json +14 -0
- data/helpers/php/composer.lock +1521 -0
- data/helpers/php/composer.phar +0 -0
- data/helpers/php/setup.sh +4 -0
- data/helpers/php/src/DependabotInstallationManager.php +61 -0
- data/helpers/php/src/DependabotPluginManager.php +23 -0
- data/helpers/php/src/ExceptionIO.php +25 -0
- data/helpers/php/src/Hasher.php +21 -0
- data/helpers/php/src/UpdateChecker.php +123 -0
- data/helpers/php/src/Updater.php +97 -0
- data/helpers/python/lib/__init__.py +0 -0
- data/helpers/python/lib/hasher.py +23 -0
- data/helpers/python/lib/parser.py +130 -0
- data/helpers/python/requirements.txt +9 -0
- data/helpers/python/run.py +18 -0
- data/helpers/test/run.rb +15 -0
- data/helpers/utils/git-credential-store-immutable +10 -0
- data/helpers/yarn/.agignore +1 -0
- data/helpers/yarn/.envrc +2 -0
- data/helpers/yarn/.eslintrc +14 -0
- data/helpers/yarn/.nvimrc +7 -0
- data/helpers/yarn/bin/run.js +36 -0
- data/helpers/yarn/lib/fix-duplicates.js +53 -0
- data/helpers/yarn/lib/helpers.js +5 -0
- data/helpers/yarn/lib/lockfile-parser.js +21 -0
- data/helpers/yarn/lib/peer-dependency-checker.js +130 -0
- data/helpers/yarn/lib/replace-lockfile-declaration.js +45 -0
- data/helpers/yarn/lib/subdependency-updater.js +69 -0
- data/helpers/yarn/lib/updater.js +254 -0
- data/helpers/yarn/package.json +17 -0
- data/helpers/yarn/test/fixtures/updater/original/package.json +6 -0
- data/helpers/yarn/test/fixtures/updater/original/yarn.lock +11 -0
- data/helpers/yarn/test/fixtures/updater/updated/yarn.lock +12 -0
- data/helpers/yarn/test/fixtures/updater/with-version-comments/package.json +5 -0
- data/helpers/yarn/test/fixtures/updater/with-version-comments/yarn.lock +13 -0
- data/helpers/yarn/test/fixtures/yarnpkg-is-positive.json +1 -0
- data/helpers/yarn/test/fixtures/yarnpkg-left-pad.json +1 -0
- data/helpers/yarn/test/helpers.js +7 -0
- data/helpers/yarn/test/updater.test.js +93 -0
- data/helpers/yarn/yarn.lock +4912 -0
- data/lib/bundler_definition_bundler_version_patch.rb +15 -0
- data/lib/bundler_definition_ruby_version_patch.rb +14 -0
- data/lib/bundler_git_source_patch.rb +27 -0
- data/lib/dependabot.rb +4 -0
- data/lib/dependabot/clients/bitbucket.rb +101 -0
- data/lib/dependabot/clients/github_with_retries.rb +117 -0
- data/lib/dependabot/clients/gitlab.rb +72 -0
- data/lib/dependabot/dependency.rb +118 -0
- data/lib/dependabot/dependency_file.rb +54 -0
- data/lib/dependabot/errors.rb +179 -0
- data/lib/dependabot/file_fetchers.rb +48 -0
- data/lib/dependabot/file_fetchers/README.md +65 -0
- data/lib/dependabot/file_fetchers/base.rb +302 -0
- data/lib/dependabot/file_fetchers/docker/docker.rb +40 -0
- data/lib/dependabot/file_fetchers/dotnet/nuget.rb +215 -0
- data/lib/dependabot/file_fetchers/dotnet/nuget/import_paths_finder.rb +51 -0
- data/lib/dependabot/file_fetchers/dotnet/nuget/sln_project_paths_finder.rb +55 -0
- data/lib/dependabot/file_fetchers/elixir/hex.rb +78 -0
- data/lib/dependabot/file_fetchers/elm/elm_package.rb +52 -0
- data/lib/dependabot/file_fetchers/git/submodules.rb +73 -0
- data/lib/dependabot/file_fetchers/go/dep.rb +69 -0
- data/lib/dependabot/file_fetchers/go/modules.rb +64 -0
- data/lib/dependabot/file_fetchers/java/gradle.rb +56 -0
- data/lib/dependabot/file_fetchers/java/gradle/settings_file_parser.rb +66 -0
- data/lib/dependabot/file_fetchers/java/maven.rb +127 -0
- data/lib/dependabot/file_fetchers/java_script/npm_and_yarn.rb +330 -0
- data/lib/dependabot/file_fetchers/java_script/npm_and_yarn/path_dependency_builder.rb +107 -0
- data/lib/dependabot/file_fetchers/php/composer.rb +131 -0
- data/lib/dependabot/file_fetchers/python/pip.rb +305 -0
- data/lib/dependabot/file_fetchers/ruby/bundler.rb +185 -0
- data/lib/dependabot/file_fetchers/ruby/bundler/child_gemfile_finder.rb +70 -0
- data/lib/dependabot/file_fetchers/ruby/bundler/path_gemspec_finder.rb +114 -0
- data/lib/dependabot/file_fetchers/ruby/bundler/require_relative_finder.rb +67 -0
- data/lib/dependabot/file_fetchers/rust/cargo.rb +240 -0
- data/lib/dependabot/file_parsers.rb +48 -0
- data/lib/dependabot/file_parsers/README.md +45 -0
- data/lib/dependabot/file_parsers/base.rb +31 -0
- data/lib/dependabot/file_parsers/base/dependency_set.rb +77 -0
- data/lib/dependabot/file_parsers/docker/docker.rb +164 -0
- data/lib/dependabot/file_parsers/dotnet/nuget.rb +85 -0
- data/lib/dependabot/file_parsers/dotnet/nuget/packages_config_parser.rb +65 -0
- data/lib/dependabot/file_parsers/dotnet/nuget/project_file_parser.rb +156 -0
- data/lib/dependabot/file_parsers/dotnet/nuget/property_value_finder.rb +131 -0
- data/lib/dependabot/file_parsers/elixir/hex.rb +134 -0
- data/lib/dependabot/file_parsers/elm/elm_package.rb +136 -0
- data/lib/dependabot/file_parsers/git/submodules.rb +69 -0
- data/lib/dependabot/file_parsers/go/dep.rb +163 -0
- data/lib/dependabot/file_parsers/go/modules.rb +34 -0
- data/lib/dependabot/file_parsers/go/modules/go_mod_parser.rb +134 -0
- data/lib/dependabot/file_parsers/java/gradle.rb +236 -0
- data/lib/dependabot/file_parsers/java/gradle/property_value_finder.rb +90 -0
- data/lib/dependabot/file_parsers/java/gradle/repositories_finder.rb +145 -0
- data/lib/dependabot/file_parsers/java/maven.rb +252 -0
- data/lib/dependabot/file_parsers/java/maven/property_value_finder.rb +166 -0
- data/lib/dependabot/file_parsers/java/maven/repositories_finder.rb +188 -0
- data/lib/dependabot/file_parsers/java_script/npm_and_yarn.rb +394 -0
- data/lib/dependabot/file_parsers/php/composer.rb +177 -0
- data/lib/dependabot/file_parsers/python/pip.rb +223 -0
- data/lib/dependabot/file_parsers/python/pip/pipfile_files_parser.rb +154 -0
- data/lib/dependabot/file_parsers/python/pip/poetry_files_parser.rb +141 -0
- data/lib/dependabot/file_parsers/python/pip/setup_file_parser.rb +160 -0
- data/lib/dependabot/file_parsers/ruby/bundler.rb +295 -0
- data/lib/dependabot/file_parsers/ruby/bundler/file_preparer.rb +85 -0
- data/lib/dependabot/file_parsers/ruby/bundler/gemfile_checker.rb +48 -0
- data/lib/dependabot/file_parsers/rust/cargo.rb +213 -0
- data/lib/dependabot/file_updaters.rb +48 -0
- data/lib/dependabot/file_updaters/README.md +58 -0
- data/lib/dependabot/file_updaters/base.rb +52 -0
- data/lib/dependabot/file_updaters/docker/docker.rb +133 -0
- data/lib/dependabot/file_updaters/dotnet/nuget.rb +151 -0
- data/lib/dependabot/file_updaters/dotnet/nuget/packages_config_declaration_finder.rb +69 -0
- data/lib/dependabot/file_updaters/dotnet/nuget/project_file_declaration_finder.rb +78 -0
- data/lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb +64 -0
- data/lib/dependabot/file_updaters/elixir/hex.rb +71 -0
- data/lib/dependabot/file_updaters/elixir/hex/lockfile_updater.rb +147 -0
- data/lib/dependabot/file_updaters/elixir/hex/mixfile_git_pin_updater.rb +53 -0
- data/lib/dependabot/file_updaters/elixir/hex/mixfile_requirement_updater.rb +74 -0
- data/lib/dependabot/file_updaters/elixir/hex/mixfile_sanitizer.rb +28 -0
- data/lib/dependabot/file_updaters/elixir/hex/mixfile_updater.rb +98 -0
- data/lib/dependabot/file_updaters/elm/elm_package.rb +79 -0
- data/lib/dependabot/file_updaters/elm/elm_package/elm_json_updater.rb +69 -0
- data/lib/dependabot/file_updaters/elm/elm_package/elm_package_updater.rb +69 -0
- data/lib/dependabot/file_updaters/git/submodules.rb +38 -0
- data/lib/dependabot/file_updaters/go/dep.rb +77 -0
- data/lib/dependabot/file_updaters/go/dep/lockfile_updater.rb +219 -0
- data/lib/dependabot/file_updaters/go/dep/manifest_updater.rb +155 -0
- data/lib/dependabot/file_updaters/go/modules.rb +71 -0
- data/lib/dependabot/file_updaters/go/modules/go_mod_updater.rb +81 -0
- data/lib/dependabot/file_updaters/java/gradle.rb +176 -0
- data/lib/dependabot/file_updaters/java/gradle/dependency_set_updater.rb +66 -0
- data/lib/dependabot/file_updaters/java/gradle/property_value_updater.rb +58 -0
- data/lib/dependabot/file_updaters/java/maven.rb +155 -0
- data/lib/dependabot/file_updaters/java/maven/declaration_finder.rb +132 -0
- data/lib/dependabot/file_updaters/java/maven/property_value_updater.rb +61 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn.rb +159 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn/npm_lockfile_updater.rb +532 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn/npmrc_builder.rb +191 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn/package_json_preparer.rb +91 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn/package_json_updater.rb +220 -0
- data/lib/dependabot/file_updaters/java_script/npm_and_yarn/yarn_lockfile_updater.rb +475 -0
- data/lib/dependabot/file_updaters/php/composer.rb +78 -0
- data/lib/dependabot/file_updaters/php/composer/lockfile_updater.rb +264 -0
- data/lib/dependabot/file_updaters/php/composer/manifest_updater.rb +70 -0
- data/lib/dependabot/file_updaters/python/pip.rb +147 -0
- data/lib/dependabot/file_updaters/python/pip/pip_compile_file_updater.rb +363 -0
- data/lib/dependabot/file_updaters/python/pip/pipfile_file_updater.rb +397 -0
- data/lib/dependabot/file_updaters/python/pip/pipfile_preparer.rb +125 -0
- data/lib/dependabot/file_updaters/python/pip/poetry_file_updater.rb +289 -0
- data/lib/dependabot/file_updaters/python/pip/pyproject_preparer.rb +105 -0
- data/lib/dependabot/file_updaters/python/pip/requirement_file_updater.rb +166 -0
- data/lib/dependabot/file_updaters/python/pip/requirement_replacer.rb +95 -0
- data/lib/dependabot/file_updaters/python/pip/setup_file_sanitizer.rb +91 -0
- data/lib/dependabot/file_updaters/ruby/bundler.rb +121 -0
- data/lib/dependabot/file_updaters/ruby/bundler/gemfile_updater.rb +116 -0
- data/lib/dependabot/file_updaters/ruby/bundler/gemspec_dependency_name_finder.rb +52 -0
- data/lib/dependabot/file_updaters/ruby/bundler/gemspec_sanitizer.rb +298 -0
- data/lib/dependabot/file_updaters/ruby/bundler/gemspec_updater.rb +64 -0
- data/lib/dependabot/file_updaters/ruby/bundler/git_pin_replacer.rb +80 -0
- data/lib/dependabot/file_updaters/ruby/bundler/git_source_remover.rb +102 -0
- data/lib/dependabot/file_updaters/ruby/bundler/lockfile_updater.rb +384 -0
- data/lib/dependabot/file_updaters/ruby/bundler/requirement_replacer.rb +188 -0
- data/lib/dependabot/file_updaters/rust/cargo.rb +83 -0
- data/lib/dependabot/file_updaters/rust/cargo/lockfile_updater.rb +251 -0
- data/lib/dependabot/file_updaters/rust/cargo/manifest_updater.rb +162 -0
- data/lib/dependabot/git_commit_checker.rb +412 -0
- data/lib/dependabot/metadata_finders.rb +46 -0
- data/lib/dependabot/metadata_finders/README.md +53 -0
- data/lib/dependabot/metadata_finders/base.rb +117 -0
- data/lib/dependabot/metadata_finders/base/changelog_finder.rb +317 -0
- data/lib/dependabot/metadata_finders/base/changelog_pruner.rb +177 -0
- data/lib/dependabot/metadata_finders/base/commits_finder.rb +217 -0
- data/lib/dependabot/metadata_finders/base/release_finder.rb +251 -0
- data/lib/dependabot/metadata_finders/docker/docker.rb +18 -0
- data/lib/dependabot/metadata_finders/dotnet/nuget.rb +116 -0
- data/lib/dependabot/metadata_finders/elixir/hex.rb +69 -0
- data/lib/dependabot/metadata_finders/elm/elm_package.rb +22 -0
- data/lib/dependabot/metadata_finders/git/submodules.rb +20 -0
- data/lib/dependabot/metadata_finders/go/dep.rb +56 -0
- data/lib/dependabot/metadata_finders/java/maven.rb +173 -0
- data/lib/dependabot/metadata_finders/java_script/npm_and_yarn.rb +215 -0
- data/lib/dependabot/metadata_finders/php/composer.rb +66 -0
- data/lib/dependabot/metadata_finders/python/pip.rb +120 -0
- data/lib/dependabot/metadata_finders/ruby/bundler.rb +150 -0
- data/lib/dependabot/metadata_finders/rust/cargo.rb +64 -0
- data/lib/dependabot/pull_request_creator.rb +151 -0
- data/lib/dependabot/pull_request_creator/branch_namer.rb +170 -0
- data/lib/dependabot/pull_request_creator/commit_signer.rb +63 -0
- data/lib/dependabot/pull_request_creator/github.rb +233 -0
- data/lib/dependabot/pull_request_creator/gitlab.rb +122 -0
- data/lib/dependabot/pull_request_creator/labeler.rb +361 -0
- data/lib/dependabot/pull_request_creator/message_builder.rb +888 -0
- data/lib/dependabot/pull_request_updater.rb +43 -0
- data/lib/dependabot/pull_request_updater/github.rb +151 -0
- data/lib/dependabot/shared_helpers.rb +201 -0
- data/lib/dependabot/source.rb +120 -0
- data/lib/dependabot/update_checkers.rb +48 -0
- data/lib/dependabot/update_checkers/README.md +67 -0
- data/lib/dependabot/update_checkers/base.rb +220 -0
- data/lib/dependabot/update_checkers/docker/docker.rb +290 -0
- data/lib/dependabot/update_checkers/dotnet/nuget.rb +127 -0
- data/lib/dependabot/update_checkers/dotnet/nuget/property_updater.rb +97 -0
- data/lib/dependabot/update_checkers/dotnet/nuget/repository_finder.rb +232 -0
- data/lib/dependabot/update_checkers/dotnet/nuget/requirements_updater.rb +81 -0
- data/lib/dependabot/update_checkers/dotnet/nuget/version_finder.rb +231 -0
- data/lib/dependabot/update_checkers/elixir/hex.rb +274 -0
- data/lib/dependabot/update_checkers/elixir/hex/file_preparer.rb +193 -0
- data/lib/dependabot/update_checkers/elixir/hex/requirements_updater.rb +177 -0
- data/lib/dependabot/update_checkers/elixir/hex/version_resolver.rb +175 -0
- data/lib/dependabot/update_checkers/elm/elm_package.rb +126 -0
- data/lib/dependabot/update_checkers/elm/elm_package/cli_parser.rb +33 -0
- data/lib/dependabot/update_checkers/elm/elm_package/elm_18_version_resolver.rb +234 -0
- data/lib/dependabot/update_checkers/elm/elm_package/elm_19_version_resolver.rb +198 -0
- data/lib/dependabot/update_checkers/elm/elm_package/requirements_updater.rb +75 -0
- data/lib/dependabot/update_checkers/git/submodules.rb +52 -0
- data/lib/dependabot/update_checkers/go/dep.rb +311 -0
- data/lib/dependabot/update_checkers/go/dep/file_preparer.rb +221 -0
- data/lib/dependabot/update_checkers/go/dep/latest_version_finder.rb +169 -0
- data/lib/dependabot/update_checkers/go/dep/requirements_updater.rb +223 -0
- data/lib/dependabot/update_checkers/go/dep/version_resolver.rb +164 -0
- data/lib/dependabot/update_checkers/go/modules.rb +112 -0
- data/lib/dependabot/update_checkers/java/gradle.rb +148 -0
- data/lib/dependabot/update_checkers/java/gradle/multi_dependency_updater.rb +105 -0
- data/lib/dependabot/update_checkers/java/gradle/version_finder.rb +183 -0
- data/lib/dependabot/update_checkers/java/maven.rb +159 -0
- data/lib/dependabot/update_checkers/java/maven/property_updater.rb +127 -0
- data/lib/dependabot/update_checkers/java/maven/requirements_updater.rb +92 -0
- data/lib/dependabot/update_checkers/java/maven/version_finder.rb +225 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn.rb +280 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/latest_version_finder.rb +342 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/library_detector.rb +69 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/registry_finder.rb +226 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/requirements_updater.rb +197 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/subdependency_version_resolver.rb +228 -0
- data/lib/dependabot/update_checkers/java_script/npm_and_yarn/version_resolver.rb +452 -0
- data/lib/dependabot/update_checkers/php/composer.rb +165 -0
- data/lib/dependabot/update_checkers/php/composer/requirements_updater.rb +243 -0
- data/lib/dependabot/update_checkers/php/composer/version_resolver.rb +203 -0
- data/lib/dependabot/update_checkers/python/pip.rb +227 -0
- data/lib/dependabot/update_checkers/python/pip/latest_version_finder.rb +252 -0
- data/lib/dependabot/update_checkers/python/pip/pip_compile_version_resolver.rb +380 -0
- data/lib/dependabot/update_checkers/python/pip/pipfile_version_resolver.rb +559 -0
- data/lib/dependabot/update_checkers/python/pip/poetry_version_resolver.rb +300 -0
- data/lib/dependabot/update_checkers/python/pip/requirements_updater.rb +367 -0
- data/lib/dependabot/update_checkers/ruby/bundler.rb +324 -0
- data/lib/dependabot/update_checkers/ruby/bundler/file_preparer.rb +278 -0
- data/lib/dependabot/update_checkers/ruby/bundler/force_updater.rb +261 -0
- data/lib/dependabot/update_checkers/ruby/bundler/latest_version_finder.rb +169 -0
- data/lib/dependabot/update_checkers/ruby/bundler/requirements_updater.rb +264 -0
- data/lib/dependabot/update_checkers/ruby/bundler/ruby_requirement_setter.rb +115 -0
- data/lib/dependabot/update_checkers/ruby/bundler/shared_bundler_helpers.rb +243 -0
- data/lib/dependabot/update_checkers/ruby/bundler/version_resolver.rb +255 -0
- data/lib/dependabot/update_checkers/rust/cargo.rb +282 -0
- data/lib/dependabot/update_checkers/rust/cargo/file_preparer.rb +202 -0
- data/lib/dependabot/update_checkers/rust/cargo/requirements_updater.rb +175 -0
- data/lib/dependabot/update_checkers/rust/cargo/version_resolver.rb +242 -0
- data/lib/dependabot/utils.rb +84 -0
- data/lib/dependabot/utils/docker/credentials_finder.rb +65 -0
- data/lib/dependabot/utils/dotnet/requirement.rb +90 -0
- data/lib/dependabot/utils/dotnet/version.rb +22 -0
- data/lib/dependabot/utils/elixir/requirement.rb +53 -0
- data/lib/dependabot/utils/elixir/version.rb +59 -0
- data/lib/dependabot/utils/elm/requirement.rb +92 -0
- data/lib/dependabot/utils/elm/version.rb +19 -0
- data/lib/dependabot/utils/go/path_converter.rb +74 -0
- data/lib/dependabot/utils/go/requirement.rb +152 -0
- data/lib/dependabot/utils/go/shared_helper.rb +20 -0
- data/lib/dependabot/utils/go/version.rb +40 -0
- data/lib/dependabot/utils/java/requirement.rb +110 -0
- data/lib/dependabot/utils/java/version.rb +179 -0
- data/lib/dependabot/utils/java_script/requirement.rb +117 -0
- data/lib/dependabot/utils/java_script/version.rb +30 -0
- data/lib/dependabot/utils/php/requirement.rb +97 -0
- data/lib/dependabot/utils/php/version.rb +22 -0
- data/lib/dependabot/utils/python/requirement.rb +130 -0
- data/lib/dependabot/utils/python/version.rb +88 -0
- data/lib/dependabot/utils/ruby/requirement.rb +26 -0
- data/lib/dependabot/utils/rust/requirement.rb +108 -0
- data/lib/dependabot/utils/rust/version.rb +32 -0
- data/lib/dependabot/version.rb +5 -0
- data/lib/python_requirement_parser.rb +33 -0
- data/lib/python_versions.rb +21 -0
- metadata +641 -0
@@ -0,0 +1,380 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "python_requirement_parser"
|
4
|
+
require "dependabot/file_fetchers/python/pip"
|
5
|
+
require "dependabot/file_parsers/python/pip"
|
6
|
+
require "dependabot/update_checkers/python/pip"
|
7
|
+
require "dependabot/file_updaters/python/pip/requirement_replacer"
|
8
|
+
require "dependabot/file_updaters/python/pip/setup_file_sanitizer"
|
9
|
+
require "dependabot/utils/python/version"
|
10
|
+
require "dependabot/shared_helpers"
|
11
|
+
|
12
|
+
# rubocop:disable Metrics/ClassLength
|
13
|
+
module Dependabot
|
14
|
+
module UpdateCheckers
|
15
|
+
module Python
|
16
|
+
class Pip
|
17
|
+
# This class does version resolution for pip-compile. Its approach is:
|
18
|
+
# - Unlock the dependency we're checking in the requirements.in file
|
19
|
+
# - Run `pip-compile` and see what the result is
|
20
|
+
class PipCompileVersionResolver
|
21
|
+
VERSION_REGEX = /[0-9]+(?:\.[A-Za-z0-9\-_]+)*/.freeze
|
22
|
+
|
23
|
+
attr_reader :dependency, :dependency_files, :credentials
|
24
|
+
|
25
|
+
def initialize(dependency:, dependency_files:, credentials:,
|
26
|
+
unlock_requirement:, latest_allowable_version:)
|
27
|
+
@dependency = dependency
|
28
|
+
@dependency_files = dependency_files
|
29
|
+
@credentials = credentials
|
30
|
+
@latest_allowable_version = latest_allowable_version
|
31
|
+
@unlock_requirement = unlock_requirement
|
32
|
+
end
|
33
|
+
|
34
|
+
def latest_resolvable_version
|
35
|
+
return @latest_resolvable_version if @resolution_already_attempted
|
36
|
+
|
37
|
+
@resolution_already_attempted = true
|
38
|
+
@latest_resolvable_version ||= fetch_latest_resolvable_version
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :latest_allowable_version
|
44
|
+
|
45
|
+
def unlock_requirement?
|
46
|
+
@unlock_requirement
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch_latest_resolvable_version
|
50
|
+
@latest_resolvable_version_string ||=
|
51
|
+
SharedHelpers.in_a_temporary_directory do
|
52
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
53
|
+
write_temporary_dependency_files
|
54
|
+
|
55
|
+
filenames_to_compile.each do |filename|
|
56
|
+
# Shell out to pip-compile.
|
57
|
+
# This is slow, as pip-compile needs to do installs.
|
58
|
+
cmd = "pyenv exec pip-compile --allow-unsafe "\
|
59
|
+
"-P #{dependency.name} #{filename}"
|
60
|
+
run_command(cmd)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Remove any .python-version file before parsing the reqs
|
64
|
+
FileUtils.remove_entry(".python-version", true)
|
65
|
+
|
66
|
+
parse_updated_files
|
67
|
+
end
|
68
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
69
|
+
handle_pip_compile_errors(error)
|
70
|
+
end
|
71
|
+
return unless @latest_resolvable_version_string
|
72
|
+
|
73
|
+
Utils::Python::Version.new(@latest_resolvable_version_string)
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_requirements_from_cwd_files
|
77
|
+
SharedHelpers.run_helper_subprocess(
|
78
|
+
command: "pyenv exec python #{python_helper_path}",
|
79
|
+
function: "parse_requirements",
|
80
|
+
args: [Dir.pwd]
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_pip_compile_errors(error)
|
85
|
+
if error.message.include?("Could not find a version")
|
86
|
+
check_original_requirements_resolvable
|
87
|
+
# If the original requirements are resolvable but we get an
|
88
|
+
# incompatibility update after unlocking then it's likely to be
|
89
|
+
# due to problems with pip-compile's cascading resolution
|
90
|
+
return nil
|
91
|
+
end
|
92
|
+
|
93
|
+
if error.message.include?('Command "python setup.py egg_info') &&
|
94
|
+
error.message.include?(dependency.name)
|
95
|
+
# The latest version of the dependency we're updating is borked
|
96
|
+
# (because it has an unevaluatable setup.py). Skip the update.
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
|
100
|
+
if error.message.include?("Could not find a version ") &&
|
101
|
+
!error.message.include?(dependency.name)
|
102
|
+
# Sometimes pip-tools gets confused and can't work around
|
103
|
+
# sub-dependency incompatibilities. Ignore those cases.
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
raise
|
108
|
+
end
|
109
|
+
|
110
|
+
# Needed because pip-compile's resolver isn't perfect.
|
111
|
+
# Note: We raise errors from this method, rather than returning a
|
112
|
+
# boolean, so that all deps for this repo will raise identical
|
113
|
+
# errors when failing to update
|
114
|
+
def check_original_requirements_resolvable
|
115
|
+
SharedHelpers.in_a_temporary_directory do
|
116
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
117
|
+
write_temporary_dependency_files(unlock_requirement: false)
|
118
|
+
|
119
|
+
filenames_to_compile.each do |filename|
|
120
|
+
cmd = "pyenv exec pip-compile --allow-unsafe #{filename}"
|
121
|
+
run_command(cmd)
|
122
|
+
end
|
123
|
+
|
124
|
+
true
|
125
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
126
|
+
raise unless error.message.include?("Could not find a version")
|
127
|
+
|
128
|
+
msg = clean_error_message(error.message)
|
129
|
+
raise if msg.empty?
|
130
|
+
|
131
|
+
raise DependencyFileNotResolvable, msg
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def run_command(command)
|
137
|
+
command = command.dup
|
138
|
+
raw_response = nil
|
139
|
+
IO.popen(command, err: %i(child out)) do |process|
|
140
|
+
raw_response = process.read
|
141
|
+
end
|
142
|
+
|
143
|
+
# Raise an error with the output from the shell session if
|
144
|
+
# pip-compile returns a non-zero status
|
145
|
+
return if $CHILD_STATUS.success?
|
146
|
+
|
147
|
+
raise SharedHelpers::HelperSubprocessFailed.new(
|
148
|
+
raw_response,
|
149
|
+
command
|
150
|
+
)
|
151
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
152
|
+
original_error ||= error
|
153
|
+
msg = error.message
|
154
|
+
|
155
|
+
relevant_error =
|
156
|
+
if error_suggests_bad_python_version?(msg) then original_error
|
157
|
+
else error
|
158
|
+
end
|
159
|
+
|
160
|
+
raise relevant_error unless error_suggests_bad_python_version?(msg)
|
161
|
+
raise relevant_error if File.exist?(".python-version")
|
162
|
+
|
163
|
+
command = "pyenv local 2.7.15 && " + command
|
164
|
+
retry
|
165
|
+
ensure
|
166
|
+
FileUtils.remove_entry(".python-version", true)
|
167
|
+
end
|
168
|
+
|
169
|
+
def error_suggests_bad_python_version?(message)
|
170
|
+
return true if message.include?("not find a version that satisfies")
|
171
|
+
|
172
|
+
message.include?('Command "python setup.py egg_info" failed')
|
173
|
+
end
|
174
|
+
|
175
|
+
def write_temporary_dependency_files(unlock_requirement: true)
|
176
|
+
dependency_files.each do |file|
|
177
|
+
next if file.name == ".python-version"
|
178
|
+
|
179
|
+
path = file.name
|
180
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
181
|
+
File.write(
|
182
|
+
path,
|
183
|
+
unlock_requirement ? unlock_dependency(file) : file.content
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
setup_files.each do |file|
|
188
|
+
path = file.name
|
189
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
190
|
+
File.write(path, sanitized_setup_file_content(file))
|
191
|
+
end
|
192
|
+
|
193
|
+
setup_cfg_files.each do |file|
|
194
|
+
path = file.name
|
195
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
196
|
+
File.write(path, "[metadata]\nname = sanitized-package\n")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def sanitized_setup_file_content(file)
|
201
|
+
@sanitized_setup_file_content ||= {}
|
202
|
+
if @sanitized_setup_file_content[file.name]
|
203
|
+
return @sanitized_setup_file_content[file.name]
|
204
|
+
end
|
205
|
+
|
206
|
+
@sanitized_setup_file_content[file.name] =
|
207
|
+
FileUpdaters::Python::Pip::SetupFileSanitizer.
|
208
|
+
new(setup_file: file, setup_cfg: setup_cfg(file)).
|
209
|
+
sanitized_content
|
210
|
+
end
|
211
|
+
|
212
|
+
def setup_cfg(file)
|
213
|
+
dependency_files.find do |f|
|
214
|
+
f.name == file.name.sub(/\.py$/, ".cfg")
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def unlock_dependency(file)
|
219
|
+
return file.content unless file.name.end_with?(".in")
|
220
|
+
return file.content unless dependency.version
|
221
|
+
return file.content unless unlock_requirement?
|
222
|
+
|
223
|
+
req = dependency.requirements.find { |r| r[:file] == file.name }
|
224
|
+
return file.content unless req&.fetch(:requirement)
|
225
|
+
|
226
|
+
FileUpdaters::Python::Pip::RequirementReplacer.new(
|
227
|
+
content: file.content,
|
228
|
+
dependency_name: dependency.name,
|
229
|
+
old_requirement: req[:requirement],
|
230
|
+
new_requirement: updated_version_requirement_string
|
231
|
+
).updated_content
|
232
|
+
end
|
233
|
+
|
234
|
+
def updated_version_requirement_string
|
235
|
+
lower_bound_req = updated_version_req_lower_bound
|
236
|
+
|
237
|
+
# Add the latest_allowable_version as an upper bound. This means
|
238
|
+
# ignore conditions are considered when checking for the latest
|
239
|
+
# resolvable version.
|
240
|
+
#
|
241
|
+
# NOTE: This isn't perfect. If v2.x is ignored and v3 is out but
|
242
|
+
# unresolvable then the `latest_allowable_version` will be v3, and
|
243
|
+
# we won't be ignoring v2.x releases like we should be.
|
244
|
+
return lower_bound_req if latest_allowable_version.nil?
|
245
|
+
unless Utils::Python::Version.correct?(latest_allowable_version)
|
246
|
+
return lower_bound_req
|
247
|
+
end
|
248
|
+
|
249
|
+
lower_bound_req + ", <= #{latest_allowable_version}"
|
250
|
+
end
|
251
|
+
|
252
|
+
def updated_version_req_lower_bound
|
253
|
+
if dependency.version
|
254
|
+
">= #{dependency.version}"
|
255
|
+
else
|
256
|
+
version_for_requirement =
|
257
|
+
dependency.requirements.map { |r| r[:requirement] }.compact.
|
258
|
+
reject { |req_string| req_string.start_with?("<") }.
|
259
|
+
select { |req_string| req_string.match?(VERSION_REGEX) }.
|
260
|
+
map { |req_string| req_string.match(VERSION_REGEX) }.
|
261
|
+
select { |version| Gem::Version.correct?(version) }.
|
262
|
+
max_by { |version| Gem::Version.new(version) }
|
263
|
+
|
264
|
+
">= #{version_for_requirement || 0}"
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def python_helper_path
|
269
|
+
project_root = File.join(File.dirname(__FILE__), "../../../../..")
|
270
|
+
File.join(project_root, "helpers/python/run.py")
|
271
|
+
end
|
272
|
+
|
273
|
+
# See https://www.python.org/dev/peps/pep-0503/#normalized-names
|
274
|
+
def normalise(name)
|
275
|
+
name.downcase.gsub(/[-_.]+/, "-")
|
276
|
+
end
|
277
|
+
|
278
|
+
def clean_error_message(message)
|
279
|
+
# Redact any URLs, as they may include credentials
|
280
|
+
message.gsub(/http.*?(?=\s)/, "<redacted>")
|
281
|
+
end
|
282
|
+
|
283
|
+
def filenames_to_compile
|
284
|
+
files_from_reqs =
|
285
|
+
dependency.requirements.
|
286
|
+
map { |r| r[:file] }.
|
287
|
+
select { |fn| fn.end_with?(".in") }
|
288
|
+
|
289
|
+
files_from_compiled_files =
|
290
|
+
pip_compile_files.map(&:name).select do |fn|
|
291
|
+
compiled_file = dependency_files.
|
292
|
+
find { |f| f.name == fn.gsub(/\.in$/, ".txt") }
|
293
|
+
compiled_file_includes_dependency?(compiled_file)
|
294
|
+
end
|
295
|
+
|
296
|
+
filenames = [*files_from_reqs, *files_from_compiled_files].uniq
|
297
|
+
|
298
|
+
order_filenames_for_compilation(filenames)
|
299
|
+
end
|
300
|
+
|
301
|
+
def compiled_file_includes_dependency?(compiled_file)
|
302
|
+
return false unless compiled_file
|
303
|
+
|
304
|
+
regex = PythonRequirementParser::INSTALL_REQ_WITH_REQUIREMENT
|
305
|
+
|
306
|
+
matches = []
|
307
|
+
compiled_file.content.scan(regex) { matches << Regexp.last_match }
|
308
|
+
matches.any? { |m| normalise(m[:name]) == dependency.name }
|
309
|
+
end
|
310
|
+
|
311
|
+
# If the files we need to update require one another then we need to
|
312
|
+
# update them in the right order
|
313
|
+
def order_filenames_for_compilation(filenames)
|
314
|
+
ordered_filenames = []
|
315
|
+
|
316
|
+
while (remaining_filenames = filenames - ordered_filenames).any?
|
317
|
+
ordered_filenames +=
|
318
|
+
remaining_filenames.
|
319
|
+
select do |fn|
|
320
|
+
unupdated_reqs = requirement_map[fn] - ordered_filenames
|
321
|
+
(unupdated_reqs & filenames).empty?
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
ordered_filenames
|
326
|
+
end
|
327
|
+
|
328
|
+
def requirement_map
|
329
|
+
child_req_regex = FileFetchers::Python::Pip::CHILD_REQUIREMENT_REGEX
|
330
|
+
@requirement_map ||=
|
331
|
+
pip_compile_files.each_with_object({}) do |file, req_map|
|
332
|
+
paths = file.content.scan(child_req_regex).flatten
|
333
|
+
current_dir = File.dirname(file.name)
|
334
|
+
|
335
|
+
req_map[file.name] =
|
336
|
+
paths.map do |path|
|
337
|
+
path = File.join(current_dir, path) if current_dir != "."
|
338
|
+
path = Pathname.new(path).cleanpath.to_path
|
339
|
+
path = path.gsub(/\.txt$/, ".in")
|
340
|
+
next if path == file.name
|
341
|
+
|
342
|
+
path
|
343
|
+
end.uniq.compact
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def parse_updated_files
|
348
|
+
updated_files =
|
349
|
+
dependency_files.map do |file|
|
350
|
+
next file if file.name == ".python-version"
|
351
|
+
|
352
|
+
updated_file = file.dup
|
353
|
+
updated_file.content = File.read(file.name)
|
354
|
+
updated_file
|
355
|
+
end
|
356
|
+
|
357
|
+
FileParsers::Python::Pip.new(
|
358
|
+
dependency_files: updated_files,
|
359
|
+
source: nil,
|
360
|
+
credentials: credentials
|
361
|
+
).parse.find { |d| d.name == dependency.name }&.version
|
362
|
+
end
|
363
|
+
|
364
|
+
def setup_files
|
365
|
+
dependency_files.select { |f| f.name.end_with?("setup.py") }
|
366
|
+
end
|
367
|
+
|
368
|
+
def pip_compile_files
|
369
|
+
dependency_files.select { |f| f.name.end_with?(".in") }
|
370
|
+
end
|
371
|
+
|
372
|
+
def setup_cfg_files
|
373
|
+
dependency_files.select { |f| f.name.end_with?("setup.cfg") }
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
# rubocop:enable Metrics/ClassLength
|
@@ -0,0 +1,559 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "excon"
|
4
|
+
require "toml-rb"
|
5
|
+
|
6
|
+
require "dependabot/file_parsers/python/pip"
|
7
|
+
require "dependabot/file_updaters/python/pip/pipfile_preparer"
|
8
|
+
require "dependabot/file_updaters/python/pip/setup_file_sanitizer"
|
9
|
+
require "dependabot/update_checkers/python/pip"
|
10
|
+
require "dependabot/shared_helpers"
|
11
|
+
require "dependabot/utils/python/version"
|
12
|
+
require "dependabot/errors"
|
13
|
+
|
14
|
+
# rubocop:disable Metrics/ClassLength
|
15
|
+
module Dependabot
|
16
|
+
module UpdateCheckers
|
17
|
+
module Python
|
18
|
+
class Pip
|
19
|
+
# This class does version resolution for Pipfiles. Its current approach
|
20
|
+
# is somewhat crude:
|
21
|
+
# - Unlock the dependency we're checking in the Pipfile
|
22
|
+
# - Freeze all of the other dependencies in the Pipfile
|
23
|
+
# - Run `pipenv lock` and see what the result is
|
24
|
+
#
|
25
|
+
# Unfortunately, Pipenv doesn't resolve how we'd expect - it appears to
|
26
|
+
# just raise if the latest version can't be resolved. Knowing that is
|
27
|
+
# still better than nothing, though.
|
28
|
+
class PipfileVersionResolver
|
29
|
+
VERSION_REGEX = /[0-9]+(?:\.[A-Za-z0-9\-_]+)*/.freeze
|
30
|
+
GIT_DEPENDENCY_UNREACHABLE_REGEX =
|
31
|
+
/Command "git clone -q (?<url>[^\s]+).*" failed/.freeze
|
32
|
+
GIT_REFERENCE_NOT_FOUND_REGEX =
|
33
|
+
%r{"git checkout -q (?<tag>[^"]+)" .*/(?<name>.*?)(\\n'\]|$)}.
|
34
|
+
freeze
|
35
|
+
UNSUPPORTED_DEPS = %w(pyobjc).freeze
|
36
|
+
UNSUPPORTED_DEP_REGEX =
|
37
|
+
/"python setup\.py egg_info".*(?:#{UNSUPPORTED_DEPS.join("|")})/.
|
38
|
+
freeze
|
39
|
+
|
40
|
+
attr_reader :dependency, :dependency_files, :credentials
|
41
|
+
|
42
|
+
def initialize(dependency:, dependency_files:, credentials:,
|
43
|
+
unlock_requirement:, latest_allowable_version:)
|
44
|
+
@dependency = dependency
|
45
|
+
@dependency_files = dependency_files
|
46
|
+
@credentials = credentials
|
47
|
+
@latest_allowable_version = latest_allowable_version
|
48
|
+
@unlock_requirement = unlock_requirement
|
49
|
+
|
50
|
+
check_private_sources_are_reachable
|
51
|
+
end
|
52
|
+
|
53
|
+
def latest_resolvable_version
|
54
|
+
return @latest_resolvable_version if @resolution_already_attempted
|
55
|
+
|
56
|
+
@resolution_already_attempted = true
|
57
|
+
@latest_resolvable_version ||= fetch_latest_resolvable_version
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
attr_reader :latest_allowable_version
|
63
|
+
|
64
|
+
def unlock_requirement?
|
65
|
+
@unlock_requirement
|
66
|
+
end
|
67
|
+
|
68
|
+
def fetch_latest_resolvable_version
|
69
|
+
@latest_resolvable_version_string ||=
|
70
|
+
SharedHelpers.in_a_temporary_directory do
|
71
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
72
|
+
write_temporary_dependency_files
|
73
|
+
|
74
|
+
# Shell out to Pipenv, which handles everything for us.
|
75
|
+
# Whilst calling `lock` avoids doing an install as part of the
|
76
|
+
# pipenv flow, an install is still done by pip-tools in order
|
77
|
+
# to resolve the dependencies. That means this is slow.
|
78
|
+
run_pipenv_command(
|
79
|
+
pipenv_environment_variables + "pyenv exec pipenv lock"
|
80
|
+
)
|
81
|
+
|
82
|
+
updated_lockfile = JSON.parse(File.read("Pipfile.lock"))
|
83
|
+
|
84
|
+
fetch_version_from_parsed_lockfile(updated_lockfile)
|
85
|
+
end
|
86
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
87
|
+
handle_pipenv_errors(error)
|
88
|
+
end
|
89
|
+
return unless @latest_resolvable_version_string
|
90
|
+
|
91
|
+
Utils::Python::Version.new(@latest_resolvable_version_string)
|
92
|
+
end
|
93
|
+
|
94
|
+
def fetch_version_from_parsed_lockfile(updated_lockfile)
|
95
|
+
if dependency.requirements.any?
|
96
|
+
group = dependency.requirements.first[:groups].first
|
97
|
+
deps = updated_lockfile[group] || {}
|
98
|
+
|
99
|
+
version =
|
100
|
+
deps.transform_keys { |k| normalise(k) }.
|
101
|
+
dig(dependency.name, "version")&.
|
102
|
+
gsub(/^==/, "")
|
103
|
+
|
104
|
+
return version
|
105
|
+
end
|
106
|
+
|
107
|
+
FileParsers::Python::Pip::DEPENDENCY_GROUP_KEYS.each do |keys|
|
108
|
+
deps = updated_lockfile[keys.fetch(:lockfile)] || {}
|
109
|
+
version =
|
110
|
+
deps.transform_keys { |k| normalise(k) }.
|
111
|
+
dig(dependency.name, "version")&.
|
112
|
+
gsub(/^==/, "")
|
113
|
+
|
114
|
+
return version if version
|
115
|
+
end
|
116
|
+
|
117
|
+
# If the sub-dependency no longer appears in the lockfile return nil
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
122
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
123
|
+
# rubocop:disable Metrics/AbcSize
|
124
|
+
# rubocop:disable Metrics/MethodLength
|
125
|
+
def handle_pipenv_errors(error)
|
126
|
+
if error.message.include?("no version found at all") ||
|
127
|
+
error.message.include?("Invalid specifier:") ||
|
128
|
+
error.message.include?("Max retries exceeded")
|
129
|
+
msg = clean_error_message(error.message)
|
130
|
+
raise if msg.empty?
|
131
|
+
|
132
|
+
raise DependencyFileNotResolvable, msg
|
133
|
+
end
|
134
|
+
|
135
|
+
if error.message.match?(UNSUPPORTED_DEP_REGEX)
|
136
|
+
msg = "Dependabot detected a dependency that can't be built on "\
|
137
|
+
"linux. Currently, all Dependabot builds happen on linux "\
|
138
|
+
"boxes, so there is no way for Dependabot to resolve your "\
|
139
|
+
"dependency files.\n\n"\
|
140
|
+
"Unless you think Dependabot has made a mistake (please "\
|
141
|
+
"tag us if so) you may wish to disable Dependabot on this "\
|
142
|
+
"repo."
|
143
|
+
raise DependencyFileNotResolvable, msg
|
144
|
+
end
|
145
|
+
|
146
|
+
if error.message.include?("Could not find a version") ||
|
147
|
+
error.message.include?("is not a python version")
|
148
|
+
check_original_requirements_resolvable
|
149
|
+
end
|
150
|
+
|
151
|
+
if error.message.include?('Command "python setup.py egg_info"') &&
|
152
|
+
error.message.include?(dependency.name)
|
153
|
+
# The latest version of the dependency we're updating is borked
|
154
|
+
# (because it has an unevaluatable setup.py). Skip the update.
|
155
|
+
return nil
|
156
|
+
end
|
157
|
+
|
158
|
+
if error.message.match?(GIT_DEPENDENCY_UNREACHABLE_REGEX)
|
159
|
+
url = error.message.match(GIT_DEPENDENCY_UNREACHABLE_REGEX).
|
160
|
+
named_captures.fetch("url")
|
161
|
+
raise GitDependenciesNotReachable, url
|
162
|
+
end
|
163
|
+
|
164
|
+
if error.message.match?(GIT_REFERENCE_NOT_FOUND_REGEX)
|
165
|
+
name = error.message.match(GIT_REFERENCE_NOT_FOUND_REGEX).
|
166
|
+
named_captures.fetch("name")
|
167
|
+
raise GitDependencyReferenceNotFound, name
|
168
|
+
end
|
169
|
+
|
170
|
+
raise unless error.message.include?("could not be resolved")
|
171
|
+
end
|
172
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
173
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
174
|
+
# rubocop:enable Metrics/AbcSize
|
175
|
+
# rubocop:enable Metrics/MethodLength
|
176
|
+
|
177
|
+
# Needed because Pipenv's resolver isn't perfect.
|
178
|
+
# Note: We raise errors from this method, rather than returning a
|
179
|
+
# boolean, so that all deps for this repo will raise identical
|
180
|
+
# errors when failing to update
|
181
|
+
def check_original_requirements_resolvable
|
182
|
+
SharedHelpers.in_a_temporary_directory do
|
183
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
184
|
+
write_temporary_dependency_files(update_pipfile: false)
|
185
|
+
|
186
|
+
run_pipenv_command(
|
187
|
+
pipenv_environment_variables + "pyenv exec pipenv lock"
|
188
|
+
)
|
189
|
+
|
190
|
+
true
|
191
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
192
|
+
if error.message.include?("Could not find a version")
|
193
|
+
msg = clean_error_message(error.message)
|
194
|
+
msg.gsub!(/\s+\(from .*$/, "")
|
195
|
+
raise if msg.empty?
|
196
|
+
|
197
|
+
raise DependencyFileNotResolvable, msg
|
198
|
+
end
|
199
|
+
|
200
|
+
if error.message.include?("is not a python version")
|
201
|
+
msg = "Pipenv does not support specifying Python ranges "\
|
202
|
+
"(see https://github.com/pypa/pipenv/issues/1050 for more "\
|
203
|
+
"details)."
|
204
|
+
raise DependencyFileNotResolvable, msg
|
205
|
+
end
|
206
|
+
|
207
|
+
raise
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def clean_error_message(message)
|
213
|
+
# Pipenv outputs a lot of things to STDERR, so we need to clean
|
214
|
+
# up the error message
|
215
|
+
msg_lines = message.lines
|
216
|
+
msg = msg_lines.
|
217
|
+
take_while { |l| !l.start_with?("During handling of") }.
|
218
|
+
drop_while do |l|
|
219
|
+
next false if l.start_with?("CRITICAL:")
|
220
|
+
next false if l.start_with?("ERROR:")
|
221
|
+
next false if l.start_with?("packaging.specifiers")
|
222
|
+
next false if l.include?("Max retries exceeded")
|
223
|
+
|
224
|
+
true
|
225
|
+
end.join.strip
|
226
|
+
|
227
|
+
# We also need to redact any URLs, as they may include credentials
|
228
|
+
msg.gsub(/http.*?(?=\s)/, "<redacted>")
|
229
|
+
end
|
230
|
+
|
231
|
+
def write_temporary_dependency_files(update_pipfile: true)
|
232
|
+
dependency_files.each do |file|
|
233
|
+
next if file.name == ".python-version"
|
234
|
+
|
235
|
+
path = file.name
|
236
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
237
|
+
File.write(path, file.content)
|
238
|
+
end
|
239
|
+
|
240
|
+
setup_files.each do |file|
|
241
|
+
path = file.name
|
242
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
243
|
+
File.write(path, sanitized_setup_file_content(file))
|
244
|
+
end
|
245
|
+
|
246
|
+
setup_cfg_files.each do |file|
|
247
|
+
path = file.name
|
248
|
+
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
249
|
+
File.write(path, "[metadata]\nname = sanitized-package\n")
|
250
|
+
end
|
251
|
+
|
252
|
+
# Overwrite the pipfile with updated content
|
253
|
+
File.write(
|
254
|
+
"Pipfile",
|
255
|
+
pipfile_content(update_pipfile: update_pipfile)
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
def sanitized_setup_file_content(file)
|
260
|
+
@sanitized_setup_file_content ||= {}
|
261
|
+
@sanitized_setup_file_content[file.name] ||=
|
262
|
+
FileUpdaters::Python::Pip::SetupFileSanitizer.
|
263
|
+
new(setup_file: file, setup_cfg: setup_cfg(file)).
|
264
|
+
sanitized_content
|
265
|
+
end
|
266
|
+
|
267
|
+
def setup_cfg(file)
|
268
|
+
config_name = file.name.sub(/\.py$/, ".cfg")
|
269
|
+
dependency_files.find { |f| f.name == config_name }
|
270
|
+
end
|
271
|
+
|
272
|
+
def pipfile_content(update_pipfile: true)
|
273
|
+
content = pipfile.content
|
274
|
+
return content unless update_pipfile
|
275
|
+
|
276
|
+
content = freeze_other_dependencies(content)
|
277
|
+
content = unlock_target_dependency(content) if unlock_requirement?
|
278
|
+
content = add_private_sources(content)
|
279
|
+
content
|
280
|
+
end
|
281
|
+
|
282
|
+
def freeze_other_dependencies(pipfile_content)
|
283
|
+
FileUpdaters::Python::Pip::PipfilePreparer.
|
284
|
+
new(pipfile_content: pipfile_content).
|
285
|
+
freeze_top_level_dependencies_except([dependency], lockfile)
|
286
|
+
end
|
287
|
+
|
288
|
+
def unlock_target_dependency(pipfile_content)
|
289
|
+
pipfile_object = TomlRB.parse(pipfile_content)
|
290
|
+
|
291
|
+
%w(packages dev-packages).each do |type|
|
292
|
+
names = pipfile_object[type]&.keys || []
|
293
|
+
pkg_name = names.find { |nm| normalise(nm) == dependency.name }
|
294
|
+
next unless pkg_name
|
295
|
+
|
296
|
+
if pipfile_object.dig(type, pkg_name).is_a?(Hash)
|
297
|
+
pipfile_object[type][pkg_name]["version"] =
|
298
|
+
updated_version_requirement_string
|
299
|
+
else
|
300
|
+
pipfile_object[type][pkg_name] =
|
301
|
+
updated_version_requirement_string
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
TomlRB.dump(pipfile_object)
|
306
|
+
end
|
307
|
+
|
308
|
+
def add_private_sources(pipfile_content)
|
309
|
+
FileUpdaters::Python::Pip::PipfilePreparer.
|
310
|
+
new(pipfile_content: pipfile_content).
|
311
|
+
replace_sources(credentials)
|
312
|
+
end
|
313
|
+
|
314
|
+
def add_python_two_requirement_to_pipfile
|
315
|
+
content = File.read("Pipfile")
|
316
|
+
|
317
|
+
updated_content =
|
318
|
+
FileUpdaters::Python::Pip::PipfilePreparer.
|
319
|
+
new(pipfile_content: content).
|
320
|
+
update_python_requirement("2.7.15")
|
321
|
+
|
322
|
+
File.write("Pipfile", updated_content)
|
323
|
+
end
|
324
|
+
|
325
|
+
def pipfile_python_requirement
|
326
|
+
parsed_pipfile = TomlRB.parse(pipfile.content)
|
327
|
+
|
328
|
+
parsed_pipfile.dig("requires", "python_full_version") ||
|
329
|
+
parsed_pipfile.dig("requires", "python_version")
|
330
|
+
end
|
331
|
+
|
332
|
+
def python_requirement_specified?
|
333
|
+
return true if pipfile_python_requirement
|
334
|
+
|
335
|
+
!python_version_file.nil?
|
336
|
+
end
|
337
|
+
|
338
|
+
def set_up_python_environment
|
339
|
+
# Initialize a git repo to appease pip-tools
|
340
|
+
begin
|
341
|
+
SharedHelpers.run_shell_command("git init") if setup_files.any?
|
342
|
+
rescue Dependabot::SharedHelpers::HelperSubprocessFailed
|
343
|
+
nil
|
344
|
+
end
|
345
|
+
|
346
|
+
SharedHelpers.run_shell_command(
|
347
|
+
"pyenv install -s #{python_version}"
|
348
|
+
)
|
349
|
+
SharedHelpers.run_shell_command("pyenv local #{python_version}")
|
350
|
+
return if pre_installed_python?(python_version)
|
351
|
+
|
352
|
+
SharedHelpers.run_shell_command(
|
353
|
+
"pyenv exec pip install -r #{python_requirements_path}"
|
354
|
+
)
|
355
|
+
end
|
356
|
+
|
357
|
+
def python_version
|
358
|
+
requirement =
|
359
|
+
if @using_python_two
|
360
|
+
"2.7.*"
|
361
|
+
elsif pipfile_python_requirement&.match?(/^\d/)
|
362
|
+
parts = pipfile_python_requirement.split(".")
|
363
|
+
parts.fill("*", (parts.length)..2).join(".")
|
364
|
+
elsif python_version_file
|
365
|
+
python_version_file.content
|
366
|
+
else
|
367
|
+
PythonVersions::PRE_INSTALLED_PYTHON_VERSIONS.first
|
368
|
+
end
|
369
|
+
|
370
|
+
requirement = Utils::Python::Requirement.new(requirement)
|
371
|
+
|
372
|
+
PythonVersions::PYTHON_VERSIONS.find do |version|
|
373
|
+
requirement.satisfied_by?(Utils::Python::Version.new(version))
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def pre_installed_python?(version)
|
378
|
+
PythonVersions::PRE_INSTALLED_PYTHON_VERSIONS.include?(version)
|
379
|
+
end
|
380
|
+
|
381
|
+
def check_private_sources_are_reachable
|
382
|
+
env_sources = pipfile_sources.select { |h| h["url"].include?("${") }
|
383
|
+
|
384
|
+
check_env_sources_included_in_config_variables(env_sources)
|
385
|
+
|
386
|
+
sources_to_check =
|
387
|
+
pipfile_sources.reject { |h| h["url"].include?("${") } +
|
388
|
+
config_variable_sources
|
389
|
+
|
390
|
+
sources_to_check.
|
391
|
+
map { |details| details["url"] }.
|
392
|
+
reject { |url| MAIN_PYPI_INDEXES.include?(url) }.
|
393
|
+
each do |url|
|
394
|
+
sanitized_url = url.gsub(%r{(?<=//).*(?=@)}, "redacted")
|
395
|
+
|
396
|
+
response = Excon.get(
|
397
|
+
url,
|
398
|
+
idempotent: true,
|
399
|
+
**SharedHelpers.excon_defaults
|
400
|
+
)
|
401
|
+
|
402
|
+
if response.status == 401 || response.status == 403
|
403
|
+
raise PrivateSourceAuthenticationFailure, sanitized_url
|
404
|
+
end
|
405
|
+
rescue Excon::Error::Timeout, Excon::Error::Socket
|
406
|
+
raise PrivateSourceTimedOut, sanitized_url
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
def updated_version_requirement_string
|
411
|
+
lower_bound_req = updated_version_req_lower_bound
|
412
|
+
|
413
|
+
# Add the latest_allowable_version as an upper bound. This means
|
414
|
+
# ignore conditions are considered when checking for the latest
|
415
|
+
# resolvable version.
|
416
|
+
#
|
417
|
+
# NOTE: This isn't perfect. If v2.x is ignored and v3 is out but
|
418
|
+
# unresolvable then the `latest_allowable_version` will be v3, and
|
419
|
+
# we won't be ignoring v2.x releases like we should be.
|
420
|
+
return lower_bound_req if latest_allowable_version.nil?
|
421
|
+
unless Utils::Python::Version.correct?(latest_allowable_version)
|
422
|
+
return lower_bound_req
|
423
|
+
end
|
424
|
+
|
425
|
+
lower_bound_req + ", <= #{latest_allowable_version}"
|
426
|
+
end
|
427
|
+
|
428
|
+
def updated_version_req_lower_bound
|
429
|
+
if dependency.version
|
430
|
+
">= #{dependency.version}"
|
431
|
+
else
|
432
|
+
version_for_requirement =
|
433
|
+
dependency.requirements.map { |r| r[:requirement] }.compact.
|
434
|
+
reject { |req_string| req_string.start_with?("<") }.
|
435
|
+
select { |req_string| req_string.match?(VERSION_REGEX) }.
|
436
|
+
map { |req_string| req_string.match(VERSION_REGEX) }.
|
437
|
+
select { |version| Gem::Version.correct?(version) }.
|
438
|
+
max_by { |version| Gem::Version.new(version) }
|
439
|
+
|
440
|
+
">= #{version_for_requirement || 0}"
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
def run_pipenv_command(cmd)
|
445
|
+
set_up_python_environment
|
446
|
+
|
447
|
+
raw_response = nil
|
448
|
+
IO.popen(cmd, err: %i(child out)) { |p| raw_response = p.read }
|
449
|
+
|
450
|
+
# Raise an error with the output from the shell session if Pipenv
|
451
|
+
# returns a non-zero status
|
452
|
+
return if $CHILD_STATUS.success?
|
453
|
+
|
454
|
+
raise SharedHelpers::HelperSubprocessFailed.new(raw_response, cmd)
|
455
|
+
rescue SharedHelpers::HelperSubprocessFailed => error
|
456
|
+
original_error ||= error
|
457
|
+
msg = error.message
|
458
|
+
|
459
|
+
relevant_error =
|
460
|
+
if may_be_using_wrong_python_version?(msg) then original_error
|
461
|
+
else error
|
462
|
+
end
|
463
|
+
|
464
|
+
raise relevant_error unless may_be_using_wrong_python_version?(msg)
|
465
|
+
raise relevant_error if @using_python_two
|
466
|
+
|
467
|
+
@using_python_two = true
|
468
|
+
add_python_two_requirement_to_pipfile
|
469
|
+
cmd = cmd.gsub("pipenv ", "pipenv --two ")
|
470
|
+
retry
|
471
|
+
ensure
|
472
|
+
@using_python_two = nil
|
473
|
+
end
|
474
|
+
|
475
|
+
def may_be_using_wrong_python_version?(error_message)
|
476
|
+
return false if python_requirement_specified?
|
477
|
+
return true if error_message.include?("UnsupportedPythonVersion")
|
478
|
+
|
479
|
+
error_message.include?('Command "python setup.py egg_info" failed')
|
480
|
+
end
|
481
|
+
|
482
|
+
def check_env_sources_included_in_config_variables(env_sources)
|
483
|
+
config_variable_source_urls =
|
484
|
+
config_variable_sources.map { |s| s["url"] }
|
485
|
+
|
486
|
+
env_sources.each do |source|
|
487
|
+
url = source["url"]
|
488
|
+
known_parts = url.split(/\$\{.*?\}/).reject(&:empty?).compact
|
489
|
+
|
490
|
+
# If the whole URL is an environment variable we can't do a check
|
491
|
+
next if known_parts.none?
|
492
|
+
|
493
|
+
regex = known_parts.map { |p| Regexp.quote(p) }.join(".*?")
|
494
|
+
next if config_variable_source_urls.any? { |s| s.match?(regex) }
|
495
|
+
|
496
|
+
raise PrivateSourceAuthenticationFailure, url
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
def config_variable_sources
|
501
|
+
@config_variable_sources ||=
|
502
|
+
credentials.
|
503
|
+
select { |cred| cred["type"] == "python_index" }.
|
504
|
+
map { |h| { "url" => h["index-url"].gsub(%r{/*$}, "") + "/" } }
|
505
|
+
end
|
506
|
+
|
507
|
+
def pipfile_sources
|
508
|
+
@pipfile_sources ||=
|
509
|
+
TomlRB.parse(pipfile.content).fetch("source", []).
|
510
|
+
map { |h| h.dup.merge("url" => h["url"].gsub(%r{/*$}, "") + "/") }
|
511
|
+
end
|
512
|
+
|
513
|
+
def pipenv_environment_variables
|
514
|
+
environment_variables = [
|
515
|
+
"PIPENV_YES=true", # Install new Python versions if needed
|
516
|
+
"PIPENV_MAX_RETRIES=3", # Retry timeouts
|
517
|
+
"PIPENV_NOSPIN=1", # Don't pollute logs with spinner
|
518
|
+
"PIPENV_TIMEOUT=600", # Set install timeout to 10 minutes
|
519
|
+
"PIP_DEFAULT_TIMEOUT=60" # Set pip timeout to 1 minute
|
520
|
+
]
|
521
|
+
|
522
|
+
environment_variables.join(" ") + " "
|
523
|
+
end
|
524
|
+
|
525
|
+
def python_requirements_path
|
526
|
+
project_root = File.join(File.dirname(__FILE__), "../../../../..")
|
527
|
+
File.join(project_root, "helpers/python/requirements.txt")
|
528
|
+
end
|
529
|
+
|
530
|
+
# See https://www.python.org/dev/peps/pep-0503/#normalized-names
|
531
|
+
def normalise(name)
|
532
|
+
name.downcase.gsub(/[-_.]+/, "-")
|
533
|
+
end
|
534
|
+
|
535
|
+
def pipfile
|
536
|
+
dependency_files.find { |f| f.name == "Pipfile" }
|
537
|
+
end
|
538
|
+
|
539
|
+
def lockfile
|
540
|
+
dependency_files.find { |f| f.name == "Pipfile.lock" }
|
541
|
+
end
|
542
|
+
|
543
|
+
def setup_files
|
544
|
+
dependency_files.select { |f| f.name.end_with?("setup.py") }
|
545
|
+
end
|
546
|
+
|
547
|
+
def setup_cfg_files
|
548
|
+
dependency_files.select { |f| f.name.end_with?("setup.cfg") }
|
549
|
+
end
|
550
|
+
|
551
|
+
def python_version_file
|
552
|
+
dependency_files.find { |f| f.name == ".python-version" }
|
553
|
+
end
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
# rubocop:enable Metrics/ClassLength
|