Skip to content

Commit

Permalink
Added TypeCheck as strict for pipenv_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
randhircs committed Jan 15, 2025
1 parent f0125e9 commit 8efc8e2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions python/lib/dependabot/python/pipenv_runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "dependabot/shared_helpers"
Expand All @@ -11,6 +11,14 @@ module Python
class PipenvRunner
extend T::Sig

sig do
params(
dependency: Dependabot::Dependency,
lockfile: DependencyFile,
language_version_manager: LanguageVersionManager
)
.void
end
def initialize(dependency:, lockfile:, language_version_manager:)
@dependency = dependency
@lockfile = lockfile
Expand All @@ -26,7 +34,7 @@ def run_upgrade(constraint)
run(command, fingerprint: "pyenv exec pipenv upgrade --verbose <dependency_name><constraint>")
end

sig { params(constraint: String).returns(T.untyped) }
sig { params(constraint: String).returns(String) }
def run_upgrade_and_fetch_version(constraint)
run_upgrade(constraint)

Expand All @@ -47,10 +55,14 @@ def run(command, fingerprint: nil)

private

sig { returns(Dependabot::Dependency) }
attr_reader :dependency
sig { returns(DependencyFile) }
attr_reader :lockfile
sig { returns(LanguageVersionManager) }
attr_reader :language_version_manager

sig { params(updated_lockfile: T.untyped).returns(T.untyped) }
def fetch_version_from_parsed_lockfile(updated_lockfile)
deps = updated_lockfile[lockfile_section] || {}

Expand All @@ -63,21 +75,24 @@ def run_command(command, fingerprint: nil)
SharedHelpers.run_shell_command(command, env: pipenv_env_variables, fingerprint: fingerprint)
end

sig { returns(String) }
def lockfile_section
if dependency.requirements.any?
dependency.requirements.first[:groups].first
T.must(dependency.requirements.first)[:groups].first
else
Python::FileParser::DEPENDENCY_GROUP_KEYS.each do |keys|
section = keys.fetch(:lockfile)
return section if JSON.parse(lockfile.content)[section].keys.any?(dependency_name)
return section if JSON.parse(T.must(lockfile.content))[section].keys.any?(dependency_name)
end
end
end

sig { returns(String) }
def dependency_name
dependency.metadata[:original_name] || dependency.name
end

sig { returns(T::Hash[String, String]) }
def pipenv_env_variables
{
"PIPENV_YES" => "true", # Install new Python ver if needed
Expand Down

0 comments on commit 8efc8e2

Please sign in to comment.